aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/DocBook/writing-an-alsa-driver.tmpl12
-rw-r--r--Documentation/sound/alsa/HD-Audio.txt10
-rw-r--r--include/linux/usb/audio-v2.h2
-rw-r--r--include/sound/control.h5
-rw-r--r--include/sound/core.h26
-rw-r--r--include/sound/pcm.h23
-rw-r--r--sound/core/control.c41
-rw-r--r--sound/core/device.c8
-rw-r--r--sound/core/hwdep.c2
-rw-r--r--sound/core/info.c41
-rw-r--r--sound/core/init.c16
-rw-r--r--sound/core/isadma.c2
-rw-r--r--sound/core/jack.c6
-rw-r--r--sound/core/memalloc.c20
-rw-r--r--sound/core/memory.c4
-rw-r--r--sound/core/pcm.c6
-rw-r--r--sound/core/pcm_lib.c54
-rw-r--r--sound/core/pcm_memory.c19
-rw-r--r--sound/core/pcm_misc.c28
-rw-r--r--sound/core/pcm_native.c13
-rw-r--r--sound/core/rawmidi.c14
-rw-r--r--sound/core/sound.c7
-rw-r--r--sound/core/vmaster.c7
-rw-r--r--sound/drivers/mpu401/mpu401_uart.c6
-rw-r--r--sound/oss/sb_common.c3
-rw-r--r--sound/oss/uart401.c11
-rw-r--r--sound/pci/ac97/ac97_codec.c16
-rw-r--r--sound/pci/ac97/ac97_pcm.c10
-rw-r--r--sound/pci/hda/hda_auto_parser.c68
-rw-r--r--sound/pci/hda/hda_auto_parser.h29
-rw-r--r--sound/pci/hda/hda_beep.c39
-rw-r--r--sound/pci/hda/hda_beep.h1
-rw-r--r--sound/pci/hda/hda_codec.c17
-rw-r--r--sound/pci/hda/hda_codec.h3
-rw-r--r--sound/pci/hda/hda_generic.c400
-rw-r--r--sound/pci/hda/hda_generic.h30
-rw-r--r--sound/pci/hda/hda_intel.c36
-rw-r--r--sound/pci/hda/hda_jack.c43
-rw-r--r--sound/pci/hda/hda_local.h4
-rw-r--r--sound/pci/hda/patch_analog.c33
-rw-r--r--sound/pci/hda/patch_ca0132.c82
-rw-r--r--sound/pci/hda/patch_cirrus.c19
-rw-r--r--sound/pci/hda/patch_conexant.c19
-rw-r--r--sound/pci/hda/patch_hdmi.c198
-rw-r--r--sound/pci/hda/patch_realtek.c664
-rw-r--r--sound/pci/hda/patch_sigmatel.c39
-rw-r--r--sound/pci/hda/patch_via.c20
-rw-r--r--sound/pci/rme9652/hdspm.c382
-rw-r--r--sound/sound_core.c22
-rw-r--r--sound/spi/at73c213.c22
-rw-r--r--sound/usb/caiaq/audio.c459
-rw-r--r--sound/usb/caiaq/audio.h4
-rw-r--r--sound/usb/caiaq/control.c67
-rw-r--r--sound/usb/caiaq/control.h2
-rw-r--r--sound/usb/caiaq/device.c248
-rw-r--r--sound/usb/caiaq/device.h18
-rw-r--r--sound/usb/caiaq/input.c328
-rw-r--r--sound/usb/caiaq/input.h6
-rw-r--r--sound/usb/caiaq/midi.c63
-rw-r--r--sound/usb/caiaq/midi.h5
-rw-r--r--sound/usb/card.c11
-rw-r--r--sound/usb/card.h1
-rw-r--r--sound/usb/clock.c189
-rw-r--r--sound/usb/clock.h3
-rw-r--r--sound/usb/endpoint.c18
-rw-r--r--sound/usb/endpoint.h2
-rw-r--r--sound/usb/format.c22
-rw-r--r--sound/usb/format.h2
-rw-r--r--sound/usb/midi.c25
-rw-r--r--sound/usb/pcm.c36
-rw-r--r--sound/usb/proc.c7
-rw-r--r--sound/usb/quirks-table.h43
-rw-r--r--sound/usb/quirks.c32
-rw-r--r--sound/usb/quirks.h1
-rw-r--r--sound/usb/stream.c15
-rw-r--r--sound/usb/usbaudio.h1
76 files changed, 2759 insertions, 1431 deletions
diff --git a/Documentation/DocBook/writing-an-alsa-driver.tmpl b/Documentation/DocBook/writing-an-alsa-driver.tmpl
index bd6fee22c4dd..06741e925985 100644
--- a/Documentation/DocBook/writing-an-alsa-driver.tmpl
+++ b/Documentation/DocBook/writing-an-alsa-driver.tmpl
@@ -6164,14 +6164,12 @@ struct _snd_pcm_runtime {
6164 6164
6165 <para> 6165 <para>
6166 The macro takes an conditional expression to evaluate. 6166 The macro takes an conditional expression to evaluate.
6167 When <constant>CONFIG_SND_DEBUG</constant>, is set, the 6167 When <constant>CONFIG_SND_DEBUG</constant>, is set, if the
6168 expression is actually evaluated. If it's non-zero, it shows 6168 expression is non-zero, it shows the warning message such as
6169 the warning message such as
6170 <computeroutput>BUG? (xxx)</computeroutput> 6169 <computeroutput>BUG? (xxx)</computeroutput>
6171 normally followed by stack trace. It returns the evaluated 6170 normally followed by stack trace.
6172 value. 6171
6173 When no <constant>CONFIG_SND_DEBUG</constant> is set, this 6172 In both cases it returns the evaluated value.
6174 macro always returns zero.
6175 </para> 6173 </para>
6176 6174
6177 </section> 6175 </section>
diff --git a/Documentation/sound/alsa/HD-Audio.txt b/Documentation/sound/alsa/HD-Audio.txt
index d4faa63ff352..c3c912d023cc 100644
--- a/Documentation/sound/alsa/HD-Audio.txt
+++ b/Documentation/sound/alsa/HD-Audio.txt
@@ -461,11 +461,13 @@ The generic parser supports the following hints:
461 the corresponding mixer control, if available 461 the corresponding mixer control, if available
462- add_stereo_mix_input (bool): add the stereo mix (analog-loopback 462- add_stereo_mix_input (bool): add the stereo mix (analog-loopback
463 mix) to the input mux if available 463 mix) to the input mux if available
464- add_out_jack_modes (bool): add "xxx Jack Mode" enum controls to each 464- add_jack_modes (bool): add "xxx Jack Mode" enum controls to each
465 output jack for allowing to change the headphone amp capability 465 I/O jack for allowing to change the headphone amp and mic bias VREF
466- add_in_jack_modes (bool): add "xxx Jack Mode" enum controls to each 466 capabilities
467 input jack for allowing to change the mic bias vref
468- power_down_unused (bool): power down the unused widgets 467- power_down_unused (bool): power down the unused widgets
468- add_hp_mic (bool): add the headphone to capture source if possible
469- hp_mic_detect (bool): enable/disable the hp/mic shared input for a
470 single built-in mic case; default true
469- mixer_nid (int): specifies the widget NID of the analog-loopback 471- mixer_nid (int): specifies the widget NID of the analog-loopback
470 mixer 472 mixer
471 473
diff --git a/include/linux/usb/audio-v2.h b/include/linux/usb/audio-v2.h
index ed13053153f4..c5f2158ab00e 100644
--- a/include/linux/usb/audio-v2.h
+++ b/include/linux/usb/audio-v2.h
@@ -170,6 +170,8 @@ struct uac2_as_header_descriptor {
170 __u8 iChannelNames; 170 __u8 iChannelNames;
171} __attribute__((packed)); 171} __attribute__((packed));
172 172
173#define UAC2_FORMAT_TYPE_I_RAW_DATA (1 << 31)
174
173/* 4.10.1.2 Class-Specific AS Isochronous Audio Data Endpoint Descriptor */ 175/* 4.10.1.2 Class-Specific AS Isochronous Audio Data Endpoint Descriptor */
174 176
175struct uac2_iso_endpoint_descriptor { 177struct uac2_iso_endpoint_descriptor {
diff --git a/include/sound/control.h b/include/sound/control.h
index 8332e865c759..34bc93d80d55 100644
--- a/include/sound/control.h
+++ b/include/sound/control.h
@@ -189,7 +189,6 @@ int _snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave,
189 * 189 *
190 * Add a virtual slave control to the given master element created via 190 * Add a virtual slave control to the given master element created via
191 * snd_ctl_create_virtual_master() beforehand. 191 * snd_ctl_create_virtual_master() beforehand.
192 * Returns zero if successful or a negative error code.
193 * 192 *
194 * All slaves must be the same type (returning the same information 193 * All slaves must be the same type (returning the same information
195 * via info callback). The function doesn't check it, so it's your 194 * via info callback). The function doesn't check it, so it's your
@@ -199,6 +198,8 @@ int _snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave,
199 * at most two channels, 198 * at most two channels,
200 * logarithmic volume control (dB level) thus no linear volume, 199 * logarithmic volume control (dB level) thus no linear volume,
201 * master can only attenuate the volume without gain 200 * master can only attenuate the volume without gain
201 *
202 * Return: Zero if successful or a negative error code.
202 */ 203 */
203static inline int 204static inline int
204snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave) 205snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave)
@@ -219,6 +220,8 @@ snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave)
219 * When the control peeks the hardware values directly and the value 220 * When the control peeks the hardware values directly and the value
220 * can be changed by other means than the put callback of the element, 221 * can be changed by other means than the put callback of the element,
221 * this function should be used to keep the value always up-to-date. 222 * this function should be used to keep the value always up-to-date.
223 *
224 * Return: Zero if successful or a negative error code.
222 */ 225 */
223static inline int 226static inline int
224snd_ctl_add_slave_uncached(struct snd_kcontrol *master, 227snd_ctl_add_slave_uncached(struct snd_kcontrol *master,
diff --git a/include/sound/core.h b/include/sound/core.h
index 7cede2d6aa86..5bfe5136441c 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -229,7 +229,7 @@ int snd_register_device_for_dev(int type, struct snd_card *card,
229 * This function uses the card's device pointer to link to the 229 * This function uses the card's device pointer to link to the
230 * correct &struct device. 230 * correct &struct device.
231 * 231 *
232 * Returns zero if successful, or a negative error code on failure. 232 * Return: Zero if successful, or a negative error code on failure.
233 */ 233 */
234static inline int snd_register_device(int type, struct snd_card *card, int dev, 234static inline int snd_register_device(int type, struct snd_card *card, int dev,
235 const struct file_operations *f_ops, 235 const struct file_operations *f_ops,
@@ -379,18 +379,10 @@ void __snd_printk(unsigned int level, const char *file, int line,
379 * snd_BUG_ON - debugging check macro 379 * snd_BUG_ON - debugging check macro
380 * @cond: condition to evaluate 380 * @cond: condition to evaluate
381 * 381 *
382 * When CONFIG_SND_DEBUG is set, this macro evaluates the given condition, 382 * Has the same behavior as WARN_ON when CONFIG_SND_DEBUG is set,
383 * and call WARN() and returns the value if it's non-zero. 383 * otherwise just evaluates the conditional and returns the value.
384 *
385 * When CONFIG_SND_DEBUG is not set, this just returns zero, and the given
386 * condition is ignored.
387 *
388 * NOTE: the argument won't be evaluated at all when CONFIG_SND_DEBUG=n.
389 * Thus, don't put any statement that influences on the code behavior,
390 * such as pre/post increment, to the argument of this macro.
391 * If you want to evaluate and give a warning, use standard WARN_ON().
392 */ 384 */
393#define snd_BUG_ON(cond) WARN((cond), "BUG? (%s)\n", __stringify(cond)) 385#define snd_BUG_ON(cond) WARN_ON((cond))
394 386
395#else /* !CONFIG_SND_DEBUG */ 387#else /* !CONFIG_SND_DEBUG */
396 388
@@ -400,11 +392,11 @@ __printf(2, 3)
400static inline void _snd_printd(int level, const char *format, ...) {} 392static inline void _snd_printd(int level, const char *format, ...) {}
401 393
402#define snd_BUG() do { } while (0) 394#define snd_BUG() do { } while (0)
403static inline int __snd_bug_on(int cond) 395
404{ 396#define snd_BUG_ON(condition) ({ \
405 return 0; 397 int __ret_warn_on = !!(condition); \
406} 398 unlikely(__ret_warn_on); \
407#define snd_BUG_ON(cond) __snd_bug_on(0 && (cond)) /* always false */ 399})
408 400
409#endif /* CONFIG_SND_DEBUG */ 401#endif /* CONFIG_SND_DEBUG */
410 402
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 45c1981c9ca2..aa7b0a8385cb 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -659,7 +659,7 @@ static inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(struct snd_pcm_runtime
659 * 659 *
660 * Checks whether enough free space is available on the playback buffer. 660 * Checks whether enough free space is available on the playback buffer.
661 * 661 *
662 * Returns non-zero if available, or zero if not. 662 * Return: Non-zero if available, or zero if not.
663 */ 663 */
664static inline int snd_pcm_playback_ready(struct snd_pcm_substream *substream) 664static inline int snd_pcm_playback_ready(struct snd_pcm_substream *substream)
665{ 665{
@@ -673,7 +673,7 @@ static inline int snd_pcm_playback_ready(struct snd_pcm_substream *substream)
673 * 673 *
674 * Checks whether enough capture data is available on the capture buffer. 674 * Checks whether enough capture data is available on the capture buffer.
675 * 675 *
676 * Returns non-zero if available, or zero if not. 676 * Return: Non-zero if available, or zero if not.
677 */ 677 */
678static inline int snd_pcm_capture_ready(struct snd_pcm_substream *substream) 678static inline int snd_pcm_capture_ready(struct snd_pcm_substream *substream)
679{ 679{
@@ -685,10 +685,10 @@ static inline int snd_pcm_capture_ready(struct snd_pcm_substream *substream)
685 * snd_pcm_playback_data - check whether any data exists on the playback buffer 685 * snd_pcm_playback_data - check whether any data exists on the playback buffer
686 * @substream: the pcm substream instance 686 * @substream: the pcm substream instance
687 * 687 *
688 * Checks whether any data exists on the playback buffer. If stop_threshold 688 * Checks whether any data exists on the playback buffer.
689 * is bigger or equal to boundary, then this function returns always non-zero.
690 * 689 *
691 * Returns non-zero if exists, or zero if not. 690 * Return: Non-zero if any data exists, or zero if not. If stop_threshold
691 * is bigger or equal to boundary, then this function returns always non-zero.
692 */ 692 */
693static inline int snd_pcm_playback_data(struct snd_pcm_substream *substream) 693static inline int snd_pcm_playback_data(struct snd_pcm_substream *substream)
694{ 694{
@@ -705,7 +705,7 @@ static inline int snd_pcm_playback_data(struct snd_pcm_substream *substream)
705 * 705 *
706 * Checks whether the playback buffer is empty. 706 * Checks whether the playback buffer is empty.
707 * 707 *
708 * Returns non-zero if empty, or zero if not. 708 * Return: Non-zero if empty, or zero if not.
709 */ 709 */
710static inline int snd_pcm_playback_empty(struct snd_pcm_substream *substream) 710static inline int snd_pcm_playback_empty(struct snd_pcm_substream *substream)
711{ 711{
@@ -719,7 +719,7 @@ static inline int snd_pcm_playback_empty(struct snd_pcm_substream *substream)
719 * 719 *
720 * Checks whether the capture buffer is empty. 720 * Checks whether the capture buffer is empty.
721 * 721 *
722 * Returns non-zero if empty, or zero if not. 722 * Return: Non-zero if empty, or zero if not.
723 */ 723 */
724static inline int snd_pcm_capture_empty(struct snd_pcm_substream *substream) 724static inline int snd_pcm_capture_empty(struct snd_pcm_substream *substream)
725{ 725{
@@ -852,7 +852,7 @@ int snd_pcm_format_big_endian(snd_pcm_format_t format);
852 * snd_pcm_format_cpu_endian - Check the PCM format is CPU-endian 852 * snd_pcm_format_cpu_endian - Check the PCM format is CPU-endian
853 * @format: the format to check 853 * @format: the format to check
854 * 854 *
855 * Returns 1 if the given PCM format is CPU-endian, 0 if 855 * Return: 1 if the given PCM format is CPU-endian, 0 if
856 * opposite, or a negative error code if endian not specified. 856 * opposite, or a negative error code if endian not specified.
857 */ 857 */
858int snd_pcm_format_cpu_endian(snd_pcm_format_t format); 858int snd_pcm_format_cpu_endian(snd_pcm_format_t format);
@@ -963,7 +963,7 @@ struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream,
963 * contiguous in kernel virtual space, but not in physical memory. Use this 963 * contiguous in kernel virtual space, but not in physical memory. Use this
964 * if the buffer is accessed by kernel code but not by device DMA. 964 * if the buffer is accessed by kernel code but not by device DMA.
965 * 965 *
966 * Returns 1 if the buffer was changed, 0 if not changed, or a negative error 966 * Return: 1 if the buffer was changed, 0 if not changed, or a negative error
967 * code. 967 * code.
968 */ 968 */
969static int snd_pcm_lib_alloc_vmalloc_buffer 969static int snd_pcm_lib_alloc_vmalloc_buffer
@@ -975,6 +975,9 @@ static int snd_pcm_lib_alloc_vmalloc_buffer
975 * 975 *
976 * This function works like snd_pcm_lib_alloc_vmalloc_buffer(), but uses 976 * This function works like snd_pcm_lib_alloc_vmalloc_buffer(), but uses
977 * vmalloc_32(), i.e., the pages are allocated from 32-bit-addressable memory. 977 * vmalloc_32(), i.e., the pages are allocated from 32-bit-addressable memory.
978 *
979 * Return: 1 if the buffer was changed, 0 if not changed, or a negative error
980 * code.
978 */ 981 */
979static int snd_pcm_lib_alloc_vmalloc_32_buffer 982static int snd_pcm_lib_alloc_vmalloc_32_buffer
980 (struct snd_pcm_substream *substream, size_t size); 983 (struct snd_pcm_substream *substream, size_t size);
@@ -1070,6 +1073,8 @@ const char *snd_pcm_format_name(snd_pcm_format_t format);
1070/** 1073/**
1071 * snd_pcm_stream_str - Get a string naming the direction of a stream 1074 * snd_pcm_stream_str - Get a string naming the direction of a stream
1072 * @substream: the pcm substream instance 1075 * @substream: the pcm substream instance
1076 *
1077 * Return: A string naming the direction of the stream.
1073 */ 1078 */
1074static inline const char *snd_pcm_stream_str(struct snd_pcm_substream *substream) 1079static inline const char *snd_pcm_stream_str(struct snd_pcm_substream *substream)
1075{ 1080{
diff --git a/sound/core/control.c b/sound/core/control.c
index 8c7c2c9bba61..d8aa206e8bde 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -190,7 +190,7 @@ EXPORT_SYMBOL(snd_ctl_notify);
190 * Allocates a new struct snd_kcontrol instance and copies the given template 190 * Allocates a new struct snd_kcontrol instance and copies the given template
191 * to the new instance. It does not copy volatile data (access). 191 * to the new instance. It does not copy volatile data (access).
192 * 192 *
193 * Returns the pointer of the new instance, or NULL on failure. 193 * Return: The pointer of the new instance, or %NULL on failure.
194 */ 194 */
195static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control, 195static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control,
196 unsigned int access) 196 unsigned int access)
@@ -224,7 +224,7 @@ static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control,
224 * template. When the access field of ncontrol is 0, it's assumed as 224 * template. When the access field of ncontrol is 0, it's assumed as
225 * READWRITE access. When the count field is 0, it's assumes as one. 225 * READWRITE access. When the count field is 0, it's assumes as one.
226 * 226 *
227 * Returns the pointer of the newly generated instance, or NULL on failure. 227 * Return: The pointer of the newly generated instance, or %NULL on failure.
228 */ 228 */
229struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol, 229struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol,
230 void *private_data) 230 void *private_data)
@@ -322,9 +322,10 @@ static int snd_ctl_find_hole(struct snd_card *card, unsigned int count)
322 * snd_ctl_new1() to the given card. Assigns also an unique 322 * snd_ctl_new1() to the given card. Assigns also an unique
323 * numid used for fast search. 323 * numid used for fast search.
324 * 324 *
325 * Returns zero if successful, or a negative error code on failure.
326 *
327 * It frees automatically the control which cannot be added. 325 * It frees automatically the control which cannot be added.
326 *
327 * Return: Zero if successful, or a negative error code on failure.
328 *
328 */ 329 */
329int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol) 330int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
330{ 331{
@@ -380,9 +381,9 @@ EXPORT_SYMBOL(snd_ctl_add);
380 * and the add_on_replace flag is set, the control is added. If the 381 * and the add_on_replace flag is set, the control is added. If the
381 * control exists, it is destroyed first. 382 * control exists, it is destroyed first.
382 * 383 *
383 * Returns zero if successful, or a negative error code on failure.
384 *
385 * It frees automatically the control which cannot be added or replaced. 384 * It frees automatically the control which cannot be added or replaced.
385 *
386 * Return: Zero if successful, or a negative error code on failure.
386 */ 387 */
387int snd_ctl_replace(struct snd_card *card, struct snd_kcontrol *kcontrol, 388int snd_ctl_replace(struct snd_card *card, struct snd_kcontrol *kcontrol,
388 bool add_on_replace) 389 bool add_on_replace)
@@ -442,8 +443,8 @@ EXPORT_SYMBOL(snd_ctl_replace);
442 * Removes the control from the card and then releases the instance. 443 * Removes the control from the card and then releases the instance.
443 * You don't need to call snd_ctl_free_one(). You must be in 444 * You don't need to call snd_ctl_free_one(). You must be in
444 * the write lock - down_write(&card->controls_rwsem). 445 * the write lock - down_write(&card->controls_rwsem).
445 * 446 *
446 * Returns 0 if successful, or a negative error code on failure. 447 * Return: 0 if successful, or a negative error code on failure.
447 */ 448 */
448int snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol) 449int snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol)
449{ 450{
@@ -470,8 +471,8 @@ EXPORT_SYMBOL(snd_ctl_remove);
470 * 471 *
471 * Finds the control instance with the given id, removes it from the 472 * Finds the control instance with the given id, removes it from the
472 * card list and releases it. 473 * card list and releases it.
473 * 474 *
474 * Returns 0 if successful, or a negative error code on failure. 475 * Return: 0 if successful, or a negative error code on failure.
475 */ 476 */
476int snd_ctl_remove_id(struct snd_card *card, struct snd_ctl_elem_id *id) 477int snd_ctl_remove_id(struct snd_card *card, struct snd_ctl_elem_id *id)
477{ 478{
@@ -498,8 +499,8 @@ EXPORT_SYMBOL(snd_ctl_remove_id);
498 * 499 *
499 * Finds the control instance with the given id, removes it from the 500 * Finds the control instance with the given id, removes it from the
500 * card list and releases it. 501 * card list and releases it.
501 * 502 *
502 * Returns 0 if successful, or a negative error code on failure. 503 * Return: 0 if successful, or a negative error code on failure.
503 */ 504 */
504static int snd_ctl_remove_user_ctl(struct snd_ctl_file * file, 505static int snd_ctl_remove_user_ctl(struct snd_ctl_file * file,
505 struct snd_ctl_elem_id *id) 506 struct snd_ctl_elem_id *id)
@@ -541,7 +542,7 @@ error:
541 * Finds the control instance with the given id, and activate or 542 * Finds the control instance with the given id, and activate or
542 * inactivate the control together with notification, if changed. 543 * inactivate the control together with notification, if changed.
543 * 544 *
544 * Returns 0 if unchanged, 1 if changed, or a negative error code on failure. 545 * Return: 0 if unchanged, 1 if changed, or a negative error code on failure.
545 */ 546 */
546int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id, 547int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id,
547 int active) 548 int active)
@@ -587,7 +588,7 @@ EXPORT_SYMBOL_GPL(snd_ctl_activate_id);
587 * Finds the control with the old id from the card, and replaces the 588 * Finds the control with the old id from the card, and replaces the
588 * id with the new one. 589 * id with the new one.
589 * 590 *
590 * Returns zero if successful, or a negative error code on failure. 591 * Return: Zero if successful, or a negative error code on failure.
591 */ 592 */
592int snd_ctl_rename_id(struct snd_card *card, struct snd_ctl_elem_id *src_id, 593int snd_ctl_rename_id(struct snd_card *card, struct snd_ctl_elem_id *src_id,
593 struct snd_ctl_elem_id *dst_id) 594 struct snd_ctl_elem_id *dst_id)
@@ -616,10 +617,11 @@ EXPORT_SYMBOL(snd_ctl_rename_id);
616 * 617 *
617 * Finds the control instance with the given number-id from the card. 618 * Finds the control instance with the given number-id from the card.
618 * 619 *
619 * Returns the pointer of the instance if found, or NULL if not.
620 *
621 * The caller must down card->controls_rwsem before calling this function 620 * The caller must down card->controls_rwsem before calling this function
622 * (if the race condition can happen). 621 * (if the race condition can happen).
622 *
623 * Return: The pointer of the instance if found, or %NULL if not.
624 *
623 */ 625 */
624struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, unsigned int numid) 626struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, unsigned int numid)
625{ 627{
@@ -643,10 +645,11 @@ EXPORT_SYMBOL(snd_ctl_find_numid);
643 * 645 *
644 * Finds the control instance with the given id from the card. 646 * Finds the control instance with the given id from the card.
645 * 647 *
646 * Returns the pointer of the instance if found, or NULL if not.
647 *
648 * The caller must down card->controls_rwsem before calling this function 648 * The caller must down card->controls_rwsem before calling this function
649 * (if the race condition can happen). 649 * (if the race condition can happen).
650 *
651 * Return: The pointer of the instance if found, or %NULL if not.
652 *
650 */ 653 */
651struct snd_kcontrol *snd_ctl_find_id(struct snd_card *card, 654struct snd_kcontrol *snd_ctl_find_id(struct snd_card *card,
652 struct snd_ctl_elem_id *id) 655 struct snd_ctl_elem_id *id)
@@ -1710,6 +1713,8 @@ EXPORT_SYMBOL(snd_ctl_boolean_stereo_info);
1710 * Sets all required fields in @info to their appropriate values. 1713 * Sets all required fields in @info to their appropriate values.
1711 * If the control's accessibility is not the default (readable and writable), 1714 * If the control's accessibility is not the default (readable and writable),
1712 * the caller has to fill @info->access. 1715 * the caller has to fill @info->access.
1716 *
1717 * Return: Zero.
1713 */ 1718 */
1714int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels, 1719int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels,
1715 unsigned int items, const char *const names[]) 1720 unsigned int items, const char *const names[])
diff --git a/sound/core/device.c b/sound/core/device.c
index f03cb5444a5a..df88defed176 100644
--- a/sound/core/device.c
+++ b/sound/core/device.c
@@ -39,7 +39,7 @@
39 * The data pointer plays a role as the identifier, too, so the 39 * The data pointer plays a role as the identifier, too, so the
40 * pointer address must be unique and unchanged. 40 * pointer address must be unique and unchanged.
41 * 41 *
42 * Returns zero if successful, or a negative error code on failure. 42 * Return: Zero if successful, or a negative error code on failure.
43 */ 43 */
44int snd_device_new(struct snd_card *card, snd_device_type_t type, 44int snd_device_new(struct snd_card *card, snd_device_type_t type,
45 void *device_data, struct snd_device_ops *ops) 45 void *device_data, struct snd_device_ops *ops)
@@ -73,7 +73,7 @@ EXPORT_SYMBOL(snd_device_new);
73 * callbacks, dev_disconnect and dev_free, corresponding to the state. 73 * callbacks, dev_disconnect and dev_free, corresponding to the state.
74 * Then release the device. 74 * Then release the device.
75 * 75 *
76 * Returns zero if successful, or a negative error code on failure or if the 76 * Return: Zero if successful, or a negative error code on failure or if the
77 * device not found. 77 * device not found.
78 */ 78 */
79int snd_device_free(struct snd_card *card, void *device_data) 79int snd_device_free(struct snd_card *card, void *device_data)
@@ -116,7 +116,7 @@ EXPORT_SYMBOL(snd_device_free);
116 * 116 *
117 * Usually called from snd_card_disconnect(). 117 * Usually called from snd_card_disconnect().
118 * 118 *
119 * Returns zero if successful, or a negative error code on failure or if the 119 * Return: Zero if successful, or a negative error code on failure or if the
120 * device not found. 120 * device not found.
121 */ 121 */
122int snd_device_disconnect(struct snd_card *card, void *device_data) 122int snd_device_disconnect(struct snd_card *card, void *device_data)
@@ -151,7 +151,7 @@ int snd_device_disconnect(struct snd_card *card, void *device_data)
151 * but it can be called later if any new devices are created after 151 * but it can be called later if any new devices are created after
152 * invocation of snd_card_register(). 152 * invocation of snd_card_register().
153 * 153 *
154 * Returns zero if successful, or a negative error code on failure or if the 154 * Return: Zero if successful, or a negative error code on failure or if the
155 * device not found. 155 * device not found.
156 */ 156 */
157int snd_device_register(struct snd_card *card, void *device_data) 157int snd_device_register(struct snd_card *card, void *device_data)
diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c
index 3f7f6628cf7b..d105073298cb 100644
--- a/sound/core/hwdep.c
+++ b/sound/core/hwdep.c
@@ -356,7 +356,7 @@ static const struct file_operations snd_hwdep_f_ops =
356 * The callbacks (hwdep->ops) must be set on the returned instance 356 * The callbacks (hwdep->ops) must be set on the returned instance
357 * after this call manually by the caller. 357 * after this call manually by the caller.
358 * 358 *
359 * Returns zero if successful, or a negative error code on failure. 359 * Return: Zero if successful, or a negative error code on failure.
360 */ 360 */
361int snd_hwdep_new(struct snd_card *card, char *id, int device, 361int snd_hwdep_new(struct snd_card *card, char *id, int device,
362 struct snd_hwdep **rhwdep) 362 struct snd_hwdep **rhwdep)
diff --git a/sound/core/info.c b/sound/core/info.c
index 5bb97e7d325a..c9042b4d3695 100644
--- a/sound/core/info.c
+++ b/sound/core/info.c
@@ -89,7 +89,7 @@ static int resize_info_buffer(struct snd_info_buffer *buffer,
89 char *nbuf; 89 char *nbuf;
90 90
91 nsize = PAGE_ALIGN(nsize); 91 nsize = PAGE_ALIGN(nsize);
92 nbuf = krealloc(buffer->buffer, nsize, GFP_KERNEL); 92 nbuf = krealloc(buffer->buffer, nsize, GFP_KERNEL | __GFP_ZERO);
93 if (! nbuf) 93 if (! nbuf)
94 return -ENOMEM; 94 return -ENOMEM;
95 95
@@ -105,7 +105,7 @@ static int resize_info_buffer(struct snd_info_buffer *buffer,
105 * 105 *
106 * Outputs the string on the procfs buffer just like printf(). 106 * Outputs the string on the procfs buffer just like printf().
107 * 107 *
108 * Returns the size of output string. 108 * Return: The size of output string, or a negative error code.
109 */ 109 */
110int snd_iprintf(struct snd_info_buffer *buffer, const char *fmt, ...) 110int snd_iprintf(struct snd_info_buffer *buffer, const char *fmt, ...)
111{ 111{
@@ -353,7 +353,7 @@ static int snd_info_entry_open(struct inode *inode, struct file *file)
353 goto __nomem; 353 goto __nomem;
354 data->rbuffer = buffer; 354 data->rbuffer = buffer;
355 buffer->len = PAGE_SIZE; 355 buffer->len = PAGE_SIZE;
356 buffer->buffer = kmalloc(buffer->len, GFP_KERNEL); 356 buffer->buffer = kzalloc(buffer->len, GFP_KERNEL);
357 if (buffer->buffer == NULL) 357 if (buffer->buffer == NULL)
358 goto __nomem; 358 goto __nomem;
359 } 359 }
@@ -694,32 +694,27 @@ int snd_info_card_free(struct snd_card *card)
694 * 694 *
695 * Reads one line from the buffer and stores the string. 695 * Reads one line from the buffer and stores the string.
696 * 696 *
697 * Returns zero if successful, or 1 if error or EOF. 697 * Return: Zero if successful, or 1 if error or EOF.
698 */ 698 */
699int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) 699int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len)
700{ 700{
701 int c = -1; 701 int c = -1;
702 702
703 if (snd_BUG_ON(!buffer || !buffer->buffer))
704 return 1;
703 if (len <= 0 || buffer->stop || buffer->error) 705 if (len <= 0 || buffer->stop || buffer->error)
704 return 1; 706 return 1;
705 while (--len > 0) { 707 while (!buffer->stop) {
706 c = buffer->buffer[buffer->curr++]; 708 c = buffer->buffer[buffer->curr++];
707 if (c == '\n') { 709 if (buffer->curr >= buffer->size)
708 if (buffer->curr >= buffer->size)
709 buffer->stop = 1;
710 break;
711 }
712 *line++ = c;
713 if (buffer->curr >= buffer->size) {
714 buffer->stop = 1; 710 buffer->stop = 1;
711 if (c == '\n')
715 break; 712 break;
713 if (len) {
714 len--;
715 *line++ = c;
716 } 716 }
717 } 717 }
718 while (c != '\n' && !buffer->stop) {
719 c = buffer->buffer[buffer->curr++];
720 if (buffer->curr >= buffer->size)
721 buffer->stop = 1;
722 }
723 *line = '\0'; 718 *line = '\0';
724 return 0; 719 return 0;
725} 720}
@@ -735,7 +730,7 @@ EXPORT_SYMBOL(snd_info_get_line);
735 * Parses the original string and copy a token to the given 730 * Parses the original string and copy a token to the given
736 * string buffer. 731 * string buffer.
737 * 732 *
738 * Returns the updated pointer of the original string so that 733 * Return: The updated pointer of the original string so that
739 * it can be used for the next call. 734 * it can be used for the next call.
740 */ 735 */
741const char *snd_info_get_str(char *dest, const char *src, int len) 736const char *snd_info_get_str(char *dest, const char *src, int len)
@@ -774,7 +769,7 @@ EXPORT_SYMBOL(snd_info_get_str);
774 * Usually called from other functions such as 769 * Usually called from other functions such as
775 * snd_info_create_card_entry(). 770 * snd_info_create_card_entry().
776 * 771 *
777 * Returns the pointer of the new instance, or NULL on failure. 772 * Return: The pointer of the new instance, or %NULL on failure.
778 */ 773 */
779static struct snd_info_entry *snd_info_create_entry(const char *name) 774static struct snd_info_entry *snd_info_create_entry(const char *name)
780{ 775{
@@ -803,7 +798,7 @@ static struct snd_info_entry *snd_info_create_entry(const char *name)
803 * 798 *
804 * Creates a new info entry and assigns it to the given module. 799 * Creates a new info entry and assigns it to the given module.
805 * 800 *
806 * Returns the pointer of the new instance, or NULL on failure. 801 * Return: The pointer of the new instance, or %NULL on failure.
807 */ 802 */
808struct snd_info_entry *snd_info_create_module_entry(struct module * module, 803struct snd_info_entry *snd_info_create_module_entry(struct module * module,
809 const char *name, 804 const char *name,
@@ -827,7 +822,7 @@ EXPORT_SYMBOL(snd_info_create_module_entry);
827 * 822 *
828 * Creates a new info entry and assigns it to the given card. 823 * Creates a new info entry and assigns it to the given card.
829 * 824 *
830 * Returns the pointer of the new instance, or NULL on failure. 825 * Return: The pointer of the new instance, or %NULL on failure.
831 */ 826 */
832struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card, 827struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,
833 const char *name, 828 const char *name,
@@ -893,7 +888,7 @@ static int snd_info_dev_register_entry(struct snd_device *device)
893 * For releasing this entry, use snd_device_free() instead of 888 * For releasing this entry, use snd_device_free() instead of
894 * snd_info_free_entry(). 889 * snd_info_free_entry().
895 * 890 *
896 * Returns zero if successful, or a negative error code on failure. 891 * Return: Zero if successful, or a negative error code on failure.
897 */ 892 */
898int snd_card_proc_new(struct snd_card *card, const char *name, 893int snd_card_proc_new(struct snd_card *card, const char *name,
899 struct snd_info_entry **entryp) 894 struct snd_info_entry **entryp)
@@ -949,7 +944,7 @@ EXPORT_SYMBOL(snd_info_free_entry);
949 * 944 *
950 * Registers the proc info entry. 945 * Registers the proc info entry.
951 * 946 *
952 * Returns zero if successful, or a negative error code on failure. 947 * Return: Zero if successful, or a negative error code on failure.
953 */ 948 */
954int snd_info_register(struct snd_info_entry * entry) 949int snd_info_register(struct snd_info_entry * entry)
955{ 950{
diff --git a/sound/core/init.c b/sound/core/init.c
index 7b012d15c2cf..6ef06400dfc8 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -144,7 +144,7 @@ static inline int init_info_for_card(struct snd_card *card)
144 * space for the driver to use freely. The allocated struct is stored 144 * space for the driver to use freely. The allocated struct is stored
145 * in the given card_ret pointer. 145 * in the given card_ret pointer.
146 * 146 *
147 * Returns zero if successful or a negative error code. 147 * Return: Zero if successful or a negative error code.
148 */ 148 */
149int snd_card_create(int idx, const char *xid, 149int snd_card_create(int idx, const char *xid,
150 struct module *module, int extra_size, 150 struct module *module, int extra_size,
@@ -337,7 +337,7 @@ static const struct file_operations snd_shutdown_f_ops =
337 * 337 *
338 * Disconnects all APIs from the file-operations (user space). 338 * Disconnects all APIs from the file-operations (user space).
339 * 339 *
340 * Returns zero, otherwise a negative error code. 340 * Return: Zero, otherwise a negative error code.
341 * 341 *
342 * Note: The current implementation replaces all active file->f_op with special 342 * Note: The current implementation replaces all active file->f_op with special
343 * dummy file operations (they do nothing except release). 343 * dummy file operations (they do nothing except release).
@@ -415,7 +415,7 @@ EXPORT_SYMBOL(snd_card_disconnect);
415 * devices automatically. That is, you don't have to release the devices 415 * devices automatically. That is, you don't have to release the devices
416 * by yourself. 416 * by yourself.
417 * 417 *
418 * Returns zero. Frees all associated devices and frees the control 418 * Return: Zero. Frees all associated devices and frees the control
419 * interface associated to given soundcard. 419 * interface associated to given soundcard.
420 */ 420 */
421static int snd_card_do_free(struct snd_card *card) 421static int snd_card_do_free(struct snd_card *card)
@@ -677,7 +677,7 @@ static struct device_attribute card_number_attrs =
677 * external accesses. Thus, you should call this function at the end 677 * external accesses. Thus, you should call this function at the end
678 * of the initialization of the card. 678 * of the initialization of the card.
679 * 679 *
680 * Returns zero otherwise a negative error code if the registration failed. 680 * Return: Zero otherwise a negative error code if the registration failed.
681 */ 681 */
682int snd_card_register(struct snd_card *card) 682int snd_card_register(struct snd_card *card)
683{ 683{
@@ -849,7 +849,7 @@ int __exit snd_card_info_done(void)
849 * This function adds the component id string to the supported list. 849 * This function adds the component id string to the supported list.
850 * The component can be referred from the alsa-lib. 850 * The component can be referred from the alsa-lib.
851 * 851 *
852 * Returns zero otherwise a negative error code. 852 * Return: Zero otherwise a negative error code.
853 */ 853 */
854 854
855int snd_component_add(struct snd_card *card, const char *component) 855int snd_component_add(struct snd_card *card, const char *component)
@@ -883,7 +883,7 @@ EXPORT_SYMBOL(snd_component_add);
883 * This linked-list is used to keep tracking the connection state, 883 * This linked-list is used to keep tracking the connection state,
884 * and to avoid the release of busy resources by hotplug. 884 * and to avoid the release of busy resources by hotplug.
885 * 885 *
886 * Returns zero or a negative error code. 886 * Return: zero or a negative error code.
887 */ 887 */
888int snd_card_file_add(struct snd_card *card, struct file *file) 888int snd_card_file_add(struct snd_card *card, struct file *file)
889{ 889{
@@ -920,7 +920,7 @@ EXPORT_SYMBOL(snd_card_file_add);
920 * called beforehand, it processes the pending release of 920 * called beforehand, it processes the pending release of
921 * resources. 921 * resources.
922 * 922 *
923 * Returns zero or a negative error code. 923 * Return: Zero or a negative error code.
924 */ 924 */
925int snd_card_file_remove(struct snd_card *card, struct file *file) 925int snd_card_file_remove(struct snd_card *card, struct file *file)
926{ 926{
@@ -959,6 +959,8 @@ EXPORT_SYMBOL(snd_card_file_remove);
959 * 959 *
960 * Waits until the power-state is changed. 960 * Waits until the power-state is changed.
961 * 961 *
962 * Return: Zero if successful, or a negative error code.
963 *
962 * Note: the power lock must be active before call. 964 * Note: the power lock must be active before call.
963 */ 965 */
964int snd_power_wait(struct snd_card *card, unsigned int power_state) 966int snd_power_wait(struct snd_card *card, unsigned int power_state)
diff --git a/sound/core/isadma.c b/sound/core/isadma.c
index c0f1208bb7df..e2b386156a4c 100644
--- a/sound/core/isadma.c
+++ b/sound/core/isadma.c
@@ -81,7 +81,7 @@ EXPORT_SYMBOL(snd_dma_disable);
81 * @dma: the dma number 81 * @dma: the dma number
82 * @size: the dma transfer size 82 * @size: the dma transfer size
83 * 83 *
84 * Returns the current pointer in DMA tranfer buffer in bytes 84 * Return: The current pointer in DMA transfer buffer in bytes.
85 */ 85 */
86unsigned int snd_dma_pointer(unsigned long dma, unsigned int size) 86unsigned int snd_dma_pointer(unsigned long dma, unsigned int size)
87{ 87{
diff --git a/sound/core/jack.c b/sound/core/jack.c
index a06b1651fcba..b35fe7345c20 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -98,8 +98,8 @@ static int snd_jack_dev_register(struct snd_device *device)
98 * 98 *
99 * Creates a new jack object. 99 * Creates a new jack object.
100 * 100 *
101 * Returns zero if successful, or a negative error code on failure. 101 * Return: Zero if successful, or a negative error code on failure.
102 * On success jjack will be initialised. 102 * On success @jjack will be initialised.
103 */ 103 */
104int snd_jack_new(struct snd_card *card, const char *id, int type, 104int snd_jack_new(struct snd_card *card, const char *id, int type,
105 struct snd_jack **jjack) 105 struct snd_jack **jjack)
@@ -189,6 +189,8 @@ EXPORT_SYMBOL(snd_jack_set_parent);
189 * using this abstraction. 189 * using this abstraction.
190 * 190 *
191 * This function may only be called prior to registration of the jack. 191 * This function may only be called prior to registration of the jack.
192 *
193 * Return: Zero if successful, or a negative error code on failure.
192 */ 194 */
193int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type, 195int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type,
194 int keytype) 196 int keytype)
diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index 691569238435..bdf826f4fe0c 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -81,7 +81,7 @@ static inline void dec_snd_pages(int order)
81 * 81 *
82 * Allocates the physically contiguous pages with the given size. 82 * Allocates the physically contiguous pages with the given size.
83 * 83 *
84 * Returns the pointer of the buffer, or NULL if no enoguh memory. 84 * Return: The pointer of the buffer, or %NULL if no enough memory.
85 */ 85 */
86void *snd_malloc_pages(size_t size, gfp_t gfp_flags) 86void *snd_malloc_pages(size_t size, gfp_t gfp_flags)
87{ 87{
@@ -175,9 +175,9 @@ static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
175 * 175 *
176 * Calls the memory-allocator function for the corresponding 176 * Calls the memory-allocator function for the corresponding
177 * buffer type. 177 * buffer type.
178 * 178 *
179 * Returns zero if the buffer with the given size is allocated successfully, 179 * Return: Zero if the buffer with the given size is allocated successfully,
180 * other a negative value at error. 180 * otherwise a negative value on error.
181 */ 181 */
182int snd_dma_alloc_pages(int type, struct device *device, size_t size, 182int snd_dma_alloc_pages(int type, struct device *device, size_t size,
183 struct snd_dma_buffer *dmab) 183 struct snd_dma_buffer *dmab)
@@ -229,9 +229,9 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
229 * buffer type. When no space is left, this function reduces the size and 229 * buffer type. When no space is left, this function reduces the size and
230 * tries to allocate again. The size actually allocated is stored in 230 * tries to allocate again. The size actually allocated is stored in
231 * res_size argument. 231 * res_size argument.
232 * 232 *
233 * Returns zero if the buffer with the given size is allocated successfully, 233 * Return: Zero if the buffer with the given size is allocated successfully,
234 * other a negative value at error. 234 * otherwise a negative value on error.
235 */ 235 */
236int snd_dma_alloc_pages_fallback(int type, struct device *device, size_t size, 236int snd_dma_alloc_pages_fallback(int type, struct device *device, size_t size,
237 struct snd_dma_buffer *dmab) 237 struct snd_dma_buffer *dmab)
@@ -292,7 +292,7 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
292 * Looks for the reserved-buffer list and re-uses if the same buffer 292 * Looks for the reserved-buffer list and re-uses if the same buffer
293 * is found in the list. When the buffer is found, it's removed from the free list. 293 * is found in the list. When the buffer is found, it's removed from the free list.
294 * 294 *
295 * Returns the size of buffer if the buffer is found, or zero if not found. 295 * Return: The size of buffer if the buffer is found, or zero if not found.
296 */ 296 */
297size_t snd_dma_get_reserved_buf(struct snd_dma_buffer *dmab, unsigned int id) 297size_t snd_dma_get_reserved_buf(struct snd_dma_buffer *dmab, unsigned int id)
298{ 298{
@@ -326,8 +326,8 @@ size_t snd_dma_get_reserved_buf(struct snd_dma_buffer *dmab, unsigned int id)
326 * @id: the buffer id 326 * @id: the buffer id
327 * 327 *
328 * Reserves the given buffer as a reserved buffer. 328 * Reserves the given buffer as a reserved buffer.
329 * 329 *
330 * Returns zero if successful, or a negative code at error. 330 * Return: Zero if successful, or a negative code on error.
331 */ 331 */
332int snd_dma_reserve_buf(struct snd_dma_buffer *dmab, unsigned int id) 332int snd_dma_reserve_buf(struct snd_dma_buffer *dmab, unsigned int id)
333{ 333{
diff --git a/sound/core/memory.c b/sound/core/memory.c
index 66a278d0b04e..36c0f1a2e189 100644
--- a/sound/core/memory.c
+++ b/sound/core/memory.c
@@ -33,7 +33,7 @@
33 * 33 *
34 * Copies the data from mmio-space to user-space. 34 * Copies the data from mmio-space to user-space.
35 * 35 *
36 * Returns zero if successful, or non-zero on failure. 36 * Return: Zero if successful, or non-zero on failure.
37 */ 37 */
38int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count) 38int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count)
39{ 39{
@@ -66,7 +66,7 @@ EXPORT_SYMBOL(copy_to_user_fromio);
66 * 66 *
67 * Copies the data from user-space to mmio-space. 67 * Copies the data from user-space to mmio-space.
68 * 68 *
69 * Returns zero if successful, or non-zero on failure. 69 * Return: Zero if successful, or non-zero on failure.
70 */ 70 */
71int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count) 71int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count)
72{ 72{
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 61798f85d030..578327e2bc26 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -637,7 +637,7 @@ static inline int snd_pcm_substream_proc_done(struct snd_pcm_substream *substrea
637 * calling this, i.e. zero must be given to the argument of 637 * calling this, i.e. zero must be given to the argument of
638 * snd_pcm_new(). 638 * snd_pcm_new().
639 * 639 *
640 * Returns zero if successful, or a negative error code on failure. 640 * Return: Zero if successful, or a negative error code on failure.
641 */ 641 */
642int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count) 642int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
643{ 643{
@@ -759,7 +759,7 @@ static int _snd_pcm_new(struct snd_card *card, const char *id, int device,
759 * The pcm operators have to be set afterwards to the new instance 759 * The pcm operators have to be set afterwards to the new instance
760 * via snd_pcm_set_ops(). 760 * via snd_pcm_set_ops().
761 * 761 *
762 * Returns zero if successful, or a negative error code on failure. 762 * Return: Zero if successful, or a negative error code on failure.
763 */ 763 */
764int snd_pcm_new(struct snd_card *card, const char *id, int device, 764int snd_pcm_new(struct snd_card *card, const char *id, int device,
765 int playback_count, int capture_count, struct snd_pcm **rpcm) 765 int playback_count, int capture_count, struct snd_pcm **rpcm)
@@ -787,7 +787,7 @@ EXPORT_SYMBOL(snd_pcm_new);
787 * The pcm operators have to be set afterwards to the new instance 787 * The pcm operators have to be set afterwards to the new instance
788 * via snd_pcm_set_ops(). 788 * via snd_pcm_set_ops().
789 * 789 *
790 * Returns zero if successful, or a negative error code on failure. 790 * Return: Zero if successful, or a negative error code on failure.
791 */ 791 */
792int snd_pcm_new_internal(struct snd_card *card, const char *id, int device, 792int snd_pcm_new_internal(struct snd_card *card, const char *id, int device,
793 int playback_count, int capture_count, 793 int playback_count, int capture_count,
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index c4840ff75d00..41b3dfe68698 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -666,7 +666,8 @@ static inline unsigned int muldiv32(unsigned int a, unsigned int b,
666 * The interval is changed to the range satisfying both intervals. 666 * The interval is changed to the range satisfying both intervals.
667 * The interval status (min, max, integer, etc.) are evaluated. 667 * The interval status (min, max, integer, etc.) are evaluated.
668 * 668 *
669 * Returns non-zero if the value is changed, zero if not changed. 669 * Return: Positive if the value is changed, zero if it's not changed, or a
670 * negative error code.
670 */ 671 */
671int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v) 672int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v)
672{ 673{
@@ -865,7 +866,8 @@ void snd_interval_mulkdiv(const struct snd_interval *a, unsigned int k,
865 * @nump: pointer to store the resultant numerator 866 * @nump: pointer to store the resultant numerator
866 * @denp: pointer to store the resultant denominator 867 * @denp: pointer to store the resultant denominator
867 * 868 *
868 * Returns non-zero if the value is changed, zero if not changed. 869 * Return: Positive if the value is changed, zero if it's not changed, or a
870 * negative error code.
869 */ 871 */
870int snd_interval_ratnum(struct snd_interval *i, 872int snd_interval_ratnum(struct snd_interval *i,
871 unsigned int rats_count, struct snd_ratnum *rats, 873 unsigned int rats_count, struct snd_ratnum *rats,
@@ -983,7 +985,8 @@ EXPORT_SYMBOL(snd_interval_ratnum);
983 * @nump: pointer to store the resultant numerator 985 * @nump: pointer to store the resultant numerator
984 * @denp: pointer to store the resultant denominator 986 * @denp: pointer to store the resultant denominator
985 * 987 *
986 * Returns non-zero if the value is changed, zero if not changed. 988 * Return: Positive if the value is changed, zero if it's not changed, or a
989 * negative error code.
987 */ 990 */
988static int snd_interval_ratden(struct snd_interval *i, 991static int snd_interval_ratden(struct snd_interval *i,
989 unsigned int rats_count, struct snd_ratden *rats, 992 unsigned int rats_count, struct snd_ratden *rats,
@@ -1082,7 +1085,8 @@ static int snd_interval_ratden(struct snd_interval *i,
1082 * When mask is non-zero, only the elements corresponding to bit 1 are 1085 * When mask is non-zero, only the elements corresponding to bit 1 are
1083 * evaluated. 1086 * evaluated.
1084 * 1087 *
1085 * Returns non-zero if the value is changed, zero if not changed. 1088 * Return: Positive if the value is changed, zero if it's not changed, or a
1089 * negative error code.
1086 */ 1090 */
1087int snd_interval_list(struct snd_interval *i, unsigned int count, 1091int snd_interval_list(struct snd_interval *i, unsigned int count,
1088 const unsigned int *list, unsigned int mask) 1092 const unsigned int *list, unsigned int mask)
@@ -1142,7 +1146,7 @@ static int snd_interval_step(struct snd_interval *i, unsigned int min, unsigned
1142 * @private: the private data pointer passed to function 1146 * @private: the private data pointer passed to function
1143 * @dep: the dependent variables 1147 * @dep: the dependent variables
1144 * 1148 *
1145 * Returns zero if successful, or a negative error code on failure. 1149 * Return: Zero if successful, or a negative error code on failure.
1146 */ 1150 */
1147int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, unsigned int cond, 1151int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, unsigned int cond,
1148 int var, 1152 int var,
@@ -1200,6 +1204,8 @@ EXPORT_SYMBOL(snd_pcm_hw_rule_add);
1200 * @mask: the bitmap mask 1204 * @mask: the bitmap mask
1201 * 1205 *
1202 * Apply the constraint of the given bitmap mask to a 32-bit mask parameter. 1206 * Apply the constraint of the given bitmap mask to a 32-bit mask parameter.
1207 *
1208 * Return: Zero if successful, or a negative error code on failure.
1203 */ 1209 */
1204int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var, 1210int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
1205 u_int32_t mask) 1211 u_int32_t mask)
@@ -1220,6 +1226,8 @@ int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime, snd_pcm_hw_param
1220 * @mask: the 64bit bitmap mask 1226 * @mask: the 64bit bitmap mask
1221 * 1227 *
1222 * Apply the constraint of the given bitmap mask to a 64-bit mask parameter. 1228 * Apply the constraint of the given bitmap mask to a 64-bit mask parameter.
1229 *
1230 * Return: Zero if successful, or a negative error code on failure.
1223 */ 1231 */
1224int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var, 1232int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
1225 u_int64_t mask) 1233 u_int64_t mask)
@@ -1240,6 +1248,9 @@ int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_par
1240 * @var: hw_params variable to apply the integer constraint 1248 * @var: hw_params variable to apply the integer constraint
1241 * 1249 *
1242 * Apply the constraint of integer to an interval parameter. 1250 * Apply the constraint of integer to an interval parameter.
1251 *
1252 * Return: Positive if the value is changed, zero if it's not changed, or a
1253 * negative error code.
1243 */ 1254 */
1244int snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var) 1255int snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var)
1245{ 1256{
@@ -1257,6 +1268,9 @@ EXPORT_SYMBOL(snd_pcm_hw_constraint_integer);
1257 * @max: the maximal value 1268 * @max: the maximal value
1258 * 1269 *
1259 * Apply the min/max range constraint to an interval parameter. 1270 * Apply the min/max range constraint to an interval parameter.
1271 *
1272 * Return: Positive if the value is changed, zero if it's not changed, or a
1273 * negative error code.
1260 */ 1274 */
1261int snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var, 1275int snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
1262 unsigned int min, unsigned int max) 1276 unsigned int min, unsigned int max)
@@ -1288,6 +1302,8 @@ static int snd_pcm_hw_rule_list(struct snd_pcm_hw_params *params,
1288 * @l: list 1302 * @l: list
1289 * 1303 *
1290 * Apply the list of constraints to an interval parameter. 1304 * Apply the list of constraints to an interval parameter.
1305 *
1306 * Return: Zero if successful, or a negative error code on failure.
1291 */ 1307 */
1292int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime, 1308int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime,
1293 unsigned int cond, 1309 unsigned int cond,
@@ -1322,6 +1338,8 @@ static int snd_pcm_hw_rule_ratnums(struct snd_pcm_hw_params *params,
1322 * @cond: condition bits 1338 * @cond: condition bits
1323 * @var: hw_params variable to apply the ratnums constraint 1339 * @var: hw_params variable to apply the ratnums constraint
1324 * @r: struct snd_ratnums constriants 1340 * @r: struct snd_ratnums constriants
1341 *
1342 * Return: Zero if successful, or a negative error code on failure.
1325 */ 1343 */
1326int snd_pcm_hw_constraint_ratnums(struct snd_pcm_runtime *runtime, 1344int snd_pcm_hw_constraint_ratnums(struct snd_pcm_runtime *runtime,
1327 unsigned int cond, 1345 unsigned int cond,
@@ -1355,6 +1373,8 @@ static int snd_pcm_hw_rule_ratdens(struct snd_pcm_hw_params *params,
1355 * @cond: condition bits 1373 * @cond: condition bits
1356 * @var: hw_params variable to apply the ratdens constraint 1374 * @var: hw_params variable to apply the ratdens constraint
1357 * @r: struct snd_ratdens constriants 1375 * @r: struct snd_ratdens constriants
1376 *
1377 * Return: Zero if successful, or a negative error code on failure.
1358 */ 1378 */
1359int snd_pcm_hw_constraint_ratdens(struct snd_pcm_runtime *runtime, 1379int snd_pcm_hw_constraint_ratdens(struct snd_pcm_runtime *runtime,
1360 unsigned int cond, 1380 unsigned int cond,
@@ -1386,6 +1406,8 @@ static int snd_pcm_hw_rule_msbits(struct snd_pcm_hw_params *params,
1386 * @cond: condition bits 1406 * @cond: condition bits
1387 * @width: sample bits width 1407 * @width: sample bits width
1388 * @msbits: msbits width 1408 * @msbits: msbits width
1409 *
1410 * Return: Zero if successful, or a negative error code on failure.
1389 */ 1411 */
1390int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime, 1412int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime,
1391 unsigned int cond, 1413 unsigned int cond,
@@ -1414,6 +1436,8 @@ static int snd_pcm_hw_rule_step(struct snd_pcm_hw_params *params,
1414 * @cond: condition bits 1436 * @cond: condition bits
1415 * @var: hw_params variable to apply the step constraint 1437 * @var: hw_params variable to apply the step constraint
1416 * @step: step size 1438 * @step: step size
1439 *
1440 * Return: Zero if successful, or a negative error code on failure.
1417 */ 1441 */
1418int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime, 1442int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
1419 unsigned int cond, 1443 unsigned int cond,
@@ -1444,6 +1468,8 @@ static int snd_pcm_hw_rule_pow2(struct snd_pcm_hw_params *params, struct snd_pcm
1444 * @runtime: PCM runtime instance 1468 * @runtime: PCM runtime instance
1445 * @cond: condition bits 1469 * @cond: condition bits
1446 * @var: hw_params variable to apply the power-of-2 constraint 1470 * @var: hw_params variable to apply the power-of-2 constraint
1471 *
1472 * Return: Zero if successful, or a negative error code on failure.
1447 */ 1473 */
1448int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime, 1474int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
1449 unsigned int cond, 1475 unsigned int cond,
@@ -1470,6 +1496,8 @@ static int snd_pcm_hw_rule_noresample_func(struct snd_pcm_hw_params *params,
1470 * snd_pcm_hw_rule_noresample - add a rule to allow disabling hw resampling 1496 * snd_pcm_hw_rule_noresample - add a rule to allow disabling hw resampling
1471 * @runtime: PCM runtime instance 1497 * @runtime: PCM runtime instance
1472 * @base_rate: the rate at which the hardware does not resample 1498 * @base_rate: the rate at which the hardware does not resample
1499 *
1500 * Return: Zero if successful, or a negative error code on failure.
1473 */ 1501 */
1474int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime, 1502int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
1475 unsigned int base_rate) 1503 unsigned int base_rate)
@@ -1519,8 +1547,8 @@ EXPORT_SYMBOL(_snd_pcm_hw_params_any);
1519 * @var: parameter to retrieve 1547 * @var: parameter to retrieve
1520 * @dir: pointer to the direction (-1,0,1) or %NULL 1548 * @dir: pointer to the direction (-1,0,1) or %NULL
1521 * 1549 *
1522 * Return the value for field @var if it's fixed in configuration space 1550 * Return: The value for field @var if it's fixed in configuration space
1523 * defined by @params. Return -%EINVAL otherwise. 1551 * defined by @params. -%EINVAL otherwise.
1524 */ 1552 */
1525int snd_pcm_hw_param_value(const struct snd_pcm_hw_params *params, 1553int snd_pcm_hw_param_value(const struct snd_pcm_hw_params *params,
1526 snd_pcm_hw_param_t var, int *dir) 1554 snd_pcm_hw_param_t var, int *dir)
@@ -1591,7 +1619,8 @@ static int _snd_pcm_hw_param_first(struct snd_pcm_hw_params *params,
1591 * 1619 *
1592 * Inside configuration space defined by @params remove from @var all 1620 * Inside configuration space defined by @params remove from @var all
1593 * values > minimum. Reduce configuration space accordingly. 1621 * values > minimum. Reduce configuration space accordingly.
1594 * Return the minimum. 1622 *
1623 * Return: The minimum, or a negative error code on failure.
1595 */ 1624 */
1596int snd_pcm_hw_param_first(struct snd_pcm_substream *pcm, 1625int snd_pcm_hw_param_first(struct snd_pcm_substream *pcm,
1597 struct snd_pcm_hw_params *params, 1626 struct snd_pcm_hw_params *params,
@@ -1637,7 +1666,8 @@ static int _snd_pcm_hw_param_last(struct snd_pcm_hw_params *params,
1637 * 1666 *
1638 * Inside configuration space defined by @params remove from @var all 1667 * Inside configuration space defined by @params remove from @var all
1639 * values < maximum. Reduce configuration space accordingly. 1668 * values < maximum. Reduce configuration space accordingly.
1640 * Return the maximum. 1669 *
1670 * Return: The maximum, or a negative error code on failure.
1641 */ 1671 */
1642int snd_pcm_hw_param_last(struct snd_pcm_substream *pcm, 1672int snd_pcm_hw_param_last(struct snd_pcm_substream *pcm,
1643 struct snd_pcm_hw_params *params, 1673 struct snd_pcm_hw_params *params,
@@ -1665,6 +1695,8 @@ EXPORT_SYMBOL(snd_pcm_hw_param_last);
1665 * The configuration chosen is that obtained fixing in this order: 1695 * The configuration chosen is that obtained fixing in this order:
1666 * first access, first format, first subformat, min channels, 1696 * first access, first format, first subformat, min channels,
1667 * min rate, min period time, max buffer size, min tick time 1697 * min rate, min period time, max buffer size, min tick time
1698 *
1699 * Return: Zero if successful, or a negative error code on failure.
1668 */ 1700 */
1669int snd_pcm_hw_params_choose(struct snd_pcm_substream *pcm, 1701int snd_pcm_hw_params_choose(struct snd_pcm_substream *pcm,
1670 struct snd_pcm_hw_params *params) 1702 struct snd_pcm_hw_params *params)
@@ -1771,7 +1803,7 @@ static int snd_pcm_lib_ioctl_fifo_size(struct snd_pcm_substream *substream,
1771 * Processes the generic ioctl commands for PCM. 1803 * Processes the generic ioctl commands for PCM.
1772 * Can be passed as the ioctl callback for PCM ops. 1804 * Can be passed as the ioctl callback for PCM ops.
1773 * 1805 *
1774 * Returns zero if successful, or a negative error code on failure. 1806 * Return: Zero if successful, or a negative error code on failure.
1775 */ 1807 */
1776int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream, 1808int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
1777 unsigned int cmd, void *arg) 1809 unsigned int cmd, void *arg)
@@ -2510,7 +2542,7 @@ static void pcm_chmap_ctl_private_free(struct snd_kcontrol *kcontrol)
2510 * @info_ret: store struct snd_pcm_chmap instance if non-NULL 2542 * @info_ret: store struct snd_pcm_chmap instance if non-NULL
2511 * 2543 *
2512 * Create channel-mapping control elements assigned to the given PCM stream(s). 2544 * Create channel-mapping control elements assigned to the given PCM stream(s).
2513 * Returns zero if succeed, or a negative error value. 2545 * Return: Zero if successful, or a negative error value.
2514 */ 2546 */
2515int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream, 2547int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
2516 const struct snd_pcm_chmap_elem *chmap, 2548 const struct snd_pcm_chmap_elem *chmap,
diff --git a/sound/core/pcm_memory.c b/sound/core/pcm_memory.c
index 69e01c4fc32d..0af622c34e19 100644
--- a/sound/core/pcm_memory.c
+++ b/sound/core/pcm_memory.c
@@ -95,7 +95,7 @@ static void snd_pcm_lib_preallocate_dma_free(struct snd_pcm_substream *substream
95 * 95 *
96 * Releases the pre-allocated buffer of the given substream. 96 * Releases the pre-allocated buffer of the given substream.
97 * 97 *
98 * Returns zero if successful, or a negative error code on failure. 98 * Return: Zero if successful, or a negative error code on failure.
99 */ 99 */
100int snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream) 100int snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream)
101{ 101{
@@ -115,7 +115,7 @@ int snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream)
115 * 115 *
116 * Releases all the pre-allocated buffers on the given pcm. 116 * Releases all the pre-allocated buffers on the given pcm.
117 * 117 *
118 * Returns zero if successful, or a negative error code on failure. 118 * Return: Zero if successful, or a negative error code on failure.
119 */ 119 */
120int snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm) 120int snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm)
121{ 121{
@@ -265,7 +265,7 @@ static int snd_pcm_lib_preallocate_pages1(struct snd_pcm_substream *substream,
265 * destruction time. The dma_buf_id must be unique for all systems 265 * destruction time. The dma_buf_id must be unique for all systems
266 * (in the same DMA buffer type) e.g. using snd_dma_pci_buf_id(). 266 * (in the same DMA buffer type) e.g. using snd_dma_pci_buf_id().
267 * 267 *
268 * Returns zero if successful, or a negative error code on failure. 268 * Return: Zero if successful, or a negative error code on failure.
269 */ 269 */
270int snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream, 270int snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
271 int type, struct device *data, 271 int type, struct device *data,
@@ -289,7 +289,7 @@ EXPORT_SYMBOL(snd_pcm_lib_preallocate_pages);
289 * Do pre-allocation to all substreams of the given pcm for the 289 * Do pre-allocation to all substreams of the given pcm for the
290 * specified DMA type. 290 * specified DMA type.
291 * 291 *
292 * Returns zero if successful, or a negative error code on failure. 292 * Return: Zero if successful, or a negative error code on failure.
293 */ 293 */
294int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm, 294int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
295 int type, void *data, 295 int type, void *data,
@@ -313,8 +313,9 @@ EXPORT_SYMBOL(snd_pcm_lib_preallocate_pages_for_all);
313 * @substream: the pcm substream instance 313 * @substream: the pcm substream instance
314 * @offset: the buffer offset 314 * @offset: the buffer offset
315 * 315 *
316 * Returns the page struct at the given buffer offset.
317 * Used as the page callback of PCM ops. 316 * Used as the page callback of PCM ops.
317 *
318 * Return: The page struct at the given buffer offset. %NULL on failure.
318 */ 319 */
319struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigned long offset) 320struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigned long offset)
320{ 321{
@@ -337,7 +338,7 @@ EXPORT_SYMBOL(snd_pcm_sgbuf_ops_page);
337 * Allocates the DMA buffer on the BUS type given earlier to 338 * Allocates the DMA buffer on the BUS type given earlier to
338 * snd_pcm_lib_preallocate_xxx_pages(). 339 * snd_pcm_lib_preallocate_xxx_pages().
339 * 340 *
340 * Returns 1 if the buffer is changed, 0 if not changed, or a negative 341 * Return: 1 if the buffer is changed, 0 if not changed, or a negative
341 * code on failure. 342 * code on failure.
342 */ 343 */
343int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size) 344int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size)
@@ -390,7 +391,7 @@ EXPORT_SYMBOL(snd_pcm_lib_malloc_pages);
390 * 391 *
391 * Releases the DMA buffer allocated via snd_pcm_lib_malloc_pages(). 392 * Releases the DMA buffer allocated via snd_pcm_lib_malloc_pages().
392 * 393 *
393 * Returns zero if successful, or a negative error code on failure. 394 * Return: Zero if successful, or a negative error code on failure.
394 */ 395 */
395int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream) 396int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream)
396{ 397{
@@ -437,6 +438,8 @@ EXPORT_SYMBOL(_snd_pcm_lib_alloc_vmalloc_buffer);
437 * snd_pcm_lib_free_vmalloc_buffer - free vmalloc buffer 438 * snd_pcm_lib_free_vmalloc_buffer - free vmalloc buffer
438 * @substream: the substream with a buffer allocated by 439 * @substream: the substream with a buffer allocated by
439 * snd_pcm_lib_alloc_vmalloc_buffer() 440 * snd_pcm_lib_alloc_vmalloc_buffer()
441 *
442 * Return: Zero if successful, or a negative error code on failure.
440 */ 443 */
441int snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream) 444int snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream)
442{ 445{
@@ -458,6 +461,8 @@ EXPORT_SYMBOL(snd_pcm_lib_free_vmalloc_buffer);
458 * @offset: offset in the buffer 461 * @offset: offset in the buffer
459 * 462 *
460 * This function is to be used as the page callback in the PCM ops. 463 * This function is to be used as the page callback in the PCM ops.
464 *
465 * Return: The page struct, or %NULL on failure.
461 */ 466 */
462struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream, 467struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream,
463 unsigned long offset) 468 unsigned long offset)
diff --git a/sound/core/pcm_misc.c b/sound/core/pcm_misc.c
index d4fc1bfbe457..b875b19f2d55 100644
--- a/sound/core/pcm_misc.c
+++ b/sound/core/pcm_misc.c
@@ -213,7 +213,7 @@ static struct pcm_format_data pcm_formats[(INT)SNDRV_PCM_FORMAT_LAST+1] = {
213 * snd_pcm_format_signed - Check the PCM format is signed linear 213 * snd_pcm_format_signed - Check the PCM format is signed linear
214 * @format: the format to check 214 * @format: the format to check
215 * 215 *
216 * Returns 1 if the given PCM format is signed linear, 0 if unsigned 216 * Return: 1 if the given PCM format is signed linear, 0 if unsigned
217 * linear, and a negative error code for non-linear formats. 217 * linear, and a negative error code for non-linear formats.
218 */ 218 */
219int snd_pcm_format_signed(snd_pcm_format_t format) 219int snd_pcm_format_signed(snd_pcm_format_t format)
@@ -232,7 +232,7 @@ EXPORT_SYMBOL(snd_pcm_format_signed);
232 * snd_pcm_format_unsigned - Check the PCM format is unsigned linear 232 * snd_pcm_format_unsigned - Check the PCM format is unsigned linear
233 * @format: the format to check 233 * @format: the format to check
234 * 234 *
235 * Returns 1 if the given PCM format is unsigned linear, 0 if signed 235 * Return: 1 if the given PCM format is unsigned linear, 0 if signed
236 * linear, and a negative error code for non-linear formats. 236 * linear, and a negative error code for non-linear formats.
237 */ 237 */
238int snd_pcm_format_unsigned(snd_pcm_format_t format) 238int snd_pcm_format_unsigned(snd_pcm_format_t format)
@@ -251,7 +251,7 @@ EXPORT_SYMBOL(snd_pcm_format_unsigned);
251 * snd_pcm_format_linear - Check the PCM format is linear 251 * snd_pcm_format_linear - Check the PCM format is linear
252 * @format: the format to check 252 * @format: the format to check
253 * 253 *
254 * Returns 1 if the given PCM format is linear, 0 if not. 254 * Return: 1 if the given PCM format is linear, 0 if not.
255 */ 255 */
256int snd_pcm_format_linear(snd_pcm_format_t format) 256int snd_pcm_format_linear(snd_pcm_format_t format)
257{ 257{
@@ -264,7 +264,7 @@ EXPORT_SYMBOL(snd_pcm_format_linear);
264 * snd_pcm_format_little_endian - Check the PCM format is little-endian 264 * snd_pcm_format_little_endian - Check the PCM format is little-endian
265 * @format: the format to check 265 * @format: the format to check
266 * 266 *
267 * Returns 1 if the given PCM format is little-endian, 0 if 267 * Return: 1 if the given PCM format is little-endian, 0 if
268 * big-endian, or a negative error code if endian not specified. 268 * big-endian, or a negative error code if endian not specified.
269 */ 269 */
270int snd_pcm_format_little_endian(snd_pcm_format_t format) 270int snd_pcm_format_little_endian(snd_pcm_format_t format)
@@ -283,7 +283,7 @@ EXPORT_SYMBOL(snd_pcm_format_little_endian);
283 * snd_pcm_format_big_endian - Check the PCM format is big-endian 283 * snd_pcm_format_big_endian - Check the PCM format is big-endian
284 * @format: the format to check 284 * @format: the format to check
285 * 285 *
286 * Returns 1 if the given PCM format is big-endian, 0 if 286 * Return: 1 if the given PCM format is big-endian, 0 if
287 * little-endian, or a negative error code if endian not specified. 287 * little-endian, or a negative error code if endian not specified.
288 */ 288 */
289int snd_pcm_format_big_endian(snd_pcm_format_t format) 289int snd_pcm_format_big_endian(snd_pcm_format_t format)
@@ -302,7 +302,7 @@ EXPORT_SYMBOL(snd_pcm_format_big_endian);
302 * snd_pcm_format_width - return the bit-width of the format 302 * snd_pcm_format_width - return the bit-width of the format
303 * @format: the format to check 303 * @format: the format to check
304 * 304 *
305 * Returns the bit-width of the format, or a negative error code 305 * Return: The bit-width of the format, or a negative error code
306 * if unknown format. 306 * if unknown format.
307 */ 307 */
308int snd_pcm_format_width(snd_pcm_format_t format) 308int snd_pcm_format_width(snd_pcm_format_t format)
@@ -321,7 +321,7 @@ EXPORT_SYMBOL(snd_pcm_format_width);
321 * snd_pcm_format_physical_width - return the physical bit-width of the format 321 * snd_pcm_format_physical_width - return the physical bit-width of the format
322 * @format: the format to check 322 * @format: the format to check
323 * 323 *
324 * Returns the physical bit-width of the format, or a negative error code 324 * Return: The physical bit-width of the format, or a negative error code
325 * if unknown format. 325 * if unknown format.
326 */ 326 */
327int snd_pcm_format_physical_width(snd_pcm_format_t format) 327int snd_pcm_format_physical_width(snd_pcm_format_t format)
@@ -341,7 +341,7 @@ EXPORT_SYMBOL(snd_pcm_format_physical_width);
341 * @format: the format to check 341 * @format: the format to check
342 * @samples: sampling rate 342 * @samples: sampling rate
343 * 343 *
344 * Returns the byte size of the given samples for the format, or a 344 * Return: The byte size of the given samples for the format, or a
345 * negative error code if unknown format. 345 * negative error code if unknown format.
346 */ 346 */
347ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples) 347ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples)
@@ -358,7 +358,7 @@ EXPORT_SYMBOL(snd_pcm_format_size);
358 * snd_pcm_format_silence_64 - return the silent data in 8 bytes array 358 * snd_pcm_format_silence_64 - return the silent data in 8 bytes array
359 * @format: the format to check 359 * @format: the format to check
360 * 360 *
361 * Returns the format pattern to fill or NULL if error. 361 * Return: The format pattern to fill or %NULL if error.
362 */ 362 */
363const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format) 363const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format)
364{ 364{
@@ -379,7 +379,7 @@ EXPORT_SYMBOL(snd_pcm_format_silence_64);
379 * 379 *
380 * Sets the silence data on the buffer for the given samples. 380 * Sets the silence data on the buffer for the given samples.
381 * 381 *
382 * Returns zero if successful, or a negative error code on failure. 382 * Return: Zero if successful, or a negative error code on failure.
383 */ 383 */
384int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int samples) 384int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int samples)
385{ 385{
@@ -449,7 +449,7 @@ EXPORT_SYMBOL(snd_pcm_format_set_silence);
449 * Determines the rate_min and rate_max fields from the rates bits of 449 * Determines the rate_min and rate_max fields from the rates bits of
450 * the given runtime->hw. 450 * the given runtime->hw.
451 * 451 *
452 * Returns zero if successful. 452 * Return: Zero if successful.
453 */ 453 */
454int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime) 454int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime)
455{ 455{
@@ -475,7 +475,7 @@ EXPORT_SYMBOL(snd_pcm_limit_hw_rates);
475 * snd_pcm_rate_to_rate_bit - converts sample rate to SNDRV_PCM_RATE_xxx bit 475 * snd_pcm_rate_to_rate_bit - converts sample rate to SNDRV_PCM_RATE_xxx bit
476 * @rate: the sample rate to convert 476 * @rate: the sample rate to convert
477 * 477 *
478 * Returns the SNDRV_PCM_RATE_xxx flag that corresponds to the given rate, or 478 * Return: The SNDRV_PCM_RATE_xxx flag that corresponds to the given rate, or
479 * SNDRV_PCM_RATE_KNOT for an unknown rate. 479 * SNDRV_PCM_RATE_KNOT for an unknown rate.
480 */ 480 */
481unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate) 481unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate)
@@ -493,8 +493,8 @@ EXPORT_SYMBOL(snd_pcm_rate_to_rate_bit);
493 * snd_pcm_rate_bit_to_rate - converts SNDRV_PCM_RATE_xxx bit to sample rate 493 * snd_pcm_rate_bit_to_rate - converts SNDRV_PCM_RATE_xxx bit to sample rate
494 * @rate_bit: the rate bit to convert 494 * @rate_bit: the rate bit to convert
495 * 495 *
496 * Returns the sample rate that corresponds to the given SNDRV_PCM_RATE_xxx flag 496 * Return: The sample rate that corresponds to the given SNDRV_PCM_RATE_xxx flag
497 * or 0 for an unknown rate bit 497 * or 0 for an unknown rate bit.
498 */ 498 */
499unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit) 499unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit)
500{ 500{
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 71ae86ca64ac..5bce9152b64e 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -898,6 +898,8 @@ static struct action_ops snd_pcm_action_start = {
898/** 898/**
899 * snd_pcm_start - start all linked streams 899 * snd_pcm_start - start all linked streams
900 * @substream: the PCM substream instance 900 * @substream: the PCM substream instance
901 *
902 * Return: Zero if successful, or a negative error code.
901 */ 903 */
902int snd_pcm_start(struct snd_pcm_substream *substream) 904int snd_pcm_start(struct snd_pcm_substream *substream)
903{ 905{
@@ -951,6 +953,8 @@ static struct action_ops snd_pcm_action_stop = {
951 * @state: PCM state after stopping the stream 953 * @state: PCM state after stopping the stream
952 * 954 *
953 * The state of each stream is then changed to the given state unconditionally. 955 * The state of each stream is then changed to the given state unconditionally.
956 *
957 * Return: Zero if succesful, or a negative error code.
954 */ 958 */
955int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state) 959int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state)
956{ 960{
@@ -965,6 +969,8 @@ EXPORT_SYMBOL(snd_pcm_stop);
965 * 969 *
966 * After stopping, the state is changed to SETUP. 970 * After stopping, the state is changed to SETUP.
967 * Unlike snd_pcm_stop(), this affects only the given stream. 971 * Unlike snd_pcm_stop(), this affects only the given stream.
972 *
973 * Return: Zero if succesful, or a negative error code.
968 */ 974 */
969int snd_pcm_drain_done(struct snd_pcm_substream *substream) 975int snd_pcm_drain_done(struct snd_pcm_substream *substream)
970{ 976{
@@ -1098,6 +1104,9 @@ static struct action_ops snd_pcm_action_suspend = {
1098 * @substream: the PCM substream 1104 * @substream: the PCM substream
1099 * 1105 *
1100 * After this call, all streams are changed to SUSPENDED state. 1106 * After this call, all streams are changed to SUSPENDED state.
1107 *
1108 * Return: Zero if successful (or @substream is %NULL), or a negative error
1109 * code.
1101 */ 1110 */
1102int snd_pcm_suspend(struct snd_pcm_substream *substream) 1111int snd_pcm_suspend(struct snd_pcm_substream *substream)
1103{ 1112{
@@ -1120,6 +1129,8 @@ EXPORT_SYMBOL(snd_pcm_suspend);
1120 * @pcm: the PCM instance 1129 * @pcm: the PCM instance
1121 * 1130 *
1122 * After this call, all streams are changed to SUSPENDED state. 1131 * After this call, all streams are changed to SUSPENDED state.
1132 *
1133 * Return: Zero if successful (or @pcm is %NULL), or a negative error code.
1123 */ 1134 */
1124int snd_pcm_suspend_all(struct snd_pcm *pcm) 1135int snd_pcm_suspend_all(struct snd_pcm *pcm)
1125{ 1136{
@@ -1343,6 +1354,8 @@ static struct action_ops snd_pcm_action_prepare = {
1343 * snd_pcm_prepare - prepare the PCM substream to be triggerable 1354 * snd_pcm_prepare - prepare the PCM substream to be triggerable
1344 * @substream: the PCM substream instance 1355 * @substream: the PCM substream instance
1345 * @file: file to refer f_flags 1356 * @file: file to refer f_flags
1357 *
1358 * Return: Zero if successful, or a negative error code.
1346 */ 1359 */
1347static int snd_pcm_prepare(struct snd_pcm_substream *substream, 1360static int snd_pcm_prepare(struct snd_pcm_substream *substream,
1348 struct file *file) 1361 struct file *file)
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 1bb95aeea084..7b596b5751db 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -863,7 +863,7 @@ static int snd_rawmidi_control_ioctl(struct snd_card *card,
863 * 863 *
864 * Reads the data from the internal buffer. 864 * Reads the data from the internal buffer.
865 * 865 *
866 * Returns the size of read data, or a negative error code on failure. 866 * Return: The size of read data, or a negative error code on failure.
867 */ 867 */
868int snd_rawmidi_receive(struct snd_rawmidi_substream *substream, 868int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
869 const unsigned char *buffer, int count) 869 const unsigned char *buffer, int count)
@@ -1024,8 +1024,8 @@ static ssize_t snd_rawmidi_read(struct file *file, char __user *buf, size_t coun
1024/** 1024/**
1025 * snd_rawmidi_transmit_empty - check whether the output buffer is empty 1025 * snd_rawmidi_transmit_empty - check whether the output buffer is empty
1026 * @substream: the rawmidi substream 1026 * @substream: the rawmidi substream
1027 * 1027 *
1028 * Returns 1 if the internal output buffer is empty, 0 if not. 1028 * Return: 1 if the internal output buffer is empty, 0 if not.
1029 */ 1029 */
1030int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream) 1030int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream)
1031{ 1031{
@@ -1055,7 +1055,7 @@ int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream)
1055 * and call snd_rawmidi_transmit_ack() after the transmission is 1055 * and call snd_rawmidi_transmit_ack() after the transmission is
1056 * finished. 1056 * finished.
1057 * 1057 *
1058 * Returns the size of copied data, or a negative error code on failure. 1058 * Return: The size of copied data, or a negative error code on failure.
1059 */ 1059 */
1060int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream, 1060int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
1061 unsigned char *buffer, int count) 1061 unsigned char *buffer, int count)
@@ -1107,7 +1107,7 @@ int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
1107 * the given size and updates the condition. 1107 * the given size and updates the condition.
1108 * Call after the transmission is finished. 1108 * Call after the transmission is finished.
1109 * 1109 *
1110 * Returns the advanced size if successful, or a negative error code on failure. 1110 * Return: The advanced size if successful, or a negative error code on failure.
1111 */ 1111 */
1112int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count) 1112int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
1113{ 1113{
@@ -1140,7 +1140,7 @@ int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
1140 * 1140 *
1141 * Copies data from the buffer to the device and advances the pointer. 1141 * Copies data from the buffer to the device and advances the pointer.
1142 * 1142 *
1143 * Returns the copied size if successful, or a negative error code on failure. 1143 * Return: The copied size if successful, or a negative error code on failure.
1144 */ 1144 */
1145int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream, 1145int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
1146 unsigned char *buffer, int count) 1146 unsigned char *buffer, int count)
@@ -1438,7 +1438,7 @@ static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi,
1438 * Creates a new rawmidi instance. 1438 * Creates a new rawmidi instance.
1439 * Use snd_rawmidi_set_ops() to set the operators to the new instance. 1439 * Use snd_rawmidi_set_ops() to set the operators to the new instance.
1440 * 1440 *
1441 * Returns zero if successful, or a negative error code on failure. 1441 * Return: Zero if successful, or a negative error code on failure.
1442 */ 1442 */
1443int snd_rawmidi_new(struct snd_card *card, char *id, int device, 1443int snd_rawmidi_new(struct snd_card *card, char *id, int device,
1444 int output_count, int input_count, 1444 int output_count, int input_count,
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 70ccdab74153..f002bd911dae 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -102,6 +102,9 @@ static void snd_request_other(int minor)
102 * This function increments the reference counter of the card instance 102 * This function increments the reference counter of the card instance
103 * if an associated instance with the given minor number and type is found. 103 * if an associated instance with the given minor number and type is found.
104 * The caller must call snd_card_unref() appropriately later. 104 * The caller must call snd_card_unref() appropriately later.
105 *
106 * Return: The user data pointer if the specified device is found. %NULL
107 * otherwise.
105 */ 108 */
106void *snd_lookup_minor_data(unsigned int minor, int type) 109void *snd_lookup_minor_data(unsigned int minor, int type)
107{ 110{
@@ -261,7 +264,7 @@ static int snd_kernel_minor(int type, struct snd_card *card, int dev)
261 * Registers an ALSA device file for the given card. 264 * Registers an ALSA device file for the given card.
262 * The operators have to be set in reg parameter. 265 * The operators have to be set in reg parameter.
263 * 266 *
264 * Returns zero if successful, or a negative error code on failure. 267 * Return: Zero if successful, or a negative error code on failure.
265 */ 268 */
266int snd_register_device_for_dev(int type, struct snd_card *card, int dev, 269int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
267 const struct file_operations *f_ops, 270 const struct file_operations *f_ops,
@@ -339,7 +342,7 @@ static int find_snd_minor(int type, struct snd_card *card, int dev)
339 * Unregisters the device file already registered via 342 * Unregisters the device file already registered via
340 * snd_register_device(). 343 * snd_register_device().
341 * 344 *
342 * Returns zero if sucecessful, or a negative error code on failure 345 * Return: Zero if successful, or a negative error code on failure.
343 */ 346 */
344int snd_unregister_device(int type, struct snd_card *card, int dev) 347int snd_unregister_device(int type, struct snd_card *card, int dev)
345{ 348{
diff --git a/sound/core/vmaster.c b/sound/core/vmaster.c
index 0097f3619faa..02f90b4f8b86 100644
--- a/sound/core/vmaster.c
+++ b/sound/core/vmaster.c
@@ -365,8 +365,7 @@ static void master_free(struct snd_kcontrol *kcontrol)
365 * @name: name string of the control element to create 365 * @name: name string of the control element to create
366 * @tlv: optional TLV int array for dB information 366 * @tlv: optional TLV int array for dB information
367 * 367 *
368 * Creates a virtual matster control with the given name string. 368 * Creates a virtual master control with the given name string.
369 * Returns the created control element, or NULL for errors (ENOMEM).
370 * 369 *
371 * After creating a vmaster element, you can add the slave controls 370 * After creating a vmaster element, you can add the slave controls
372 * via snd_ctl_add_slave() or snd_ctl_add_slave_uncached(). 371 * via snd_ctl_add_slave() or snd_ctl_add_slave_uncached().
@@ -375,6 +374,8 @@ static void master_free(struct snd_kcontrol *kcontrol)
375 * for dB scale of the master control. It should be a single element 374 * for dB scale of the master control. It should be a single element
376 * with #SNDRV_CTL_TLVT_DB_SCALE, #SNDRV_CTL_TLV_DB_MINMAX or 375 * with #SNDRV_CTL_TLVT_DB_SCALE, #SNDRV_CTL_TLV_DB_MINMAX or
377 * #SNDRV_CTL_TLVT_DB_MINMAX_MUTE type, and should be the max 0dB. 376 * #SNDRV_CTL_TLVT_DB_MINMAX_MUTE type, and should be the max 0dB.
377 *
378 * Return: The created control element, or %NULL for errors (ENOMEM).
378 */ 379 */
379struct snd_kcontrol *snd_ctl_make_virtual_master(char *name, 380struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
380 const unsigned int *tlv) 381 const unsigned int *tlv)
@@ -426,6 +427,8 @@ EXPORT_SYMBOL(snd_ctl_make_virtual_master);
426 * 427 *
427 * Adds the given hook to the vmaster control element so that it's called 428 * Adds the given hook to the vmaster control element so that it's called
428 * at each time when the value is changed. 429 * at each time when the value is changed.
430 *
431 * Return: Zero.
429 */ 432 */
430int snd_ctl_add_vmaster_hook(struct snd_kcontrol *kcontrol, 433int snd_ctl_add_vmaster_hook(struct snd_kcontrol *kcontrol,
431 void (*hook)(void *private_data, int), 434 void (*hook)(void *private_data, int),
diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c
index 4608c2ca43f8..e3a90d043f03 100644
--- a/sound/drivers/mpu401/mpu401_uart.c
+++ b/sound/drivers/mpu401/mpu401_uart.c
@@ -129,6 +129,8 @@ static void _snd_mpu401_uart_interrupt(struct snd_mpu401 *mpu)
129 * @dev_id: mpu401 instance 129 * @dev_id: mpu401 instance
130 * 130 *
131 * Processes the interrupt for MPU401-UART i/o. 131 * Processes the interrupt for MPU401-UART i/o.
132 *
133 * Return: %IRQ_HANDLED if the interrupt was handled. %IRQ_NONE otherwise.
132 */ 134 */
133irqreturn_t snd_mpu401_uart_interrupt(int irq, void *dev_id) 135irqreturn_t snd_mpu401_uart_interrupt(int irq, void *dev_id)
134{ 136{
@@ -148,6 +150,8 @@ EXPORT_SYMBOL(snd_mpu401_uart_interrupt);
148 * @dev_id: mpu401 instance 150 * @dev_id: mpu401 instance
149 * 151 *
150 * Processes the interrupt for MPU401-UART output. 152 * Processes the interrupt for MPU401-UART output.
153 *
154 * Return: %IRQ_HANDLED if the interrupt was handled. %IRQ_NONE otherwise.
151 */ 155 */
152irqreturn_t snd_mpu401_uart_interrupt_tx(int irq, void *dev_id) 156irqreturn_t snd_mpu401_uart_interrupt_tx(int irq, void *dev_id)
153{ 157{
@@ -519,7 +523,7 @@ static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi)
519 * not the mpu401 instance itself. To access to the mpu401 instance, 523 * not the mpu401 instance itself. To access to the mpu401 instance,
520 * cast from rawmidi->private_data (with struct snd_mpu401 magic-cast). 524 * cast from rawmidi->private_data (with struct snd_mpu401 magic-cast).
521 * 525 *
522 * Returns zero if successful, or a negative error code. 526 * Return: Zero if successful, or a negative error code.
523 */ 527 */
524int snd_mpu401_uart_new(struct snd_card *card, int device, 528int snd_mpu401_uart_new(struct snd_card *card, int device,
525 unsigned short hardware, 529 unsigned short hardware,
diff --git a/sound/oss/sb_common.c b/sound/oss/sb_common.c
index 7d42c5418d1b..851a1da46be1 100644
--- a/sound/oss/sb_common.c
+++ b/sound/oss/sb_common.c
@@ -626,13 +626,12 @@ int sb_dsp_detect(struct address_info *hw_config, int pci, int pciio, struct sb_
626 */ 626 */
627 627
628 628
629 detected_devc = kmalloc(sizeof(sb_devc), GFP_KERNEL); 629 detected_devc = kmemdup(devc, sizeof(sb_devc), GFP_KERNEL);
630 if (detected_devc == NULL) 630 if (detected_devc == NULL)
631 { 631 {
632 printk(KERN_ERR "sb: Can't allocate memory for device information\n"); 632 printk(KERN_ERR "sb: Can't allocate memory for device information\n");
633 return 0; 633 return 0;
634 } 634 }
635 memcpy(detected_devc, devc, sizeof(sb_devc));
636 MDB(printk(KERN_INFO "SB %d.%02d detected OK (%x)\n", devc->major, devc->minor, hw_config->io_base)); 635 MDB(printk(KERN_INFO "SB %d.%02d detected OK (%x)\n", devc->major, devc->minor, hw_config->io_base));
637 return 1; 636 return 1;
638} 637}
diff --git a/sound/oss/uart401.c b/sound/oss/uart401.c
index 8e514a676a0d..5433c6f5eca2 100644
--- a/sound/oss/uart401.c
+++ b/sound/oss/uart401.c
@@ -352,23 +352,26 @@ int probe_uart401(struct address_info *hw_config, struct module *owner)
352 goto cleanup_irq; 352 goto cleanup_irq;
353 } 353 }
354 conf_printf(name, hw_config); 354 conf_printf(name, hw_config);
355 midi_devs[devc->my_dev] = kmalloc(sizeof(struct midi_operations), GFP_KERNEL); 355 midi_devs[devc->my_dev] = kmemdup(&uart401_operations,
356 sizeof(struct midi_operations),
357 GFP_KERNEL);
356 if (!midi_devs[devc->my_dev]) { 358 if (!midi_devs[devc->my_dev]) {
357 printk(KERN_ERR "uart401: Failed to allocate memory\n"); 359 printk(KERN_ERR "uart401: Failed to allocate memory\n");
358 goto cleanup_unload_mididev; 360 goto cleanup_unload_mididev;
359 } 361 }
360 memcpy(midi_devs[devc->my_dev], &uart401_operations, sizeof(struct midi_operations));
361 362
362 if (owner) 363 if (owner)
363 midi_devs[devc->my_dev]->owner = owner; 364 midi_devs[devc->my_dev]->owner = owner;
364 365
365 midi_devs[devc->my_dev]->devc = devc; 366 midi_devs[devc->my_dev]->devc = devc;
366 midi_devs[devc->my_dev]->converter = kmalloc(sizeof(struct synth_operations), GFP_KERNEL); 367 midi_devs[devc->my_dev]->converter = kmemdup(&std_midi_synth,
368 sizeof(struct synth_operations),
369 GFP_KERNEL);
370
367 if (!midi_devs[devc->my_dev]->converter) { 371 if (!midi_devs[devc->my_dev]->converter) {
368 printk(KERN_WARNING "uart401: Failed to allocate memory\n"); 372 printk(KERN_WARNING "uart401: Failed to allocate memory\n");
369 goto cleanup_midi_devs; 373 goto cleanup_midi_devs;
370 } 374 }
371 memcpy(midi_devs[devc->my_dev]->converter, &std_midi_synth, sizeof(struct synth_operations));
372 strcpy(midi_devs[devc->my_dev]->info.name, name); 375 strcpy(midi_devs[devc->my_dev]->info.name, name);
373 midi_devs[devc->my_dev]->converter->id = "UART401"; 376 midi_devs[devc->my_dev]->converter->id = "UART401";
374 midi_devs[devc->my_dev]->converter->midi_dev = devc->my_dev; 377 midi_devs[devc->my_dev]->converter->midi_dev = devc->my_dev;
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 8b0f99688303..d37c683cfd7a 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -299,7 +299,7 @@ EXPORT_SYMBOL(snd_ac97_write);
299 * Reads a value from the given register. This will invoke the read 299 * Reads a value from the given register. This will invoke the read
300 * callback directly after the register check. 300 * callback directly after the register check.
301 * 301 *
302 * Returns the read value. 302 * Return: The read value.
303 */ 303 */
304unsigned short snd_ac97_read(struct snd_ac97 *ac97, unsigned short reg) 304unsigned short snd_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
305{ 305{
@@ -352,7 +352,7 @@ EXPORT_SYMBOL(snd_ac97_write_cache);
352 * Compares the value with the register cache and updates the value 352 * Compares the value with the register cache and updates the value
353 * only when the value is changed. 353 * only when the value is changed.
354 * 354 *
355 * Returns 1 if the value is changed, 0 if no change, or a negative 355 * Return: 1 if the value is changed, 0 if no change, or a negative
356 * code on failure. 356 * code on failure.
357 */ 357 */
358int snd_ac97_update(struct snd_ac97 *ac97, unsigned short reg, unsigned short value) 358int snd_ac97_update(struct snd_ac97 *ac97, unsigned short reg, unsigned short value)
@@ -384,7 +384,7 @@ EXPORT_SYMBOL(snd_ac97_update);
384 * Updates the masked-bits on the given register only when the value 384 * Updates the masked-bits on the given register only when the value
385 * is changed. 385 * is changed.
386 * 386 *
387 * Returns 1 if the bits are changed, 0 if no change, or a negative 387 * Return: 1 if the bits are changed, 0 if no change, or a negative
388 * code on failure. 388 * code on failure.
389 */ 389 */
390int snd_ac97_update_bits(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value) 390int snd_ac97_update_bits(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value)
@@ -1836,7 +1836,7 @@ void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name, int m
1836 * snd_ac97_get_short_name - retrieve codec name 1836 * snd_ac97_get_short_name - retrieve codec name
1837 * @ac97: the codec instance 1837 * @ac97: the codec instance
1838 * 1838 *
1839 * Returns the short identifying name of the codec. 1839 * Return: The short identifying name of the codec.
1840 */ 1840 */
1841const char *snd_ac97_get_short_name(struct snd_ac97 *ac97) 1841const char *snd_ac97_get_short_name(struct snd_ac97 *ac97)
1842{ 1842{
@@ -1910,7 +1910,7 @@ static int ac97_reset_wait(struct snd_ac97 *ac97, int timeout, int with_modem)
1910 * The AC97 bus instance is registered as a low-level device, so you don't 1910 * The AC97 bus instance is registered as a low-level device, so you don't
1911 * have to release it manually. 1911 * have to release it manually.
1912 * 1912 *
1913 * Returns zero if successful, or a negative error code on failure. 1913 * Return: Zero if successful, or a negative error code on failure.
1914 */ 1914 */
1915int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops, 1915int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops,
1916 void *private_data, struct snd_ac97_bus **rbus) 1916 void *private_data, struct snd_ac97_bus **rbus)
@@ -2006,7 +2006,7 @@ static void do_update_power(struct work_struct *work)
2006 * The ac97 instance is registered as a low-level device, so you don't 2006 * The ac97 instance is registered as a low-level device, so you don't
2007 * have to release it manually. 2007 * have to release it manually.
2008 * 2008 *
2009 * Returns zero if successful, or a negative error code on failure. 2009 * Return: Zero if successful, or a negative error code on failure.
2010 */ 2010 */
2011int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template, struct snd_ac97 **rac97) 2011int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template, struct snd_ac97 **rac97)
2012{ 2012{
@@ -2373,6 +2373,8 @@ static struct ac97_power_reg power_regs[PWIDX_SIZE] = {
2373 * @powerup: non-zero when power up the part 2373 * @powerup: non-zero when power up the part
2374 * 2374 *
2375 * Update the AC97 powerdown register bits of the given part. 2375 * Update the AC97 powerdown register bits of the given part.
2376 *
2377 * Return: Zero.
2376 */ 2378 */
2377int snd_ac97_update_power(struct snd_ac97 *ac97, int reg, int powerup) 2379int snd_ac97_update_power(struct snd_ac97 *ac97, int reg, int powerup)
2378{ 2380{
@@ -2885,7 +2887,7 @@ static int apply_quirk_str(struct snd_ac97 *ac97, const char *typestr)
2885 * headphone (true line-out) control as "Master". 2887 * headphone (true line-out) control as "Master".
2886 * The quirk-list must be terminated with a zero-filled entry. 2888 * The quirk-list must be terminated with a zero-filled entry.
2887 * 2889 *
2888 * Returns zero if successful, or a negative error code on failure. 2890 * Return: Zero if successful, or a negative error code on failure.
2889 */ 2891 */
2890 2892
2891int snd_ac97_tune_hardware(struct snd_ac97 *ac97, struct ac97_quirk *quirk, const char *override) 2893int snd_ac97_tune_hardware(struct snd_ac97 *ac97, struct ac97_quirk *quirk, const char *override)
diff --git a/sound/pci/ac97/ac97_pcm.c b/sound/pci/ac97/ac97_pcm.c
index f1488fc176d5..eab0fc9ff2e0 100644
--- a/sound/pci/ac97/ac97_pcm.c
+++ b/sound/pci/ac97/ac97_pcm.c
@@ -253,7 +253,7 @@ static int set_spdif_rate(struct snd_ac97 *ac97, unsigned short rate)
253 * AC97_SPDIF is accepted as a pseudo register to modify the SPDIF 253 * AC97_SPDIF is accepted as a pseudo register to modify the SPDIF
254 * status bits. 254 * status bits.
255 * 255 *
256 * Returns zero if successful, or a negative error code on failure. 256 * Return: Zero if successful, or a negative error code on failure.
257 */ 257 */
258int snd_ac97_set_rate(struct snd_ac97 *ac97, int reg, unsigned int rate) 258int snd_ac97_set_rate(struct snd_ac97 *ac97, int reg, unsigned int rate)
259{ 259{
@@ -440,6 +440,8 @@ static unsigned int get_rates(struct ac97_pcm *pcm, unsigned int cidx, unsigned
440 * It assigns available AC97 slots for given PCMs. If none or only 440 * It assigns available AC97 slots for given PCMs. If none or only
441 * some slots are available, pcm->xxx.slots and pcm->xxx.rslots[] members 441 * some slots are available, pcm->xxx.slots and pcm->xxx.rslots[] members
442 * are reduced and might be zero. 442 * are reduced and might be zero.
443 *
444 * Return: Zero if successful, or a negative error code on failure.
443 */ 445 */
444int snd_ac97_pcm_assign(struct snd_ac97_bus *bus, 446int snd_ac97_pcm_assign(struct snd_ac97_bus *bus,
445 unsigned short pcms_count, 447 unsigned short pcms_count,
@@ -562,6 +564,8 @@ EXPORT_SYMBOL(snd_ac97_pcm_assign);
562 * @slots: a subset of allocated slots (snd_ac97_pcm_assign) for this pcm 564 * @slots: a subset of allocated slots (snd_ac97_pcm_assign) for this pcm
563 * 565 *
564 * It locks the specified slots and sets the given rate to AC97 registers. 566 * It locks the specified slots and sets the given rate to AC97 registers.
567 *
568 * Return: Zero if successful, or a negative error code on failure.
565 */ 569 */
566int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate, 570int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate,
567 enum ac97_pcm_cfg cfg, unsigned short slots) 571 enum ac97_pcm_cfg cfg, unsigned short slots)
@@ -644,6 +648,8 @@ EXPORT_SYMBOL(snd_ac97_pcm_open);
644 * @pcm: the ac97 pcm instance 648 * @pcm: the ac97 pcm instance
645 * 649 *
646 * It frees the locked AC97 slots. 650 * It frees the locked AC97 slots.
651 *
652 * Return: Zero.
647 */ 653 */
648int snd_ac97_pcm_close(struct ac97_pcm *pcm) 654int snd_ac97_pcm_close(struct ac97_pcm *pcm)
649{ 655{
@@ -718,6 +724,8 @@ static int double_rate_hw_constraint_channels(struct snd_pcm_hw_params *params,
718 * 724 *
719 * Installs the hardware constraint rules to prevent using double rates and 725 * Installs the hardware constraint rules to prevent using double rates and
720 * more than two channels at the same time. 726 * more than two channels at the same time.
727 *
728 * Return: Zero if successful, or a negative error code on failure.
721 */ 729 */
722int snd_ac97_pcm_double_rate_rules(struct snd_pcm_runtime *runtime) 730int snd_ac97_pcm_double_rate_rules(struct snd_pcm_runtime *runtime)
723{ 731{
diff --git a/sound/pci/hda/hda_auto_parser.c b/sound/pci/hda/hda_auto_parser.c
index a3ea76a4c9d2..7c11d46b84d3 100644
--- a/sound/pci/hda/hda_auto_parser.c
+++ b/sound/pci/hda/hda_auto_parser.c
@@ -119,6 +119,32 @@ static bool check_pincap_validity(struct hda_codec *codec, hda_nid_t pin,
119 } 119 }
120} 120}
121 121
122static bool can_be_headset_mic(struct hda_codec *codec,
123 struct auto_pin_cfg_item *item,
124 int seq_number)
125{
126 int attr;
127 unsigned int def_conf;
128 if (item->type != AUTO_PIN_MIC)
129 return false;
130
131 if (item->is_headset_mic || item->is_headphone_mic)
132 return false; /* Already assigned */
133
134 def_conf = snd_hda_codec_get_pincfg(codec, item->pin);
135 attr = snd_hda_get_input_pin_attr(def_conf);
136 if (attr <= INPUT_PIN_ATTR_DOCK)
137 return false;
138
139 if (seq_number >= 0) {
140 int seq = get_defcfg_sequence(def_conf);
141 if (seq != seq_number)
142 return false;
143 }
144
145 return true;
146}
147
122/* 148/*
123 * Parse all pin widgets and store the useful pin nids to cfg 149 * Parse all pin widgets and store the useful pin nids to cfg
124 * 150 *
@@ -260,6 +286,38 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
260 } 286 }
261 } 287 }
262 288
289 /* Find a pin that could be a headset or headphone mic */
290 if (cond_flags & HDA_PINCFG_HEADSET_MIC || cond_flags & HDA_PINCFG_HEADPHONE_MIC) {
291 bool hsmic = !!(cond_flags & HDA_PINCFG_HEADSET_MIC);
292 bool hpmic = !!(cond_flags & HDA_PINCFG_HEADPHONE_MIC);
293 for (i = 0; (hsmic || hpmic) && (i < cfg->num_inputs); i++)
294 if (hsmic && can_be_headset_mic(codec, &cfg->inputs[i], 0xc)) {
295 cfg->inputs[i].is_headset_mic = 1;
296 hsmic = false;
297 } else if (hpmic && can_be_headset_mic(codec, &cfg->inputs[i], 0xd)) {
298 cfg->inputs[i].is_headphone_mic = 1;
299 hpmic = false;
300 }
301
302 /* If we didn't find our sequence number mark, fall back to any sequence number */
303 for (i = 0; (hsmic || hpmic) && (i < cfg->num_inputs); i++) {
304 if (!can_be_headset_mic(codec, &cfg->inputs[i], -1))
305 continue;
306 if (hsmic) {
307 cfg->inputs[i].is_headset_mic = 1;
308 hsmic = false;
309 } else if (hpmic) {
310 cfg->inputs[i].is_headphone_mic = 1;
311 hpmic = false;
312 }
313 }
314
315 if (hsmic)
316 snd_printdd("Told to look for a headset mic, but didn't find any.\n");
317 if (hpmic)
318 snd_printdd("Told to look for a headphone mic, but didn't find any.\n");
319 }
320
263 /* FIX-UP: 321 /* FIX-UP:
264 * If no line-out is defined but multiple HPs are found, 322 * If no line-out is defined but multiple HPs are found,
265 * some of them might be the real line-outs. 323 * some of them might be the real line-outs.
@@ -388,6 +446,7 @@ EXPORT_SYMBOL_HDA(snd_hda_get_input_pin_attr);
388 */ 446 */
389 447
390static const char *hda_get_input_pin_label(struct hda_codec *codec, 448static const char *hda_get_input_pin_label(struct hda_codec *codec,
449 const struct auto_pin_cfg_item *item,
391 hda_nid_t pin, bool check_location) 450 hda_nid_t pin, bool check_location)
392{ 451{
393 unsigned int def_conf; 452 unsigned int def_conf;
@@ -400,6 +459,10 @@ static const char *hda_get_input_pin_label(struct hda_codec *codec,
400 459
401 switch (get_defcfg_device(def_conf)) { 460 switch (get_defcfg_device(def_conf)) {
402 case AC_JACK_MIC_IN: 461 case AC_JACK_MIC_IN:
462 if (item && item->is_headset_mic)
463 return "Headset Mic";
464 if (item && item->is_headphone_mic)
465 return "Headphone Mic";
403 if (!check_location) 466 if (!check_location)
404 return "Mic"; 467 return "Mic";
405 attr = snd_hda_get_input_pin_attr(def_conf); 468 attr = snd_hda_get_input_pin_attr(def_conf);
@@ -480,7 +543,8 @@ const char *hda_get_autocfg_input_label(struct hda_codec *codec,
480 has_multiple_pins = 1; 543 has_multiple_pins = 1;
481 if (has_multiple_pins && type == AUTO_PIN_MIC) 544 if (has_multiple_pins && type == AUTO_PIN_MIC)
482 has_multiple_pins &= check_mic_location_need(codec, cfg, input); 545 has_multiple_pins &= check_mic_location_need(codec, cfg, input);
483 return hda_get_input_pin_label(codec, cfg->inputs[input].pin, 546 return hda_get_input_pin_label(codec, &cfg->inputs[input],
547 cfg->inputs[input].pin,
484 has_multiple_pins); 548 has_multiple_pins);
485} 549}
486EXPORT_SYMBOL_HDA(hda_get_autocfg_input_label); 550EXPORT_SYMBOL_HDA(hda_get_autocfg_input_label);
@@ -649,7 +713,7 @@ int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
649 } 713 }
650 } 714 }
651 if (!name) 715 if (!name)
652 name = hda_get_input_pin_label(codec, nid, true); 716 name = hda_get_input_pin_label(codec, NULL, nid, true);
653 break; 717 break;
654 } 718 }
655 if (!name) 719 if (!name)
diff --git a/sound/pci/hda/hda_auto_parser.h b/sound/pci/hda/hda_auto_parser.h
index f74807138b49..e941f604f5e5 100644
--- a/sound/pci/hda/hda_auto_parser.h
+++ b/sound/pci/hda/hda_auto_parser.h
@@ -36,6 +36,8 @@ enum {
36struct auto_pin_cfg_item { 36struct auto_pin_cfg_item {
37 hda_nid_t pin; 37 hda_nid_t pin;
38 int type; 38 int type;
39 unsigned int is_headset_mic:1;
40 unsigned int is_headphone_mic:1; /* Mic-only in headphone jack */
39}; 41};
40 42
41struct auto_pin_cfg; 43struct auto_pin_cfg;
@@ -78,8 +80,10 @@ struct auto_pin_cfg {
78}; 80};
79 81
80/* bit-flags for snd_hda_parse_pin_def_config() behavior */ 82/* bit-flags for snd_hda_parse_pin_def_config() behavior */
81#define HDA_PINCFG_NO_HP_FIXUP (1 << 0) /* no HP-split */ 83#define HDA_PINCFG_NO_HP_FIXUP (1 << 0) /* no HP-split */
82#define HDA_PINCFG_NO_LO_FIXUP (1 << 1) /* don't take other outs as LO */ 84#define HDA_PINCFG_NO_LO_FIXUP (1 << 1) /* don't take other outs as LO */
85#define HDA_PINCFG_HEADSET_MIC (1 << 2) /* Try to find headset mic; mark seq number as 0xc to trigger */
86#define HDA_PINCFG_HEADPHONE_MIC (1 << 3) /* Try to find headphone mic; mark seq number as 0xd to trigger */
83 87
84int snd_hda_parse_pin_defcfg(struct hda_codec *codec, 88int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
85 struct auto_pin_cfg *cfg, 89 struct auto_pin_cfg *cfg,
@@ -90,4 +94,25 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
90#define snd_hda_parse_pin_def_config(codec, cfg, ignore) \ 94#define snd_hda_parse_pin_def_config(codec, cfg, ignore) \
91 snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0) 95 snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0)
92 96
97static inline int auto_cfg_hp_outs(const struct auto_pin_cfg *cfg)
98{
99 return (cfg->line_out_type == AUTO_PIN_HP_OUT) ?
100 cfg->line_outs : cfg->hp_outs;
101}
102static inline const hda_nid_t *auto_cfg_hp_pins(const struct auto_pin_cfg *cfg)
103{
104 return (cfg->line_out_type == AUTO_PIN_HP_OUT) ?
105 cfg->line_out_pins : cfg->hp_pins;
106}
107static inline int auto_cfg_speaker_outs(const struct auto_pin_cfg *cfg)
108{
109 return (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) ?
110 cfg->line_outs : cfg->speaker_outs;
111}
112static inline const hda_nid_t *auto_cfg_speaker_pins(const struct auto_pin_cfg *cfg)
113{
114 return (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) ?
115 cfg->line_out_pins : cfg->speaker_pins;
116}
117
93#endif /* __SOUND_HDA_AUTO_PARSER_H */ 118#endif /* __SOUND_HDA_AUTO_PARSER_H */
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 0849aac449f2..63c99090a4ec 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -39,13 +39,23 @@ static void snd_hda_generate_beep(struct work_struct *work)
39 struct hda_beep *beep = 39 struct hda_beep *beep =
40 container_of(work, struct hda_beep, beep_work); 40 container_of(work, struct hda_beep, beep_work);
41 struct hda_codec *codec = beep->codec; 41 struct hda_codec *codec = beep->codec;
42 int tone;
42 43
43 if (!beep->enabled) 44 if (!beep->enabled)
44 return; 45 return;
45 46
47 tone = beep->tone;
48 if (tone && !beep->playing) {
49 snd_hda_power_up(codec);
50 beep->playing = 1;
51 }
46 /* generate tone */ 52 /* generate tone */
47 snd_hda_codec_write(codec, beep->nid, 0, 53 snd_hda_codec_write(codec, beep->nid, 0,
48 AC_VERB_SET_BEEP_CONTROL, beep->tone); 54 AC_VERB_SET_BEEP_CONTROL, tone);
55 if (!tone && beep->playing) {
56 beep->playing = 0;
57 snd_hda_power_down(codec);
58 }
49} 59}
50 60
51/* (non-standard) Linear beep tone calculation for IDT/STAC codecs 61/* (non-standard) Linear beep tone calculation for IDT/STAC codecs
@@ -115,14 +125,23 @@ static int snd_hda_beep_event(struct input_dev *dev, unsigned int type,
115 return 0; 125 return 0;
116} 126}
117 127
128static void turn_off_beep(struct hda_beep *beep)
129{
130 cancel_work_sync(&beep->beep_work);
131 if (beep->playing) {
132 /* turn off beep */
133 snd_hda_codec_write(beep->codec, beep->nid, 0,
134 AC_VERB_SET_BEEP_CONTROL, 0);
135 beep->playing = 0;
136 snd_hda_power_down(beep->codec);
137 }
138}
139
118static void snd_hda_do_detach(struct hda_beep *beep) 140static void snd_hda_do_detach(struct hda_beep *beep)
119{ 141{
120 input_unregister_device(beep->dev); 142 input_unregister_device(beep->dev);
121 beep->dev = NULL; 143 beep->dev = NULL;
122 cancel_work_sync(&beep->beep_work); 144 turn_off_beep(beep);
123 /* turn off beep for sure */
124 snd_hda_codec_write(beep->codec, beep->nid, 0,
125 AC_VERB_SET_BEEP_CONTROL, 0);
126} 145}
127 146
128static int snd_hda_do_attach(struct hda_beep *beep) 147static int snd_hda_do_attach(struct hda_beep *beep)
@@ -170,12 +189,8 @@ int snd_hda_enable_beep_device(struct hda_codec *codec, int enable)
170 enable = !!enable; 189 enable = !!enable;
171 if (beep->enabled != enable) { 190 if (beep->enabled != enable) {
172 beep->enabled = enable; 191 beep->enabled = enable;
173 if (!enable) { 192 if (!enable)
174 cancel_work_sync(&beep->beep_work); 193 turn_off_beep(beep);
175 /* turn off beep */
176 snd_hda_codec_write(beep->codec, beep->nid, 0,
177 AC_VERB_SET_BEEP_CONTROL, 0);
178 }
179 return 1; 194 return 1;
180 } 195 }
181 return 0; 196 return 0;
@@ -198,7 +213,7 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
198 snprintf(beep->phys, sizeof(beep->phys), 213 snprintf(beep->phys, sizeof(beep->phys),
199 "card%d/codec#%d/beep0", codec->bus->card->number, codec->addr); 214 "card%d/codec#%d/beep0", codec->bus->card->number, codec->addr);
200 /* enable linear scale */ 215 /* enable linear scale */
201 snd_hda_codec_write(codec, nid, 0, 216 snd_hda_codec_write_cache(codec, nid, 0,
202 AC_VERB_SET_DIGI_CONVERT_2, 0x01); 217 AC_VERB_SET_DIGI_CONVERT_2, 0x01);
203 218
204 beep->nid = nid; 219 beep->nid = nid;
diff --git a/sound/pci/hda/hda_beep.h b/sound/pci/hda/hda_beep.h
index 4dc6933bc655..cb88464676b6 100644
--- a/sound/pci/hda/hda_beep.h
+++ b/sound/pci/hda/hda_beep.h
@@ -36,6 +36,7 @@ struct hda_beep {
36 hda_nid_t nid; 36 hda_nid_t nid;
37 unsigned int enabled:1; 37 unsigned int enabled:1;
38 unsigned int linear_tone:1; /* linear tone for IDT/STAC codec */ 38 unsigned int linear_tone:1; /* linear tone for IDT/STAC codec */
39 unsigned int playing:1;
39 struct work_struct beep_work; /* scheduled task for beep event */ 40 struct work_struct beep_work; /* scheduled task for beep event */
40 struct mutex mutex; 41 struct mutex mutex;
41}; 42};
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 4aba7646dd9c..e37b7388e8aa 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -1300,8 +1300,6 @@ static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec,
1300 1300
1301static unsigned int hda_set_power_state(struct hda_codec *codec, 1301static unsigned int hda_set_power_state(struct hda_codec *codec,
1302 unsigned int power_state); 1302 unsigned int power_state);
1303static unsigned int default_power_filter(struct hda_codec *codec, hda_nid_t nid,
1304 unsigned int power_state);
1305 1303
1306/** 1304/**
1307 * snd_hda_codec_new - create a HDA codec 1305 * snd_hda_codec_new - create a HDA codec
@@ -1422,7 +1420,6 @@ int snd_hda_codec_new(struct hda_bus *bus,
1422#endif 1420#endif
1423 codec->epss = snd_hda_codec_get_supported_ps(codec, fg, 1421 codec->epss = snd_hda_codec_get_supported_ps(codec, fg,
1424 AC_PWRST_EPSS); 1422 AC_PWRST_EPSS);
1425 codec->power_filter = default_power_filter;
1426 1423
1427 /* power-up all before initialization */ 1424 /* power-up all before initialization */
1428 hda_set_power_state(codec, AC_PWRST_D0); 1425 hda_set_power_state(codec, AC_PWRST_D0);
@@ -3770,8 +3767,9 @@ static unsigned int hda_sync_power_state(struct hda_codec *codec,
3770} 3767}
3771 3768
3772/* don't power down the widget if it controls eapd and EAPD_BTLENABLE is set */ 3769/* don't power down the widget if it controls eapd and EAPD_BTLENABLE is set */
3773static unsigned int default_power_filter(struct hda_codec *codec, hda_nid_t nid, 3770unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
3774 unsigned int power_state) 3771 hda_nid_t nid,
3772 unsigned int power_state)
3775{ 3773{
3776 if (power_state == AC_PWRST_D3 && 3774 if (power_state == AC_PWRST_D3 &&
3777 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN && 3775 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN &&
@@ -3783,6 +3781,7 @@ static unsigned int default_power_filter(struct hda_codec *codec, hda_nid_t nid,
3783 } 3781 }
3784 return power_state; 3782 return power_state;
3785} 3783}
3784EXPORT_SYMBOL_HDA(snd_hda_codec_eapd_power_filter);
3786 3785
3787/* 3786/*
3788 * set power state of the codec, and return the power state 3787 * set power state of the codec, and return the power state
@@ -3827,8 +3826,8 @@ static void sync_power_up_states(struct hda_codec *codec)
3827 hda_nid_t nid = codec->start_nid; 3826 hda_nid_t nid = codec->start_nid;
3828 int i; 3827 int i;
3829 3828
3830 /* don't care if no or standard filter is used */ 3829 /* don't care if no filter is used */
3831 if (!codec->power_filter || codec->power_filter == default_power_filter) 3830 if (!codec->power_filter)
3832 return; 3831 return;
3833 3832
3834 for (i = 0; i < codec->num_nodes; i++, nid++) { 3833 for (i = 0; i < codec->num_nodes; i++, nid++) {
@@ -5546,14 +5545,12 @@ void *snd_array_new(struct snd_array *array)
5546 if (array->used >= array->alloced) { 5545 if (array->used >= array->alloced) {
5547 int num = array->alloced + array->alloc_align; 5546 int num = array->alloced + array->alloc_align;
5548 int size = (num + 1) * array->elem_size; 5547 int size = (num + 1) * array->elem_size;
5549 int oldsize = array->alloced * array->elem_size;
5550 void *nlist; 5548 void *nlist;
5551 if (snd_BUG_ON(num >= 4096)) 5549 if (snd_BUG_ON(num >= 4096))
5552 return NULL; 5550 return NULL;
5553 nlist = krealloc(array->list, size, GFP_KERNEL); 5551 nlist = krealloc(array->list, size, GFP_KERNEL | __GFP_ZERO);
5554 if (!nlist) 5552 if (!nlist)
5555 return NULL; 5553 return NULL;
5556 memset(nlist + oldsize, 0, size - oldsize);
5557 array->list = nlist; 5554 array->list = nlist;
5558 array->alloced = num; 5555 array->alloced = num;
5559 } 5556 }
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 23ca1722aff1..c93f9021f452 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -757,6 +757,9 @@ struct hda_pcm_ops {
757 struct snd_pcm_substream *substream); 757 struct snd_pcm_substream *substream);
758 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec, 758 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
759 struct snd_pcm_substream *substream); 759 struct snd_pcm_substream *substream);
760 unsigned int (*get_delay)(struct hda_pcm_stream *info,
761 struct hda_codec *codec,
762 struct snd_pcm_substream *substream);
760}; 763};
761 764
762/* PCM information for each substream */ 765/* PCM information for each substream */
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index 2dbe767be16b..c7b59ddc4bce 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -34,6 +34,7 @@
34#include "hda_local.h" 34#include "hda_local.h"
35#include "hda_auto_parser.h" 35#include "hda_auto_parser.h"
36#include "hda_jack.h" 36#include "hda_jack.h"
37#include "hda_beep.h"
37#include "hda_generic.h" 38#include "hda_generic.h"
38 39
39 40
@@ -150,15 +151,25 @@ static void parse_user_hints(struct hda_codec *codec)
150 val = snd_hda_get_bool_hint(codec, "add_stereo_mix_input"); 151 val = snd_hda_get_bool_hint(codec, "add_stereo_mix_input");
151 if (val >= 0) 152 if (val >= 0)
152 spec->add_stereo_mix_input = !!val; 153 spec->add_stereo_mix_input = !!val;
154 /* the following two are just for compatibility */
153 val = snd_hda_get_bool_hint(codec, "add_out_jack_modes"); 155 val = snd_hda_get_bool_hint(codec, "add_out_jack_modes");
154 if (val >= 0) 156 if (val >= 0)
155 spec->add_out_jack_modes = !!val; 157 spec->add_jack_modes = !!val;
156 val = snd_hda_get_bool_hint(codec, "add_in_jack_modes"); 158 val = snd_hda_get_bool_hint(codec, "add_in_jack_modes");
157 if (val >= 0) 159 if (val >= 0)
158 spec->add_in_jack_modes = !!val; 160 spec->add_jack_modes = !!val;
161 val = snd_hda_get_bool_hint(codec, "add_jack_modes");
162 if (val >= 0)
163 spec->add_jack_modes = !!val;
159 val = snd_hda_get_bool_hint(codec, "power_down_unused"); 164 val = snd_hda_get_bool_hint(codec, "power_down_unused");
160 if (val >= 0) 165 if (val >= 0)
161 spec->power_down_unused = !!val; 166 spec->power_down_unused = !!val;
167 val = snd_hda_get_bool_hint(codec, "add_hp_mic");
168 if (val >= 0)
169 spec->hp_mic = !!val;
170 val = snd_hda_get_bool_hint(codec, "hp_mic_detect");
171 if (val >= 0)
172 spec->suppress_hp_mic_detect = !val;
162 173
163 if (!snd_hda_get_int_hint(codec, "mixer_nid", &val)) 174 if (!snd_hda_get_int_hint(codec, "mixer_nid", &val))
164 spec->mixer_nid = val; 175 spec->mixer_nid = val;
@@ -996,7 +1007,7 @@ enum {
996 /* Primary DAC shared with main surrounds */ 1007 /* Primary DAC shared with main surrounds */
997 BAD_SHARED_SURROUND = 0x100, 1008 BAD_SHARED_SURROUND = 0x100,
998 /* No independent HP possible */ 1009 /* No independent HP possible */
999 BAD_NO_INDEP_HP = 0x40, 1010 BAD_NO_INDEP_HP = 0x10,
1000 /* Primary DAC shared with main CLFE */ 1011 /* Primary DAC shared with main CLFE */
1001 BAD_SHARED_CLFE = 0x10, 1012 BAD_SHARED_CLFE = 0x10,
1002 /* Primary DAC shared with extra surrounds */ 1013 /* Primary DAC shared with extra surrounds */
@@ -1051,16 +1062,7 @@ static int assign_out_path_ctls(struct hda_codec *codec, struct nid_path *path)
1051 return badness; 1062 return badness;
1052} 1063}
1053 1064
1054struct badness_table { 1065const struct badness_table hda_main_out_badness = {
1055 int no_primary_dac; /* no primary DAC */
1056 int no_dac; /* no secondary DACs */
1057 int shared_primary; /* primary DAC is shared with main output */
1058 int shared_surr; /* secondary DAC shared with main or primary */
1059 int shared_clfe; /* third DAC shared with main or primary */
1060 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
1061};
1062
1063static struct badness_table main_out_badness = {
1064 .no_primary_dac = BAD_NO_PRIMARY_DAC, 1066 .no_primary_dac = BAD_NO_PRIMARY_DAC,
1065 .no_dac = BAD_NO_DAC, 1067 .no_dac = BAD_NO_DAC,
1066 .shared_primary = BAD_NO_PRIMARY_DAC, 1068 .shared_primary = BAD_NO_PRIMARY_DAC,
@@ -1068,8 +1070,9 @@ static struct badness_table main_out_badness = {
1068 .shared_clfe = BAD_SHARED_CLFE, 1070 .shared_clfe = BAD_SHARED_CLFE,
1069 .shared_surr_main = BAD_SHARED_SURROUND, 1071 .shared_surr_main = BAD_SHARED_SURROUND,
1070}; 1072};
1073EXPORT_SYMBOL_HDA(hda_main_out_badness);
1071 1074
1072static struct badness_table extra_out_badness = { 1075const struct badness_table hda_extra_out_badness = {
1073 .no_primary_dac = BAD_NO_DAC, 1076 .no_primary_dac = BAD_NO_DAC,
1074 .no_dac = BAD_NO_DAC, 1077 .no_dac = BAD_NO_DAC,
1075 .shared_primary = BAD_NO_EXTRA_DAC, 1078 .shared_primary = BAD_NO_EXTRA_DAC,
@@ -1077,6 +1080,7 @@ static struct badness_table extra_out_badness = {
1077 .shared_clfe = BAD_SHARED_EXTRA_SURROUND, 1080 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
1078 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC, 1081 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
1079}; 1082};
1083EXPORT_SYMBOL_HDA(hda_extra_out_badness);
1080 1084
1081/* get the DAC of the primary output corresponding to the given array index */ 1085/* get the DAC of the primary output corresponding to the given array index */
1082static hda_nid_t get_primary_out(struct hda_codec *codec, int idx) 1086static hda_nid_t get_primary_out(struct hda_codec *codec, int idx)
@@ -1507,7 +1511,7 @@ static int fill_and_eval_dacs(struct hda_codec *codec,
1507 1511
1508 badness += try_assign_dacs(codec, cfg->line_outs, cfg->line_out_pins, 1512 badness += try_assign_dacs(codec, cfg->line_outs, cfg->line_out_pins,
1509 spec->private_dac_nids, spec->out_paths, 1513 spec->private_dac_nids, spec->out_paths,
1510 &main_out_badness); 1514 spec->main_out_badness);
1511 1515
1512 if (fill_mio_first && 1516 if (fill_mio_first &&
1513 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { 1517 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
@@ -1522,7 +1526,7 @@ static int fill_and_eval_dacs(struct hda_codec *codec,
1522 err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins, 1526 err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins,
1523 spec->multiout.hp_out_nid, 1527 spec->multiout.hp_out_nid,
1524 spec->hp_paths, 1528 spec->hp_paths,
1525 &extra_out_badness); 1529 spec->extra_out_badness);
1526 if (err < 0) 1530 if (err < 0)
1527 return err; 1531 return err;
1528 badness += err; 1532 badness += err;
@@ -1532,7 +1536,7 @@ static int fill_and_eval_dacs(struct hda_codec *codec,
1532 cfg->speaker_pins, 1536 cfg->speaker_pins,
1533 spec->multiout.extra_out_nid, 1537 spec->multiout.extra_out_nid,
1534 spec->speaker_paths, 1538 spec->speaker_paths,
1535 &extra_out_badness); 1539 spec->extra_out_badness);
1536 if (err < 0) 1540 if (err < 0)
1537 return err; 1541 return err;
1538 badness += err; 1542 badness += err;
@@ -1926,6 +1930,17 @@ static int create_speaker_out_ctls(struct hda_codec *codec)
1926 * independent HP controls 1930 * independent HP controls
1927 */ 1931 */
1928 1932
1933/* update HP auto-mute state too */
1934static void update_hp_automute_hook(struct hda_codec *codec)
1935{
1936 struct hda_gen_spec *spec = codec->spec;
1937
1938 if (spec->hp_automute_hook)
1939 spec->hp_automute_hook(codec, NULL);
1940 else
1941 snd_hda_gen_hp_automute(codec, NULL);
1942}
1943
1929static int indep_hp_info(struct snd_kcontrol *kcontrol, 1944static int indep_hp_info(struct snd_kcontrol *kcontrol,
1930 struct snd_ctl_elem_info *uinfo) 1945 struct snd_ctl_elem_info *uinfo)
1931{ 1946{
@@ -1986,12 +2001,7 @@ static int indep_hp_put(struct snd_kcontrol *kcontrol,
1986 else 2001 else
1987 *dacp = spec->alt_dac_nid; 2002 *dacp = spec->alt_dac_nid;
1988 2003
1989 /* update HP auto-mute state too */ 2004 update_hp_automute_hook(codec);
1990 if (spec->hp_automute_hook)
1991 spec->hp_automute_hook(codec, NULL);
1992 else
1993 snd_hda_gen_hp_automute(codec, NULL);
1994
1995 ret = 1; 2005 ret = 1;
1996 } 2006 }
1997 unlock: 2007 unlock:
@@ -2240,63 +2250,95 @@ static int create_loopback_mixing_ctl(struct hda_codec *codec)
2240static void call_update_outputs(struct hda_codec *codec); 2250static void call_update_outputs(struct hda_codec *codec);
2241 2251
2242/* for shared I/O, change the pin-control accordingly */ 2252/* for shared I/O, change the pin-control accordingly */
2243static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic) 2253static void update_hp_mic(struct hda_codec *codec, int adc_mux, bool force)
2244{ 2254{
2245 struct hda_gen_spec *spec = codec->spec; 2255 struct hda_gen_spec *spec = codec->spec;
2256 bool as_mic;
2246 unsigned int val; 2257 unsigned int val;
2247 hda_nid_t pin = spec->autocfg.inputs[1].pin; 2258 hda_nid_t pin;
2248 /* NOTE: this assumes that there are only two inputs, the
2249 * first is the real internal mic and the second is HP/mic jack.
2250 */
2251 2259
2252 val = snd_hda_get_default_vref(codec, pin); 2260 pin = spec->hp_mic_pin;
2261 as_mic = spec->cur_mux[adc_mux] == spec->hp_mic_mux_idx;
2262
2263 if (!force) {
2264 val = snd_hda_codec_get_pin_target(codec, pin);
2265 if (as_mic) {
2266 if (val & PIN_IN)
2267 return;
2268 } else {
2269 if (val & PIN_OUT)
2270 return;
2271 }
2272 }
2253 2273
2254 /* This pin does not have vref caps - let's enable vref on pin 0x18 2274 val = snd_hda_get_default_vref(codec, pin);
2255 instead, as suggested by Realtek */ 2275 /* if the HP pin doesn't support VREF and the codec driver gives an
2276 * alternative pin, set up the VREF on that pin instead
2277 */
2256 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) { 2278 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
2257 const hda_nid_t vref_pin = spec->shared_mic_vref_pin; 2279 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
2258 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin); 2280 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
2259 if (vref_val != AC_PINCTL_VREF_HIZ) 2281 if (vref_val != AC_PINCTL_VREF_HIZ)
2260 snd_hda_set_pin_ctl_cache(codec, vref_pin, 2282 snd_hda_set_pin_ctl_cache(codec, vref_pin,
2261 PIN_IN | (set_as_mic ? vref_val : 0)); 2283 PIN_IN | (as_mic ? vref_val : 0));
2262 } 2284 }
2263 2285
2264 val = set_as_mic ? val | PIN_IN : PIN_HP; 2286 if (!spec->hp_mic_jack_modes) {
2265 set_pin_target(codec, pin, val, true); 2287 if (as_mic)
2266 2288 val |= PIN_IN;
2267 spec->automute_speaker = !set_as_mic; 2289 else
2268 call_update_outputs(codec); 2290 val = PIN_HP;
2291 set_pin_target(codec, pin, val, true);
2292 update_hp_automute_hook(codec);
2293 }
2269} 2294}
2270 2295
2271/* create a shared input with the headphone out */ 2296/* create a shared input with the headphone out */
2272static int create_shared_input(struct hda_codec *codec) 2297static int create_hp_mic(struct hda_codec *codec)
2273{ 2298{
2274 struct hda_gen_spec *spec = codec->spec; 2299 struct hda_gen_spec *spec = codec->spec;
2275 struct auto_pin_cfg *cfg = &spec->autocfg; 2300 struct auto_pin_cfg *cfg = &spec->autocfg;
2276 unsigned int defcfg; 2301 unsigned int defcfg;
2277 hda_nid_t nid; 2302 hda_nid_t nid;
2278 2303
2279 /* only one internal input pin? */ 2304 if (!spec->hp_mic) {
2280 if (cfg->num_inputs != 1) 2305 if (spec->suppress_hp_mic_detect)
2281 return 0; 2306 return 0;
2282 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin); 2307 /* automatic detection: only if no input or a single internal
2283 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT) 2308 * input pin is found, try to detect the shared hp/mic
2309 */
2310 if (cfg->num_inputs > 1)
2311 return 0;
2312 else if (cfg->num_inputs == 1) {
2313 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2314 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2315 return 0;
2316 }
2317 }
2318
2319 spec->hp_mic = 0; /* clear once */
2320 if (cfg->num_inputs >= AUTO_CFG_MAX_INS)
2284 return 0; 2321 return 0;
2285 2322
2286 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) 2323 nid = 0;
2287 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */ 2324 if (cfg->line_out_type == AUTO_PIN_HP_OUT && cfg->line_outs > 0)
2288 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT) 2325 nid = cfg->line_out_pins[0];
2289 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */ 2326 else if (cfg->hp_outs > 0)
2290 else 2327 nid = cfg->hp_pins[0];
2291 return 0; /* both not available */ 2328 if (!nid)
2329 return 0;
2292 2330
2293 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN)) 2331 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2294 return 0; /* no input */ 2332 return 0; /* no input */
2295 2333
2296 cfg->inputs[1].pin = nid; 2334 cfg->inputs[cfg->num_inputs].pin = nid;
2297 cfg->inputs[1].type = AUTO_PIN_MIC; 2335 cfg->inputs[cfg->num_inputs].type = AUTO_PIN_MIC;
2298 cfg->num_inputs = 2; 2336 cfg->inputs[cfg->num_inputs].is_headphone_mic = 1;
2299 spec->shared_mic_hp = 1; 2337 cfg->num_inputs++;
2338 spec->hp_mic = 1;
2339 spec->hp_mic_pin = nid;
2340 /* we can't handle auto-mic together with HP-mic */
2341 spec->suppress_auto_mic = 1;
2300 snd_printdd("hda-codec: Enable shared I/O jack on NID 0x%x\n", nid); 2342 snd_printdd("hda-codec: Enable shared I/O jack on NID 0x%x\n", nid);
2301 return 0; 2343 return 0;
2302} 2344}
@@ -2304,13 +2346,17 @@ static int create_shared_input(struct hda_codec *codec)
2304/* 2346/*
2305 * output jack mode 2347 * output jack mode
2306 */ 2348 */
2349
2350static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin);
2351
2352static const char * const out_jack_texts[] = {
2353 "Line Out", "Headphone Out",
2354};
2355
2307static int out_jack_mode_info(struct snd_kcontrol *kcontrol, 2356static int out_jack_mode_info(struct snd_kcontrol *kcontrol,
2308 struct snd_ctl_elem_info *uinfo) 2357 struct snd_ctl_elem_info *uinfo)
2309{ 2358{
2310 static const char * const texts[] = { 2359 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, out_jack_texts);
2311 "Line Out", "Headphone Out",
2312 };
2313 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts);
2314} 2360}
2315 2361
2316static int out_jack_mode_get(struct snd_kcontrol *kcontrol, 2362static int out_jack_mode_get(struct snd_kcontrol *kcontrol,
@@ -2372,6 +2418,17 @@ static void get_jack_mode_name(struct hda_codec *codec, hda_nid_t pin,
2372 ; 2418 ;
2373} 2419}
2374 2420
2421static int get_out_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2422{
2423 struct hda_gen_spec *spec = codec->spec;
2424 if (spec->add_jack_modes) {
2425 unsigned int pincap = snd_hda_query_pin_caps(codec, pin);
2426 if ((pincap & AC_PINCAP_OUT) && (pincap & AC_PINCAP_HP_DRV))
2427 return 2;
2428 }
2429 return 1;
2430}
2431
2375static int create_out_jack_modes(struct hda_codec *codec, int num_pins, 2432static int create_out_jack_modes(struct hda_codec *codec, int num_pins,
2376 hda_nid_t *pins) 2433 hda_nid_t *pins)
2377{ 2434{
@@ -2380,8 +2437,13 @@ static int create_out_jack_modes(struct hda_codec *codec, int num_pins,
2380 2437
2381 for (i = 0; i < num_pins; i++) { 2438 for (i = 0; i < num_pins; i++) {
2382 hda_nid_t pin = pins[i]; 2439 hda_nid_t pin = pins[i];
2383 unsigned int pincap = snd_hda_query_pin_caps(codec, pin); 2440 if (pin == spec->hp_mic_pin) {
2384 if ((pincap & AC_PINCAP_OUT) && (pincap & AC_PINCAP_HP_DRV)) { 2441 int ret = create_hp_mic_jack_mode(codec, pin);
2442 if (ret < 0)
2443 return ret;
2444 continue;
2445 }
2446 if (get_out_jack_num_items(codec, pin) > 1) {
2385 struct snd_kcontrol_new *knew; 2447 struct snd_kcontrol_new *knew;
2386 char name[44]; 2448 char name[44];
2387 get_jack_mode_name(codec, pin, name, sizeof(name)); 2449 get_jack_mode_name(codec, pin, name, sizeof(name));
@@ -2502,12 +2564,24 @@ static const struct snd_kcontrol_new in_jack_mode_enum = {
2502 .put = in_jack_mode_put, 2564 .put = in_jack_mode_put,
2503}; 2565};
2504 2566
2567static int get_in_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2568{
2569 struct hda_gen_spec *spec = codec->spec;
2570 int nitems = 0;
2571 if (spec->add_jack_modes)
2572 nitems = hweight32(get_vref_caps(codec, pin));
2573 return nitems ? nitems : 1;
2574}
2575
2505static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin) 2576static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2506{ 2577{
2507 struct hda_gen_spec *spec = codec->spec; 2578 struct hda_gen_spec *spec = codec->spec;
2508 unsigned int defcfg;
2509 struct snd_kcontrol_new *knew; 2579 struct snd_kcontrol_new *knew;
2510 char name[44]; 2580 char name[44];
2581 unsigned int defcfg;
2582
2583 if (pin == spec->hp_mic_pin)
2584 return 0; /* already done in create_out_jack_mode() */
2511 2585
2512 /* no jack mode for fixed pins */ 2586 /* no jack mode for fixed pins */
2513 defcfg = snd_hda_codec_get_pincfg(codec, pin); 2587 defcfg = snd_hda_codec_get_pincfg(codec, pin);
@@ -2515,7 +2589,7 @@ static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2515 return 0; 2589 return 0;
2516 2590
2517 /* no multiple vref caps? */ 2591 /* no multiple vref caps? */
2518 if (hweight32(get_vref_caps(codec, pin)) <= 1) 2592 if (get_in_jack_num_items(codec, pin) <= 1)
2519 return 0; 2593 return 0;
2520 2594
2521 get_jack_mode_name(codec, pin, name, sizeof(name)); 2595 get_jack_mode_name(codec, pin, name, sizeof(name));
@@ -2526,6 +2600,132 @@ static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2526 return 0; 2600 return 0;
2527} 2601}
2528 2602
2603/*
2604 * HP/mic shared jack mode
2605 */
2606static int hp_mic_jack_mode_info(struct snd_kcontrol *kcontrol,
2607 struct snd_ctl_elem_info *uinfo)
2608{
2609 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2610 hda_nid_t nid = kcontrol->private_value;
2611 int out_jacks = get_out_jack_num_items(codec, nid);
2612 int in_jacks = get_in_jack_num_items(codec, nid);
2613 const char *text = NULL;
2614 int idx;
2615
2616 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2617 uinfo->count = 1;
2618 uinfo->value.enumerated.items = out_jacks + in_jacks;
2619 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2620 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2621 idx = uinfo->value.enumerated.item;
2622 if (idx < out_jacks) {
2623 if (out_jacks > 1)
2624 text = out_jack_texts[idx];
2625 else
2626 text = "Headphone Out";
2627 } else {
2628 idx -= out_jacks;
2629 if (in_jacks > 1) {
2630 unsigned int vref_caps = get_vref_caps(codec, nid);
2631 text = vref_texts[get_vref_idx(vref_caps, idx)];
2632 } else
2633 text = "Mic In";
2634 }
2635
2636 strcpy(uinfo->value.enumerated.name, text);
2637 return 0;
2638}
2639
2640static int get_cur_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t nid)
2641{
2642 int out_jacks = get_out_jack_num_items(codec, nid);
2643 int in_jacks = get_in_jack_num_items(codec, nid);
2644 unsigned int val = snd_hda_codec_get_pin_target(codec, nid);
2645 int idx = 0;
2646
2647 if (val & PIN_OUT) {
2648 if (out_jacks > 1 && val == PIN_HP)
2649 idx = 1;
2650 } else if (val & PIN_IN) {
2651 idx = out_jacks;
2652 if (in_jacks > 1) {
2653 unsigned int vref_caps = get_vref_caps(codec, nid);
2654 val &= AC_PINCTL_VREFEN;
2655 idx += cvt_from_vref_idx(vref_caps, val);
2656 }
2657 }
2658 return idx;
2659}
2660
2661static int hp_mic_jack_mode_get(struct snd_kcontrol *kcontrol,
2662 struct snd_ctl_elem_value *ucontrol)
2663{
2664 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2665 hda_nid_t nid = kcontrol->private_value;
2666 ucontrol->value.enumerated.item[0] =
2667 get_cur_hp_mic_jack_mode(codec, nid);
2668 return 0;
2669}
2670
2671static int hp_mic_jack_mode_put(struct snd_kcontrol *kcontrol,
2672 struct snd_ctl_elem_value *ucontrol)
2673{
2674 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2675 hda_nid_t nid = kcontrol->private_value;
2676 int out_jacks = get_out_jack_num_items(codec, nid);
2677 int in_jacks = get_in_jack_num_items(codec, nid);
2678 unsigned int val, oldval, idx;
2679
2680 oldval = get_cur_hp_mic_jack_mode(codec, nid);
2681 idx = ucontrol->value.enumerated.item[0];
2682 if (oldval == idx)
2683 return 0;
2684
2685 if (idx < out_jacks) {
2686 if (out_jacks > 1)
2687 val = idx ? PIN_HP : PIN_OUT;
2688 else
2689 val = PIN_HP;
2690 } else {
2691 idx -= out_jacks;
2692 if (in_jacks > 1) {
2693 unsigned int vref_caps = get_vref_caps(codec, nid);
2694 val = snd_hda_codec_get_pin_target(codec, nid);
2695 val &= ~(AC_PINCTL_VREFEN | PIN_HP);
2696 val |= get_vref_idx(vref_caps, idx) | PIN_IN;
2697 } else
2698 val = snd_hda_get_default_vref(codec, nid);
2699 }
2700 snd_hda_set_pin_ctl_cache(codec, nid, val);
2701 update_hp_automute_hook(codec);
2702
2703 return 1;
2704}
2705
2706static const struct snd_kcontrol_new hp_mic_jack_mode_enum = {
2707 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2708 .info = hp_mic_jack_mode_info,
2709 .get = hp_mic_jack_mode_get,
2710 .put = hp_mic_jack_mode_put,
2711};
2712
2713static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2714{
2715 struct hda_gen_spec *spec = codec->spec;
2716 struct snd_kcontrol_new *knew;
2717
2718 if (get_out_jack_num_items(codec, pin) <= 1 &&
2719 get_in_jack_num_items(codec, pin) <= 1)
2720 return 0; /* no need */
2721 knew = snd_hda_gen_add_kctl(spec, "Headphone Mic Jack Mode",
2722 &hp_mic_jack_mode_enum);
2723 if (!knew)
2724 return -ENOMEM;
2725 knew->private_value = pin;
2726 spec->hp_mic_jack_modes = 1;
2727 return 0;
2728}
2529 2729
2530/* 2730/*
2531 * Parse input paths 2731 * Parse input paths
@@ -2648,7 +2848,6 @@ static int check_dyn_adc_switch(struct hda_codec *codec)
2648 unsigned int ok_bits; 2848 unsigned int ok_bits;
2649 int i, n, nums; 2849 int i, n, nums;
2650 2850
2651 again:
2652 nums = 0; 2851 nums = 0;
2653 ok_bits = 0; 2852 ok_bits = 0;
2654 for (n = 0; n < spec->num_adc_nids; n++) { 2853 for (n = 0; n < spec->num_adc_nids; n++) {
@@ -2663,12 +2862,6 @@ static int check_dyn_adc_switch(struct hda_codec *codec)
2663 } 2862 }
2664 2863
2665 if (!ok_bits) { 2864 if (!ok_bits) {
2666 if (spec->shared_mic_hp) {
2667 spec->shared_mic_hp = 0;
2668 imux->num_items = 1;
2669 goto again;
2670 }
2671
2672 /* check whether ADC-switch is possible */ 2865 /* check whether ADC-switch is possible */
2673 for (i = 0; i < imux->num_items; i++) { 2866 for (i = 0; i < imux->num_items; i++) {
2674 for (n = 0; n < spec->num_adc_nids; n++) { 2867 for (n = 0; n < spec->num_adc_nids; n++) {
@@ -2701,7 +2894,8 @@ static int check_dyn_adc_switch(struct hda_codec *codec)
2701 spec->num_adc_nids = nums; 2894 spec->num_adc_nids = nums;
2702 } 2895 }
2703 2896
2704 if (imux->num_items == 1 || spec->shared_mic_hp) { 2897 if (imux->num_items == 1 ||
2898 (imux->num_items == 2 && spec->hp_mic)) {
2705 snd_printdd("hda-codec: reducing to a single ADC\n"); 2899 snd_printdd("hda-codec: reducing to a single ADC\n");
2706 spec->num_adc_nids = 1; /* reduce to a single ADC */ 2900 spec->num_adc_nids = 1; /* reduce to a single ADC */
2707 } 2901 }
@@ -2738,6 +2932,8 @@ static int parse_capture_source(struct hda_codec *codec, hda_nid_t pin,
2738 snd_hda_get_path_idx(codec, path); 2932 snd_hda_get_path_idx(codec, path);
2739 2933
2740 if (!imux_added) { 2934 if (!imux_added) {
2935 if (spec->hp_mic_pin == pin)
2936 spec->hp_mic_mux_idx = imux->num_items;
2741 spec->imux_pins[imux->num_items] = pin; 2937 spec->imux_pins[imux->num_items] = pin;
2742 snd_hda_add_imux_item(imux, label, cfg_idx, NULL); 2938 snd_hda_add_imux_item(imux, label, cfg_idx, NULL);
2743 imux_added = true; 2939 imux_added = true;
@@ -2812,7 +3008,8 @@ static int create_input_ctls(struct hda_codec *codec)
2812 val = PIN_IN; 3008 val = PIN_IN;
2813 if (cfg->inputs[i].type == AUTO_PIN_MIC) 3009 if (cfg->inputs[i].type == AUTO_PIN_MIC)
2814 val |= snd_hda_get_default_vref(codec, pin); 3010 val |= snd_hda_get_default_vref(codec, pin);
2815 set_pin_target(codec, pin, val, false); 3011 if (pin != spec->hp_mic_pin)
3012 set_pin_target(codec, pin, val, false);
2816 3013
2817 if (mixer) { 3014 if (mixer) {
2818 if (is_reachable_path(codec, pin, mixer)) { 3015 if (is_reachable_path(codec, pin, mixer)) {
@@ -2830,7 +3027,7 @@ static int create_input_ctls(struct hda_codec *codec)
2830 if (err < 0) 3027 if (err < 0)
2831 return err; 3028 return err;
2832 3029
2833 if (spec->add_in_jack_modes) { 3030 if (spec->add_jack_modes) {
2834 err = create_in_jack_mode(codec, pin); 3031 err = create_in_jack_mode(codec, pin);
2835 if (err < 0) 3032 if (err < 0)
2836 return err; 3033 return err;
@@ -3462,8 +3659,8 @@ static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3462 3659
3463 spec->cur_mux[adc_idx] = idx; 3660 spec->cur_mux[adc_idx] = idx;
3464 3661
3465 if (spec->shared_mic_hp) 3662 if (spec->hp_mic)
3466 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]); 3663 update_hp_mic(codec, adc_idx, false);
3467 3664
3468 if (spec->dyn_adc_switch) 3665 if (spec->dyn_adc_switch)
3469 dyn_adc_pcm_resetup(codec, idx); 3666 dyn_adc_pcm_resetup(codec, idx);
@@ -3511,18 +3708,21 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
3511 3708
3512 for (i = 0; i < num_pins; i++) { 3709 for (i = 0; i < num_pins; i++) {
3513 hda_nid_t nid = pins[i]; 3710 hda_nid_t nid = pins[i];
3514 unsigned int val; 3711 unsigned int val, oldval;
3515 if (!nid) 3712 if (!nid)
3516 break; 3713 break;
3714 oldval = snd_hda_codec_get_pin_target(codec, nid);
3715 if (oldval & PIN_IN)
3716 continue; /* no mute for inputs */
3517 /* don't reset VREF value in case it's controlling 3717 /* don't reset VREF value in case it's controlling
3518 * the amp (see alc861_fixup_asus_amp_vref_0f()) 3718 * the amp (see alc861_fixup_asus_amp_vref_0f())
3519 */ 3719 */
3520 if (spec->keep_vref_in_automute) 3720 if (spec->keep_vref_in_automute)
3521 val = snd_hda_codec_get_pin_target(codec, nid) & ~PIN_HP; 3721 val = oldval & ~PIN_HP;
3522 else 3722 else
3523 val = 0; 3723 val = 0;
3524 if (!mute) 3724 if (!mute)
3525 val |= snd_hda_codec_get_pin_target(codec, nid); 3725 val |= oldval;
3526 /* here we call update_pin_ctl() so that the pinctl is changed 3726 /* here we call update_pin_ctl() so that the pinctl is changed
3527 * without changing the pinctl target value; 3727 * without changing the pinctl target value;
3528 * the original target value will be still referred at the 3728 * the original target value will be still referred at the
@@ -3543,8 +3743,7 @@ void snd_hda_gen_update_outputs(struct hda_codec *codec)
3543 * in general, HP pins/amps control should be enabled in all cases, 3743 * in general, HP pins/amps control should be enabled in all cases,
3544 * but currently set only for master_mute, just to be safe 3744 * but currently set only for master_mute, just to be safe
3545 */ 3745 */
3546 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */ 3746 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
3547 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
3548 spec->autocfg.hp_pins, spec->master_mute); 3747 spec->autocfg.hp_pins, spec->master_mute);
3549 3748
3550 if (!spec->automute_speaker) 3749 if (!spec->automute_speaker)
@@ -3649,10 +3848,7 @@ static void update_automute_all(struct hda_codec *codec)
3649{ 3848{
3650 struct hda_gen_spec *spec = codec->spec; 3849 struct hda_gen_spec *spec = codec->spec;
3651 3850
3652 if (spec->hp_automute_hook) 3851 update_hp_automute_hook(codec);
3653 spec->hp_automute_hook(codec, NULL);
3654 else
3655 snd_hda_gen_hp_automute(codec, NULL);
3656 if (spec->line_automute_hook) 3852 if (spec->line_automute_hook)
3657 spec->line_automute_hook(codec, NULL); 3853 spec->line_automute_hook(codec, NULL);
3658 else 3854 else
@@ -3978,6 +4174,11 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
3978 cfg = &spec->autocfg; 4174 cfg = &spec->autocfg;
3979 } 4175 }
3980 4176
4177 if (!spec->main_out_badness)
4178 spec->main_out_badness = &hda_main_out_badness;
4179 if (!spec->extra_out_badness)
4180 spec->extra_out_badness = &hda_extra_out_badness;
4181
3981 fill_all_dac_nids(codec); 4182 fill_all_dac_nids(codec);
3982 4183
3983 if (!cfg->line_outs) { 4184 if (!cfg->line_outs) {
@@ -4024,7 +4225,7 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4024 err = create_loopback_mixing_ctl(codec); 4225 err = create_loopback_mixing_ctl(codec);
4025 if (err < 0) 4226 if (err < 0)
4026 return err; 4227 return err;
4027 err = create_shared_input(codec); 4228 err = create_hp_mic(codec);
4028 if (err < 0) 4229 if (err < 0)
4029 return err; 4230 return err;
4030 err = create_input_ctls(codec); 4231 err = create_input_ctls(codec);
@@ -4050,11 +4251,9 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4050 if (err < 0) 4251 if (err < 0)
4051 return err; 4252 return err;
4052 4253
4053 if (!spec->shared_mic_hp) { 4254 err = check_auto_mic_availability(codec);
4054 err = check_auto_mic_availability(codec); 4255 if (err < 0)
4055 if (err < 0) 4256 return err;
4056 return err;
4057 }
4058 4257
4059 err = create_capture_mixers(codec); 4258 err = create_capture_mixers(codec);
4060 if (err < 0) 4259 if (err < 0)
@@ -4064,7 +4263,7 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4064 if (err < 0) 4263 if (err < 0)
4065 return err; 4264 return err;
4066 4265
4067 if (spec->add_out_jack_modes) { 4266 if (spec->add_jack_modes) {
4068 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { 4267 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
4069 err = create_out_jack_modes(codec, cfg->line_outs, 4268 err = create_out_jack_modes(codec, cfg->line_outs,
4070 cfg->line_out_pins); 4269 cfg->line_out_pins);
@@ -4085,6 +4284,12 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4085 if (spec->power_down_unused) 4284 if (spec->power_down_unused)
4086 codec->power_filter = snd_hda_gen_path_power_filter; 4285 codec->power_filter = snd_hda_gen_path_power_filter;
4087 4286
4287 if (!spec->no_analog && spec->beep_nid) {
4288 err = snd_hda_attach_beep_device(codec, spec->beep_nid);
4289 if (err < 0)
4290 return err;
4291 }
4292
4088 return 1; 4293 return 1;
4089} 4294}
4090EXPORT_SYMBOL_HDA(snd_hda_gen_parse_auto_config); 4295EXPORT_SYMBOL_HDA(snd_hda_gen_parse_auto_config);
@@ -4161,17 +4366,6 @@ int snd_hda_gen_build_controls(struct hda_codec *codec)
4161 4366
4162 free_kctls(spec); /* no longer needed */ 4367 free_kctls(spec); /* no longer needed */
4163 4368
4164 if (spec->shared_mic_hp) {
4165 int err;
4166 int nid = spec->autocfg.inputs[1].pin;
4167 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
4168 if (err < 0)
4169 return err;
4170 err = snd_hda_jack_detect_enable(codec, nid, 0);
4171 if (err < 0)
4172 return err;
4173 }
4174
4175 err = snd_hda_jack_add_kctls(codec, &spec->autocfg); 4369 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4176 if (err < 0) 4370 if (err < 0)
4177 return err; 4371 return err;
@@ -4826,11 +5020,10 @@ static void init_input_src(struct hda_codec *codec)
4826 snd_hda_activate_path(codec, path, active, false); 5020 snd_hda_activate_path(codec, path, active, false);
4827 } 5021 }
4828 } 5022 }
5023 if (spec->hp_mic)
5024 update_hp_mic(codec, c, true);
4829 } 5025 }
4830 5026
4831 if (spec->shared_mic_hp)
4832 update_shared_mic_hp(codec, spec->cur_mux[0]);
4833
4834 if (spec->cap_sync_hook) 5027 if (spec->cap_sync_hook)
4835 spec->cap_sync_hook(codec, NULL); 5028 spec->cap_sync_hook(codec, NULL);
4836} 5029}
@@ -4911,6 +5104,7 @@ EXPORT_SYMBOL_HDA(snd_hda_gen_init);
4911 */ 5104 */
4912void snd_hda_gen_free(struct hda_codec *codec) 5105void snd_hda_gen_free(struct hda_codec *codec)
4913{ 5106{
5107 snd_hda_detach_beep_device(codec);
4914 snd_hda_gen_spec_free(codec->spec); 5108 snd_hda_gen_spec_free(codec->spec);
4915 kfree(codec->spec); 5109 kfree(codec->spec);
4916 codec->spec = NULL; 5110 codec->spec = NULL;
diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h
index 009b57be96d3..54e665160379 100644
--- a/sound/pci/hda/hda_generic.h
+++ b/sound/pci/hda/hda_generic.h
@@ -76,6 +76,19 @@ enum {
76 HDA_GEN_PCM_ACT_CLOSE, 76 HDA_GEN_PCM_ACT_CLOSE,
77}; 77};
78 78
79/* DAC assignment badness table */
80struct badness_table {
81 int no_primary_dac; /* no primary DAC */
82 int no_dac; /* no secondary DACs */
83 int shared_primary; /* primary DAC is shared with main output */
84 int shared_surr; /* secondary DAC shared with main or primary */
85 int shared_clfe; /* third DAC shared with main or primary */
86 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
87};
88
89extern const struct badness_table hda_main_out_badness;
90extern const struct badness_table hda_extra_out_badness;
91
79struct hda_gen_spec { 92struct hda_gen_spec {
80 char stream_name_analog[32]; /* analog PCM stream */ 93 char stream_name_analog[32]; /* analog PCM stream */
81 const struct hda_pcm_stream *stream_analog_playback; 94 const struct hda_pcm_stream *stream_analog_playback;
@@ -145,7 +158,10 @@ struct hda_gen_spec {
145 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 158 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
146 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS]; 159 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
147 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS]; 160 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
161 /* shared hp/mic */
148 hda_nid_t shared_mic_vref_pin; 162 hda_nid_t shared_mic_vref_pin;
163 hda_nid_t hp_mic_pin;
164 int hp_mic_mux_idx;
149 165
150 /* DAC/ADC lists */ 166 /* DAC/ADC lists */
151 int num_all_dacs; 167 int num_all_dacs;
@@ -200,7 +216,8 @@ struct hda_gen_spec {
200 216
201 /* other parse behavior flags */ 217 /* other parse behavior flags */
202 unsigned int need_dac_fix:1; /* need to limit DACs for multi channels */ 218 unsigned int need_dac_fix:1; /* need to limit DACs for multi channels */
203 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */ 219 unsigned int hp_mic:1; /* Allow HP as a mic-in */
220 unsigned int suppress_hp_mic_detect:1; /* Don't detect HP/mic */
204 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */ 221 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
205 unsigned int multi_cap_vol:1; /* allow multiple capture xxx volumes */ 222 unsigned int multi_cap_vol:1; /* allow multiple capture xxx volumes */
206 unsigned int inv_dmic_split:1; /* inverted dmic w/a for conexant */ 223 unsigned int inv_dmic_split:1; /* inverted dmic w/a for conexant */
@@ -209,8 +226,7 @@ struct hda_gen_spec {
209 unsigned int indep_hp:1; /* independent HP supported */ 226 unsigned int indep_hp:1; /* independent HP supported */
210 unsigned int prefer_hp_amp:1; /* enable HP amp for speaker if any */ 227 unsigned int prefer_hp_amp:1; /* enable HP amp for speaker if any */
211 unsigned int add_stereo_mix_input:1; /* add aamix as a capture src */ 228 unsigned int add_stereo_mix_input:1; /* add aamix as a capture src */
212 unsigned int add_out_jack_modes:1; /* add output jack mode enum ctls */ 229 unsigned int add_jack_modes:1; /* add i/o jack mode enum ctls */
213 unsigned int add_in_jack_modes:1; /* add input jack mode enum ctls */
214 unsigned int power_down_unused:1; /* power down unused widgets */ 230 unsigned int power_down_unused:1; /* power down unused widgets */
215 231
216 /* other internal flags */ 232 /* other internal flags */
@@ -218,10 +234,18 @@ struct hda_gen_spec {
218 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */ 234 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
219 unsigned int indep_hp_enabled:1; /* independent HP enabled */ 235 unsigned int indep_hp_enabled:1; /* independent HP enabled */
220 unsigned int have_aamix_ctl:1; 236 unsigned int have_aamix_ctl:1;
237 unsigned int hp_mic_jack_modes:1;
238
239 /* badness tables for output path evaluations */
240 const struct badness_table *main_out_badness;
241 const struct badness_table *extra_out_badness;
221 242
222 /* loopback mixing mode */ 243 /* loopback mixing mode */
223 bool aamix_mode; 244 bool aamix_mode;
224 245
246 /* digital beep */
247 hda_nid_t beep_nid;
248
225 /* for virtual master */ 249 /* for virtual master */
226 hda_nid_t vmaster_nid; 250 hda_nid_t vmaster_nid;
227 unsigned int vmaster_tlv[4]; 251 unsigned int vmaster_tlv[4];
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index bcd40ee488e3..63734b531f36 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -1889,6 +1889,23 @@ static void azx_timecounter_init(struct snd_pcm_substream *substream,
1889 tc->cycle_last = last; 1889 tc->cycle_last = last;
1890} 1890}
1891 1891
1892static u64 azx_subtract_codec_delay(struct snd_pcm_substream *substream,
1893 u64 nsec)
1894{
1895 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1896 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
1897 u64 codec_frames, codec_nsecs;
1898
1899 if (!hinfo->ops.get_delay)
1900 return nsec;
1901
1902 codec_frames = hinfo->ops.get_delay(hinfo, apcm->codec, substream);
1903 codec_nsecs = div_u64(codec_frames * 1000000000LL,
1904 substream->runtime->rate);
1905
1906 return (nsec > codec_nsecs) ? nsec - codec_nsecs : 0;
1907}
1908
1892static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream, 1909static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream,
1893 struct timespec *ts) 1910 struct timespec *ts)
1894{ 1911{
@@ -1897,6 +1914,7 @@ static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream,
1897 1914
1898 nsec = timecounter_read(&azx_dev->azx_tc); 1915 nsec = timecounter_read(&azx_dev->azx_tc);
1899 nsec = div_u64(nsec, 3); /* can be optimized */ 1916 nsec = div_u64(nsec, 3); /* can be optimized */
1917 nsec = azx_subtract_codec_delay(substream, nsec);
1900 1918
1901 *ts = ns_to_timespec(nsec); 1919 *ts = ns_to_timespec(nsec);
1902 1920
@@ -2349,8 +2367,11 @@ static unsigned int azx_get_position(struct azx *chip,
2349 struct azx_dev *azx_dev, 2367 struct azx_dev *azx_dev,
2350 bool with_check) 2368 bool with_check)
2351{ 2369{
2370 struct snd_pcm_substream *substream = azx_dev->substream;
2371 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
2352 unsigned int pos; 2372 unsigned int pos;
2353 int stream = azx_dev->substream->stream; 2373 int stream = substream->stream;
2374 struct hda_pcm_stream *hinfo = apcm->hinfo[stream];
2354 int delay = 0; 2375 int delay = 0;
2355 2376
2356 switch (chip->position_fix[stream]) { 2377 switch (chip->position_fix[stream]) {
@@ -2381,7 +2402,7 @@ static unsigned int azx_get_position(struct azx *chip,
2381 pos = 0; 2402 pos = 0;
2382 2403
2383 /* calculate runtime delay from LPIB */ 2404 /* calculate runtime delay from LPIB */
2384 if (azx_dev->substream->runtime && 2405 if (substream->runtime &&
2385 chip->position_fix[stream] == POS_FIX_POSBUF && 2406 chip->position_fix[stream] == POS_FIX_POSBUF &&
2386 (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)) { 2407 (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)) {
2387 unsigned int lpib_pos = azx_sd_readl(azx_dev, SD_LPIB); 2408 unsigned int lpib_pos = azx_sd_readl(azx_dev, SD_LPIB);
@@ -2399,9 +2420,16 @@ static unsigned int azx_get_position(struct azx *chip,
2399 delay = 0; 2420 delay = 0;
2400 chip->driver_caps &= ~AZX_DCAPS_COUNT_LPIB_DELAY; 2421 chip->driver_caps &= ~AZX_DCAPS_COUNT_LPIB_DELAY;
2401 } 2422 }
2402 azx_dev->substream->runtime->delay = 2423 delay = bytes_to_frames(substream->runtime, delay);
2403 bytes_to_frames(azx_dev->substream->runtime, delay);
2404 } 2424 }
2425
2426 if (substream->runtime) {
2427 if (hinfo->ops.get_delay)
2428 delay += hinfo->ops.get_delay(hinfo, apcm->codec,
2429 substream);
2430 substream->runtime->delay = delay;
2431 }
2432
2405 trace_azx_get_position(chip, azx_dev, pos, delay); 2433 trace_azx_get_position(chip, azx_dev, pos, delay);
2406 return pos; 2434 return pos;
2407} 2435}
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index 1d035efeff4f..9e0a95288f46 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -394,7 +394,8 @@ static int get_unique_index(struct hda_codec *codec, const char *name, int idx)
394} 394}
395 395
396static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid, 396static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid,
397 const struct auto_pin_cfg *cfg) 397 const struct auto_pin_cfg *cfg,
398 const char *base_name)
398{ 399{
399 unsigned int def_conf, conn; 400 unsigned int def_conf, conn;
400 char name[44]; 401 char name[44];
@@ -410,7 +411,11 @@ static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid,
410 phantom_jack = (conn != AC_JACK_PORT_COMPLEX) || 411 phantom_jack = (conn != AC_JACK_PORT_COMPLEX) ||
411 !is_jack_detectable(codec, nid); 412 !is_jack_detectable(codec, nid);
412 413
413 snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), &idx); 414 if (base_name) {
415 strlcpy(name, base_name, sizeof(name));
416 idx = 0;
417 } else
418 snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), &idx);
414 if (phantom_jack) 419 if (phantom_jack)
415 /* Example final name: "Internal Mic Phantom Jack" */ 420 /* Example final name: "Internal Mic Phantom Jack" */
416 strncat(name, " Phantom", sizeof(name) - strlen(name) - 1); 421 strncat(name, " Phantom", sizeof(name) - strlen(name) - 1);
@@ -433,39 +438,51 @@ int snd_hda_jack_add_kctls(struct hda_codec *codec,
433 const hda_nid_t *p; 438 const hda_nid_t *p;
434 int i, err; 439 int i, err;
435 440
441 for (i = 0; i < cfg->num_inputs; i++) {
442 /* If we have headphone mics; make sure they get the right name
443 before grabbed by output pins */
444 if (cfg->inputs[i].is_headphone_mic) {
445 if (auto_cfg_hp_outs(cfg) == 1)
446 err = add_jack_kctl(codec, auto_cfg_hp_pins(cfg)[0],
447 cfg, "Headphone Mic");
448 else
449 err = add_jack_kctl(codec, cfg->inputs[i].pin,
450 cfg, "Headphone Mic");
451 } else
452 err = add_jack_kctl(codec, cfg->inputs[i].pin, cfg,
453 NULL);
454 if (err < 0)
455 return err;
456 }
457
436 for (i = 0, p = cfg->line_out_pins; i < cfg->line_outs; i++, p++) { 458 for (i = 0, p = cfg->line_out_pins; i < cfg->line_outs; i++, p++) {
437 err = add_jack_kctl(codec, *p, cfg); 459 err = add_jack_kctl(codec, *p, cfg, NULL);
438 if (err < 0) 460 if (err < 0)
439 return err; 461 return err;
440 } 462 }
441 for (i = 0, p = cfg->hp_pins; i < cfg->hp_outs; i++, p++) { 463 for (i = 0, p = cfg->hp_pins; i < cfg->hp_outs; i++, p++) {
442 if (*p == *cfg->line_out_pins) /* might be duplicated */ 464 if (*p == *cfg->line_out_pins) /* might be duplicated */
443 break; 465 break;
444 err = add_jack_kctl(codec, *p, cfg); 466 err = add_jack_kctl(codec, *p, cfg, NULL);
445 if (err < 0) 467 if (err < 0)
446 return err; 468 return err;
447 } 469 }
448 for (i = 0, p = cfg->speaker_pins; i < cfg->speaker_outs; i++, p++) { 470 for (i = 0, p = cfg->speaker_pins; i < cfg->speaker_outs; i++, p++) {
449 if (*p == *cfg->line_out_pins) /* might be duplicated */ 471 if (*p == *cfg->line_out_pins) /* might be duplicated */
450 break; 472 break;
451 err = add_jack_kctl(codec, *p, cfg); 473 err = add_jack_kctl(codec, *p, cfg, NULL);
452 if (err < 0)
453 return err;
454 }
455 for (i = 0; i < cfg->num_inputs; i++) {
456 err = add_jack_kctl(codec, cfg->inputs[i].pin, cfg);
457 if (err < 0) 474 if (err < 0)
458 return err; 475 return err;
459 } 476 }
460 for (i = 0, p = cfg->dig_out_pins; i < cfg->dig_outs; i++, p++) { 477 for (i = 0, p = cfg->dig_out_pins; i < cfg->dig_outs; i++, p++) {
461 err = add_jack_kctl(codec, *p, cfg); 478 err = add_jack_kctl(codec, *p, cfg, NULL);
462 if (err < 0) 479 if (err < 0)
463 return err; 480 return err;
464 } 481 }
465 err = add_jack_kctl(codec, cfg->dig_in_pin, cfg); 482 err = add_jack_kctl(codec, cfg->dig_in_pin, cfg, NULL);
466 if (err < 0) 483 if (err < 0)
467 return err; 484 return err;
468 err = add_jack_kctl(codec, cfg->mono_out_pin, cfg); 485 err = add_jack_kctl(codec, cfg->mono_out_pin, cfg, NULL);
469 if (err < 0) 486 if (err < 0)
470 return err; 487 return err;
471 return 0; 488 return 0;
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 83b7486c8eff..e0bf7534fa1f 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -670,6 +670,10 @@ snd_hda_check_power_state(struct hda_codec *codec, hda_nid_t nid,
670 return (state != target_state); 670 return (state != target_state);
671} 671}
672 672
673unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
674 hda_nid_t nid,
675 unsigned int power_state);
676
673/* 677/*
674 * AMP control callbacks 678 * AMP control callbacks
675 */ 679 */
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index df8014b27596..977b0d878dae 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -43,7 +43,6 @@ struct ad198x_spec {
43 hda_nid_t eapd_nid; 43 hda_nid_t eapd_nid;
44 44
45 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ 45 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
46 hda_nid_t beep_dev_nid;
47 46
48#ifdef ENABLE_AD_STATIC_QUIRKS 47#ifdef ENABLE_AD_STATIC_QUIRKS
49 const struct snd_kcontrol_new *mixers[6]; 48 const struct snd_kcontrol_new *mixers[6];
@@ -609,7 +608,7 @@ static const struct hda_codec_ops ad198x_auto_patch_ops = {
609 .build_controls = ad198x_auto_build_controls, 608 .build_controls = ad198x_auto_build_controls,
610 .build_pcms = snd_hda_gen_build_pcms, 609 .build_pcms = snd_hda_gen_build_pcms,
611 .init = snd_hda_gen_init, 610 .init = snd_hda_gen_init,
612 .free = ad198x_free, 611 .free = snd_hda_gen_free,
613 .unsol_event = snd_hda_jack_unsol_event, 612 .unsol_event = snd_hda_jack_unsol_event,
614#ifdef CONFIG_PM 613#ifdef CONFIG_PM
615 .check_power_status = snd_hda_gen_check_power_status, 614 .check_power_status = snd_hda_gen_check_power_status,
@@ -638,12 +637,6 @@ static int ad198x_parse_auto_config(struct hda_codec *codec)
638 if (err < 0) 637 if (err < 0)
639 return err; 638 return err;
640 639
641 if (spec->beep_dev_nid) {
642 err = snd_hda_attach_beep_device(codec, spec->beep_dev_nid);
643 if (err < 0)
644 return err;
645 }
646
647 codec->patch_ops = ad198x_auto_patch_ops; 640 codec->patch_ops = ad198x_auto_patch_ops;
648 641
649 return 0; 642 return 0;
@@ -1240,7 +1233,7 @@ static int ad1986a_parse_auto_config(struct hda_codec *codec)
1240 codec->inv_eapd = 1; 1233 codec->inv_eapd = 1;
1241 1234
1242 spec->gen.mixer_nid = 0x07; 1235 spec->gen.mixer_nid = 0x07;
1243 spec->beep_dev_nid = 0x19; 1236 spec->gen.beep_nid = 0x19;
1244 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT); 1237 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
1245 1238
1246 /* AD1986A has a hardware problem that it can't share a stream 1239 /* AD1986A has a hardware problem that it can't share a stream
@@ -1256,7 +1249,7 @@ static int ad1986a_parse_auto_config(struct hda_codec *codec)
1256 1249
1257 err = ad198x_parse_auto_config(codec); 1250 err = ad198x_parse_auto_config(codec);
1258 if (err < 0) { 1251 if (err < 0) {
1259 ad198x_free(codec); 1252 snd_hda_gen_free(codec);
1260 return err; 1253 return err;
1261 } 1254 }
1262 1255
@@ -1673,7 +1666,7 @@ static int ad1983_parse_auto_config(struct hda_codec *codec)
1673 return err; 1666 return err;
1674 spec = codec->spec; 1667 spec = codec->spec;
1675 1668
1676 spec->beep_dev_nid = 0x10; 1669 spec->gen.beep_nid = 0x10;
1677 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); 1670 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1678 err = ad198x_parse_auto_config(codec); 1671 err = ad198x_parse_auto_config(codec);
1679 if (err < 0) 1672 if (err < 0)
@@ -1684,7 +1677,7 @@ static int ad1983_parse_auto_config(struct hda_codec *codec)
1684 return 0; 1677 return 0;
1685 1678
1686 error: 1679 error:
1687 ad198x_free(codec); 1680 snd_hda_gen_free(codec);
1688 return err; 1681 return err;
1689} 1682}
1690 1683
@@ -2187,7 +2180,7 @@ static int ad1981_parse_auto_config(struct hda_codec *codec)
2187 spec = codec->spec; 2180 spec = codec->spec;
2188 2181
2189 spec->gen.mixer_nid = 0x0e; 2182 spec->gen.mixer_nid = 0x0e;
2190 spec->beep_dev_nid = 0x10; 2183 spec->gen.beep_nid = 0x10;
2191 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT); 2184 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
2192 2185
2193 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups); 2186 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
@@ -2205,7 +2198,7 @@ static int ad1981_parse_auto_config(struct hda_codec *codec)
2205 return 0; 2198 return 0;
2206 2199
2207 error: 2200 error:
2208 ad198x_free(codec); 2201 snd_hda_gen_free(codec);
2209 return err; 2202 return err;
2210} 2203}
2211 2204
@@ -3236,7 +3229,7 @@ static int ad1988_parse_auto_config(struct hda_codec *codec)
3236 3229
3237 spec->gen.mixer_nid = 0x20; 3230 spec->gen.mixer_nid = 0x20;
3238 spec->gen.mixer_merge_nid = 0x21; 3231 spec->gen.mixer_merge_nid = 0x21;
3239 spec->beep_dev_nid = 0x10; 3232 spec->gen.beep_nid = 0x10;
3240 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); 3233 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3241 err = ad198x_parse_auto_config(codec); 3234 err = ad198x_parse_auto_config(codec);
3242 if (err < 0) 3235 if (err < 0)
@@ -3247,7 +3240,7 @@ static int ad1988_parse_auto_config(struct hda_codec *codec)
3247 return 0; 3240 return 0;
3248 3241
3249 error: 3242 error:
3250 ad198x_free(codec); 3243 snd_hda_gen_free(codec);
3251 return err; 3244 return err;
3252} 3245}
3253 3246
@@ -3653,7 +3646,7 @@ static int ad1884_parse_auto_config(struct hda_codec *codec)
3653 spec = codec->spec; 3646 spec = codec->spec;
3654 3647
3655 spec->gen.mixer_nid = 0x20; 3648 spec->gen.mixer_nid = 0x20;
3656 spec->beep_dev_nid = 0x10; 3649 spec->gen.beep_nid = 0x10;
3657 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); 3650 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3658 3651
3659 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups); 3652 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
@@ -3671,7 +3664,7 @@ static int ad1884_parse_auto_config(struct hda_codec *codec)
3671 return 0; 3664 return 0;
3672 3665
3673 error: 3666 error:
3674 ad198x_free(codec); 3667 snd_hda_gen_free(codec);
3675 return err; 3668 return err;
3676} 3669}
3677 3670
@@ -5155,7 +5148,7 @@ static int ad1882_parse_auto_config(struct hda_codec *codec)
5155 5148
5156 spec->gen.mixer_nid = 0x20; 5149 spec->gen.mixer_nid = 0x20;
5157 spec->gen.mixer_merge_nid = 0x21; 5150 spec->gen.mixer_merge_nid = 0x21;
5158 spec->beep_dev_nid = 0x10; 5151 spec->gen.beep_nid = 0x10;
5159 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); 5152 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
5160 err = ad198x_parse_auto_config(codec); 5153 err = ad198x_parse_auto_config(codec);
5161 if (err < 0) 5154 if (err < 0)
@@ -5166,7 +5159,7 @@ static int ad1882_parse_auto_config(struct hda_codec *codec)
5166 return 0; 5159 return 0;
5167 5160
5168 error: 5161 error:
5169 ad198x_free(codec); 5162 snd_hda_gen_free(codec);
5170 return err; 5163 return err;
5171} 5164}
5172 5165
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 0792b5725f9c..90ff7a3f72df 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -131,6 +131,13 @@ enum {
131/* Effects values size*/ 131/* Effects values size*/
132#define EFFECT_VALS_MAX_COUNT 12 132#define EFFECT_VALS_MAX_COUNT 12
133 133
134/* Latency introduced by DSP blocks in milliseconds. */
135#define DSP_CAPTURE_INIT_LATENCY 0
136#define DSP_CRYSTAL_VOICE_LATENCY 124
137#define DSP_PLAYBACK_INIT_LATENCY 13
138#define DSP_PLAY_ENHANCEMENT_LATENCY 30
139#define DSP_SPEAKER_OUT_LATENCY 7
140
134struct ct_effect { 141struct ct_effect {
135 char name[44]; 142 char name[44];
136 hda_nid_t nid; 143 hda_nid_t nid;
@@ -741,6 +748,9 @@ struct ca0132_spec {
741 long voicefx_val; 748 long voicefx_val;
742 long cur_mic_boost; 749 long cur_mic_boost;
743 750
751 struct hda_codec *codec;
752 struct delayed_work unsol_hp_work;
753
744#ifdef ENABLE_TUNING_CONTROLS 754#ifdef ENABLE_TUNING_CONTROLS
745 long cur_ctl_vals[TUNING_CTLS_COUNT]; 755 long cur_ctl_vals[TUNING_CTLS_COUNT];
746#endif 756#endif
@@ -2740,6 +2750,31 @@ static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2740 return 0; 2750 return 0;
2741} 2751}
2742 2752
2753static unsigned int ca0132_playback_pcm_delay(struct hda_pcm_stream *info,
2754 struct hda_codec *codec,
2755 struct snd_pcm_substream *substream)
2756{
2757 struct ca0132_spec *spec = codec->spec;
2758 unsigned int latency = DSP_PLAYBACK_INIT_LATENCY;
2759 struct snd_pcm_runtime *runtime = substream->runtime;
2760
2761 if (spec->dsp_state != DSP_DOWNLOADED)
2762 return 0;
2763
2764 /* Add latency if playback enhancement and either effect is enabled. */
2765 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]) {
2766 if ((spec->effects_switch[SURROUND - EFFECT_START_NID]) ||
2767 (spec->effects_switch[DIALOG_PLUS - EFFECT_START_NID]))
2768 latency += DSP_PLAY_ENHANCEMENT_LATENCY;
2769 }
2770
2771 /* Applying Speaker EQ adds latency as well. */
2772 if (spec->cur_out_type == SPEAKER_OUT)
2773 latency += DSP_SPEAKER_OUT_LATENCY;
2774
2775 return (latency * runtime->rate) / 1000;
2776}
2777
2743/* 2778/*
2744 * Digital out 2779 * Digital out
2745 */ 2780 */
@@ -2808,6 +2843,23 @@ static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2808 return 0; 2843 return 0;
2809} 2844}
2810 2845
2846static unsigned int ca0132_capture_pcm_delay(struct hda_pcm_stream *info,
2847 struct hda_codec *codec,
2848 struct snd_pcm_substream *substream)
2849{
2850 struct ca0132_spec *spec = codec->spec;
2851 unsigned int latency = DSP_CAPTURE_INIT_LATENCY;
2852 struct snd_pcm_runtime *runtime = substream->runtime;
2853
2854 if (spec->dsp_state != DSP_DOWNLOADED)
2855 return 0;
2856
2857 if (spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
2858 latency += DSP_CRYSTAL_VOICE_LATENCY;
2859
2860 return (latency * runtime->rate) / 1000;
2861}
2862
2811/* 2863/*
2812 * Controls stuffs. 2864 * Controls stuffs.
2813 */ 2865 */
@@ -3227,6 +3279,14 @@ exit:
3227 return err < 0 ? err : 0; 3279 return err < 0 ? err : 0;
3228} 3280}
3229 3281
3282static void ca0132_unsol_hp_delayed(struct work_struct *work)
3283{
3284 struct ca0132_spec *spec = container_of(
3285 to_delayed_work(work), struct ca0132_spec, unsol_hp_work);
3286 ca0132_select_out(spec->codec);
3287 snd_hda_jack_report_sync(spec->codec);
3288}
3289
3230static void ca0132_set_dmic(struct hda_codec *codec, int enable); 3290static void ca0132_set_dmic(struct hda_codec *codec, int enable);
3231static int ca0132_mic_boost_set(struct hda_codec *codec, long val); 3291static int ca0132_mic_boost_set(struct hda_codec *codec, long val);
3232static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val); 3292static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val);
@@ -3991,7 +4051,8 @@ static struct hda_pcm_stream ca0132_pcm_analog_playback = {
3991 .channels_max = 6, 4051 .channels_max = 6,
3992 .ops = { 4052 .ops = {
3993 .prepare = ca0132_playback_pcm_prepare, 4053 .prepare = ca0132_playback_pcm_prepare,
3994 .cleanup = ca0132_playback_pcm_cleanup 4054 .cleanup = ca0132_playback_pcm_cleanup,
4055 .get_delay = ca0132_playback_pcm_delay,
3995 }, 4056 },
3996}; 4057};
3997 4058
@@ -4001,7 +4062,8 @@ static struct hda_pcm_stream ca0132_pcm_analog_capture = {
4001 .channels_max = 2, 4062 .channels_max = 2,
4002 .ops = { 4063 .ops = {
4003 .prepare = ca0132_capture_pcm_prepare, 4064 .prepare = ca0132_capture_pcm_prepare,
4004 .cleanup = ca0132_capture_pcm_cleanup 4065 .cleanup = ca0132_capture_pcm_cleanup,
4066 .get_delay = ca0132_capture_pcm_delay,
4005 }, 4067 },
4006}; 4068};
4007 4069
@@ -4399,8 +4461,7 @@ static void ca0132_process_dsp_response(struct hda_codec *codec)
4399 4461
4400static void ca0132_unsol_event(struct hda_codec *codec, unsigned int res) 4462static void ca0132_unsol_event(struct hda_codec *codec, unsigned int res)
4401{ 4463{
4402 snd_printdd(KERN_INFO "ca0132_unsol_event: 0x%x\n", res); 4464 struct ca0132_spec *spec = codec->spec;
4403
4404 4465
4405 if (((res >> AC_UNSOL_RES_TAG_SHIFT) & 0x3f) == UNSOL_TAG_DSP) { 4466 if (((res >> AC_UNSOL_RES_TAG_SHIFT) & 0x3f) == UNSOL_TAG_DSP) {
4406 ca0132_process_dsp_response(codec); 4467 ca0132_process_dsp_response(codec);
@@ -4412,8 +4473,13 @@ static void ca0132_unsol_event(struct hda_codec *codec, unsigned int res)
4412 4473
4413 switch (res) { 4474 switch (res) {
4414 case UNSOL_TAG_HP: 4475 case UNSOL_TAG_HP:
4415 ca0132_select_out(codec); 4476 /* Delay enabling the HP amp, to let the mic-detection
4416 snd_hda_jack_report_sync(codec); 4477 * state machine run.
4478 */
4479 cancel_delayed_work_sync(&spec->unsol_hp_work);
4480 queue_delayed_work(codec->bus->workq,
4481 &spec->unsol_hp_work,
4482 msecs_to_jiffies(500));
4417 break; 4483 break;
4418 case UNSOL_TAG_AMIC1: 4484 case UNSOL_TAG_AMIC1:
4419 ca0132_select_mic(codec); 4485 ca0132_select_mic(codec);
@@ -4588,6 +4654,7 @@ static void ca0132_free(struct hda_codec *codec)
4588{ 4654{
4589 struct ca0132_spec *spec = codec->spec; 4655 struct ca0132_spec *spec = codec->spec;
4590 4656
4657 cancel_delayed_work_sync(&spec->unsol_hp_work);
4591 snd_hda_power_up(codec); 4658 snd_hda_power_up(codec);
4592 snd_hda_sequence_write(codec, spec->base_exit_verbs); 4659 snd_hda_sequence_write(codec, spec->base_exit_verbs);
4593 ca0132_exit_chip(codec); 4660 ca0132_exit_chip(codec);
@@ -4653,6 +4720,7 @@ static int patch_ca0132(struct hda_codec *codec)
4653 if (!spec) 4720 if (!spec)
4654 return -ENOMEM; 4721 return -ENOMEM;
4655 codec->spec = spec; 4722 codec->spec = spec;
4723 spec->codec = codec;
4656 4724
4657 spec->num_mixers = 1; 4725 spec->num_mixers = 1;
4658 spec->mixers[0] = ca0132_mixer; 4726 spec->mixers[0] = ca0132_mixer;
@@ -4663,6 +4731,8 @@ static int patch_ca0132(struct hda_codec *codec)
4663 spec->init_verbs[1] = ca0132_init_verbs1; 4731 spec->init_verbs[1] = ca0132_init_verbs1;
4664 spec->num_init_verbs = 2; 4732 spec->num_init_verbs = 2;
4665 4733
4734 INIT_DELAYED_WORK(&spec->unsol_hp_work, ca0132_unsol_hp_delayed);
4735
4666 ca0132_init_chip(codec); 4736 ca0132_init_chip(codec);
4667 4737
4668 ca0132_config(codec); 4738 ca0132_config(codec);
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index 0d9c58f13560..bd8d46cca2b3 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -68,6 +68,7 @@ enum {
68enum { 68enum {
69 CS421X_CDB4210, 69 CS421X_CDB4210,
70 CS421X_SENSE_B, 70 CS421X_SENSE_B,
71 CS421X_STUMPY,
71}; 72};
72 73
73/* Vendor-specific processing widget */ 74/* Vendor-specific processing widget */
@@ -538,6 +539,7 @@ static int patch_cs420x(struct hda_codec *codec)
538/* CS4210 board names */ 539/* CS4210 board names */
539static const struct hda_model_fixup cs421x_models[] = { 540static const struct hda_model_fixup cs421x_models[] = {
540 { .id = CS421X_CDB4210, .name = "cdb4210" }, 541 { .id = CS421X_CDB4210, .name = "cdb4210" },
542 { .id = CS421X_STUMPY, .name = "stumpy" },
541 {} 543 {}
542}; 544};
543 545
@@ -559,6 +561,17 @@ static const struct hda_pintbl cdb4210_pincfgs[] = {
559 {} /* terminator */ 561 {} /* terminator */
560}; 562};
561 563
564/* Stumpy ChromeBox */
565static const struct hda_pintbl stumpy_pincfgs[] = {
566 { 0x05, 0x022120f0 },
567 { 0x06, 0x901700f0 },
568 { 0x07, 0x02a120f0 },
569 { 0x08, 0x77a70037 },
570 { 0x09, 0x77a6003e },
571 { 0x0a, 0x434510f0 },
572 {} /* terminator */
573};
574
562/* Setup GPIO/SENSE for each board (if used) */ 575/* Setup GPIO/SENSE for each board (if used) */
563static void cs421x_fixup_sense_b(struct hda_codec *codec, 576static void cs421x_fixup_sense_b(struct hda_codec *codec,
564 const struct hda_fixup *fix, int action) 577 const struct hda_fixup *fix, int action)
@@ -578,7 +591,11 @@ static const struct hda_fixup cs421x_fixups[] = {
578 [CS421X_SENSE_B] = { 591 [CS421X_SENSE_B] = {
579 .type = HDA_FIXUP_FUNC, 592 .type = HDA_FIXUP_FUNC,
580 .v.func = cs421x_fixup_sense_b, 593 .v.func = cs421x_fixup_sense_b,
581 } 594 },
595 [CS421X_STUMPY] = {
596 .type = HDA_FIXUP_PINS,
597 .v.pins = stumpy_pincfgs,
598 },
582}; 599};
583 600
584static const struct hda_verb cs421x_coef_init_verbs[] = { 601static const struct hda_verb cs421x_coef_init_verbs[] = {
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 2a89d1eefeb6..549964395770 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -139,8 +139,12 @@ struct conexant_spec {
139 139
140 140
141#ifdef CONFIG_SND_HDA_INPUT_BEEP 141#ifdef CONFIG_SND_HDA_INPUT_BEEP
142#define set_beep_amp(spec, nid, idx, dir) \ 142static inline void set_beep_amp(struct conexant_spec *spec, hda_nid_t nid,
143 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) 143 int idx, int dir)
144{
145 spec->gen.beep_nid = nid;
146 spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
147}
144/* additional beep mixers; the actual parameters are overwritten at build */ 148/* additional beep mixers; the actual parameters are overwritten at build */
145static const struct snd_kcontrol_new cxt_beep_mixer[] = { 149static const struct snd_kcontrol_new cxt_beep_mixer[] = {
146 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 150 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
@@ -3191,17 +3195,11 @@ static int cx_auto_build_controls(struct hda_codec *codec)
3191 return 0; 3195 return 0;
3192} 3196}
3193 3197
3194static void cx_auto_free(struct hda_codec *codec)
3195{
3196 snd_hda_detach_beep_device(codec);
3197 snd_hda_gen_free(codec);
3198}
3199
3200static const struct hda_codec_ops cx_auto_patch_ops = { 3198static const struct hda_codec_ops cx_auto_patch_ops = {
3201 .build_controls = cx_auto_build_controls, 3199 .build_controls = cx_auto_build_controls,
3202 .build_pcms = snd_hda_gen_build_pcms, 3200 .build_pcms = snd_hda_gen_build_pcms,
3203 .init = snd_hda_gen_init, 3201 .init = snd_hda_gen_init,
3204 .free = cx_auto_free, 3202 .free = snd_hda_gen_free,
3205 .unsol_event = snd_hda_jack_unsol_event, 3203 .unsol_event = snd_hda_jack_unsol_event,
3206#ifdef CONFIG_PM 3204#ifdef CONFIG_PM
3207 .check_power_status = snd_hda_gen_check_power_status, 3205 .check_power_status = snd_hda_gen_check_power_status,
@@ -3356,7 +3354,6 @@ static int patch_conexant_auto(struct hda_codec *codec)
3356 switch (codec->vendor_id) { 3354 switch (codec->vendor_id) {
3357 case 0x14f15045: 3355 case 0x14f15045:
3358 codec->single_adc_amp = 1; 3356 codec->single_adc_amp = 1;
3359 codec->power_filter = NULL; /* Needs speaker amp to D3 to avoid click */
3360 break; 3357 break;
3361 case 0x14f15047: 3358 case 0x14f15047:
3362 codec->pin_amp_workaround = 1; 3359 codec->pin_amp_workaround = 1;
@@ -3396,8 +3393,6 @@ static int patch_conexant_auto(struct hda_codec *codec)
3396 goto error; 3393 goto error;
3397 3394
3398 codec->patch_ops = cx_auto_patch_ops; 3395 codec->patch_ops = cx_auto_patch_ops;
3399 if (spec->beep_amp)
3400 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
3401 3396
3402 /* Some laptops with Conexant chips show stalls in S3 resume, 3397 /* Some laptops with Conexant chips show stalls in S3 resume,
3403 * which falls into the single-cmd mode. 3398 * which falls into the single-cmd mode.
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index de8ac5c07fd0..ede82156da0f 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -44,16 +44,6 @@ static bool static_hdmi_pcm;
44module_param(static_hdmi_pcm, bool, 0644); 44module_param(static_hdmi_pcm, bool, 0644);
45MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info"); 45MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
46 46
47/*
48 * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device
49 * could support N independent pipes, each of them can be connected to one or
50 * more ports (DVI, HDMI or DisplayPort).
51 *
52 * The HDA correspondence of pipes/ports are converter/pin nodes.
53 */
54#define MAX_HDMI_CVTS 8
55#define MAX_HDMI_PINS 8
56
57struct hdmi_spec_per_cvt { 47struct hdmi_spec_per_cvt {
58 hda_nid_t cvt_nid; 48 hda_nid_t cvt_nid;
59 int assigned; 49 int assigned;
@@ -80,16 +70,17 @@ struct hdmi_spec_per_pin {
80 bool non_pcm; 70 bool non_pcm;
81 bool chmap_set; /* channel-map override by ALSA API? */ 71 bool chmap_set; /* channel-map override by ALSA API? */
82 unsigned char chmap[8]; /* ALSA API channel-map */ 72 unsigned char chmap[8]; /* ALSA API channel-map */
73 char pcm_name[8]; /* filled in build_pcm callbacks */
83}; 74};
84 75
85struct hdmi_spec { 76struct hdmi_spec {
86 int num_cvts; 77 int num_cvts;
87 struct hdmi_spec_per_cvt cvts[MAX_HDMI_CVTS]; 78 struct snd_array cvts; /* struct hdmi_spec_per_cvt */
88 hda_nid_t cvt_nids[MAX_HDMI_CVTS]; 79 hda_nid_t cvt_nids[4]; /* only for haswell fix */
89 80
90 int num_pins; 81 int num_pins;
91 struct hdmi_spec_per_pin pins[MAX_HDMI_PINS]; 82 struct snd_array pins; /* struct hdmi_spec_per_pin */
92 struct hda_pcm pcm_rec[MAX_HDMI_PINS]; 83 struct snd_array pcm_rec; /* struct hda_pcm */
93 unsigned int channels_max; /* max over all cvts */ 84 unsigned int channels_max; /* max over all cvts */
94 85
95 struct hdmi_eld temp_eld; 86 struct hdmi_eld temp_eld;
@@ -304,12 +295,19 @@ static struct cea_channel_speaker_allocation channel_allocations[] = {
304 * HDMI routines 295 * HDMI routines
305 */ 296 */
306 297
298#define get_pin(spec, idx) \
299 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
300#define get_cvt(spec, idx) \
301 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
302#define get_pcm_rec(spec, idx) \
303 ((struct hda_pcm *)snd_array_elem(&spec->pcm_rec, idx))
304
307static int pin_nid_to_pin_index(struct hdmi_spec *spec, hda_nid_t pin_nid) 305static int pin_nid_to_pin_index(struct hdmi_spec *spec, hda_nid_t pin_nid)
308{ 306{
309 int pin_idx; 307 int pin_idx;
310 308
311 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) 309 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
312 if (spec->pins[pin_idx].pin_nid == pin_nid) 310 if (get_pin(spec, pin_idx)->pin_nid == pin_nid)
313 return pin_idx; 311 return pin_idx;
314 312
315 snd_printk(KERN_WARNING "HDMI: pin nid %d not registered\n", pin_nid); 313 snd_printk(KERN_WARNING "HDMI: pin nid %d not registered\n", pin_nid);
@@ -322,7 +320,7 @@ static int hinfo_to_pin_index(struct hdmi_spec *spec,
322 int pin_idx; 320 int pin_idx;
323 321
324 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) 322 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
325 if (&spec->pcm_rec[pin_idx].stream[0] == hinfo) 323 if (get_pcm_rec(spec, pin_idx)->stream == hinfo)
326 return pin_idx; 324 return pin_idx;
327 325
328 snd_printk(KERN_WARNING "HDMI: hinfo %p not registered\n", hinfo); 326 snd_printk(KERN_WARNING "HDMI: hinfo %p not registered\n", hinfo);
@@ -334,7 +332,7 @@ static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid)
334 int cvt_idx; 332 int cvt_idx;
335 333
336 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) 334 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
337 if (spec->cvts[cvt_idx].cvt_nid == cvt_nid) 335 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
338 return cvt_idx; 336 return cvt_idx;
339 337
340 snd_printk(KERN_WARNING "HDMI: cvt nid %d not registered\n", cvt_nid); 338 snd_printk(KERN_WARNING "HDMI: cvt nid %d not registered\n", cvt_nid);
@@ -352,7 +350,7 @@ static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
352 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 350 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
353 351
354 pin_idx = kcontrol->private_value; 352 pin_idx = kcontrol->private_value;
355 eld = &spec->pins[pin_idx].sink_eld; 353 eld = &get_pin(spec, pin_idx)->sink_eld;
356 354
357 mutex_lock(&eld->lock); 355 mutex_lock(&eld->lock);
358 uinfo->count = eld->eld_valid ? eld->eld_size : 0; 356 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
@@ -370,7 +368,7 @@ static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
370 int pin_idx; 368 int pin_idx;
371 369
372 pin_idx = kcontrol->private_value; 370 pin_idx = kcontrol->private_value;
373 eld = &spec->pins[pin_idx].sink_eld; 371 eld = &get_pin(spec, pin_idx)->sink_eld;
374 372
375 mutex_lock(&eld->lock); 373 mutex_lock(&eld->lock);
376 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) { 374 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) {
@@ -410,11 +408,11 @@ static int hdmi_create_eld_ctl(struct hda_codec *codec, int pin_idx,
410 kctl->private_value = pin_idx; 408 kctl->private_value = pin_idx;
411 kctl->id.device = device; 409 kctl->id.device = device;
412 410
413 err = snd_hda_ctl_add(codec, spec->pins[pin_idx].pin_nid, kctl); 411 err = snd_hda_ctl_add(codec, get_pin(spec, pin_idx)->pin_nid, kctl);
414 if (err < 0) 412 if (err < 0)
415 return err; 413 return err;
416 414
417 spec->pins[pin_idx].eld_ctl = kctl; 415 get_pin(spec, pin_idx)->eld_ctl = kctl;
418 return 0; 416 return 0;
419} 417}
420 418
@@ -875,14 +873,14 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec, int pin_idx,
875 struct snd_pcm_substream *substream) 873 struct snd_pcm_substream *substream)
876{ 874{
877 struct hdmi_spec *spec = codec->spec; 875 struct hdmi_spec *spec = codec->spec;
878 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx]; 876 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
879 hda_nid_t pin_nid = per_pin->pin_nid; 877 hda_nid_t pin_nid = per_pin->pin_nid;
880 int channels = substream->runtime->channels; 878 int channels = substream->runtime->channels;
881 struct hdmi_eld *eld; 879 struct hdmi_eld *eld;
882 int ca; 880 int ca;
883 union audio_infoframe ai; 881 union audio_infoframe ai;
884 882
885 eld = &spec->pins[pin_idx].sink_eld; 883 eld = &per_pin->sink_eld;
886 if (!eld->monitor_present) 884 if (!eld->monitor_present)
887 return; 885 return;
888 886
@@ -977,7 +975,7 @@ static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
977 if (pin_idx < 0) 975 if (pin_idx < 0)
978 return; 976 return;
979 977
980 hdmi_present_sense(&spec->pins[pin_idx], 1); 978 hdmi_present_sense(get_pin(spec, pin_idx), 1);
981 snd_hda_jack_report_sync(codec); 979 snd_hda_jack_report_sync(codec);
982} 980}
983 981
@@ -1083,12 +1081,12 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1083 pin_idx = hinfo_to_pin_index(spec, hinfo); 1081 pin_idx = hinfo_to_pin_index(spec, hinfo);
1084 if (snd_BUG_ON(pin_idx < 0)) 1082 if (snd_BUG_ON(pin_idx < 0))
1085 return -EINVAL; 1083 return -EINVAL;
1086 per_pin = &spec->pins[pin_idx]; 1084 per_pin = get_pin(spec, pin_idx);
1087 eld = &per_pin->sink_eld; 1085 eld = &per_pin->sink_eld;
1088 1086
1089 /* Dynamically assign converter to stream */ 1087 /* Dynamically assign converter to stream */
1090 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) { 1088 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
1091 per_cvt = &spec->cvts[cvt_idx]; 1089 per_cvt = get_cvt(spec, cvt_idx);
1092 1090
1093 /* Must not already be assigned */ 1091 /* Must not already be assigned */
1094 if (per_cvt->assigned) 1092 if (per_cvt->assigned)
@@ -1151,7 +1149,7 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1151static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx) 1149static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1152{ 1150{
1153 struct hdmi_spec *spec = codec->spec; 1151 struct hdmi_spec *spec = codec->spec;
1154 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx]; 1152 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1155 hda_nid_t pin_nid = per_pin->pin_nid; 1153 hda_nid_t pin_nid = per_pin->pin_nid;
1156 1154
1157 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) { 1155 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
@@ -1275,14 +1273,13 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1275 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE) 1273 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
1276 return 0; 1274 return 0;
1277 1275
1278 if (snd_BUG_ON(spec->num_pins >= MAX_HDMI_PINS))
1279 return -E2BIG;
1280
1281 if (codec->vendor_id == 0x80862807) 1276 if (codec->vendor_id == 0x80862807)
1282 intel_haswell_fixup_connect_list(codec, pin_nid); 1277 intel_haswell_fixup_connect_list(codec, pin_nid);
1283 1278
1284 pin_idx = spec->num_pins; 1279 pin_idx = spec->num_pins;
1285 per_pin = &spec->pins[pin_idx]; 1280 per_pin = snd_array_new(&spec->pins);
1281 if (!per_pin)
1282 return -ENOMEM;
1286 1283
1287 per_pin->pin_nid = pin_nid; 1284 per_pin->pin_nid = pin_nid;
1288 per_pin->non_pcm = false; 1285 per_pin->non_pcm = false;
@@ -1299,19 +1296,16 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1299static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid) 1296static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1300{ 1297{
1301 struct hdmi_spec *spec = codec->spec; 1298 struct hdmi_spec *spec = codec->spec;
1302 int cvt_idx;
1303 struct hdmi_spec_per_cvt *per_cvt; 1299 struct hdmi_spec_per_cvt *per_cvt;
1304 unsigned int chans; 1300 unsigned int chans;
1305 int err; 1301 int err;
1306 1302
1307 if (snd_BUG_ON(spec->num_cvts >= MAX_HDMI_CVTS))
1308 return -E2BIG;
1309
1310 chans = get_wcaps(codec, cvt_nid); 1303 chans = get_wcaps(codec, cvt_nid);
1311 chans = get_wcaps_channels(chans); 1304 chans = get_wcaps_channels(chans);
1312 1305
1313 cvt_idx = spec->num_cvts; 1306 per_cvt = snd_array_new(&spec->cvts);
1314 per_cvt = &spec->cvts[cvt_idx]; 1307 if (!per_cvt)
1308 return -ENOMEM;
1315 1309
1316 per_cvt->cvt_nid = cvt_nid; 1310 per_cvt->cvt_nid = cvt_nid;
1317 per_cvt->channels_min = 2; 1311 per_cvt->channels_min = 2;
@@ -1328,7 +1322,9 @@ static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1328 if (err < 0) 1322 if (err < 0)
1329 return err; 1323 return err;
1330 1324
1331 spec->cvt_nids[spec->num_cvts++] = cvt_nid; 1325 if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids))
1326 spec->cvt_nids[spec->num_cvts] = cvt_nid;
1327 spec->num_cvts++;
1332 1328
1333 return 0; 1329 return 0;
1334} 1330}
@@ -1384,13 +1380,6 @@ static int hdmi_parse_codec(struct hda_codec *codec)
1384 1380
1385/* 1381/*
1386 */ 1382 */
1387static char *get_hdmi_pcm_name(int idx)
1388{
1389 static char names[MAX_HDMI_PINS][8];
1390 sprintf(&names[idx][0], "HDMI %d", idx);
1391 return &names[idx][0];
1392}
1393
1394static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid) 1383static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1395{ 1384{
1396 struct hda_spdif_out *spdif; 1385 struct hda_spdif_out *spdif;
@@ -1417,7 +1406,7 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1417 hda_nid_t cvt_nid = hinfo->nid; 1406 hda_nid_t cvt_nid = hinfo->nid;
1418 struct hdmi_spec *spec = codec->spec; 1407 struct hdmi_spec *spec = codec->spec;
1419 int pin_idx = hinfo_to_pin_index(spec, hinfo); 1408 int pin_idx = hinfo_to_pin_index(spec, hinfo);
1420 hda_nid_t pin_nid = spec->pins[pin_idx].pin_nid; 1409 hda_nid_t pin_nid = get_pin(spec, pin_idx)->pin_nid;
1421 bool non_pcm; 1410 bool non_pcm;
1422 1411
1423 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid); 1412 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
@@ -1450,7 +1439,7 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1450 cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid); 1439 cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid);
1451 if (snd_BUG_ON(cvt_idx < 0)) 1440 if (snd_BUG_ON(cvt_idx < 0))
1452 return -EINVAL; 1441 return -EINVAL;
1453 per_cvt = &spec->cvts[cvt_idx]; 1442 per_cvt = get_cvt(spec, cvt_idx);
1454 1443
1455 snd_BUG_ON(!per_cvt->assigned); 1444 snd_BUG_ON(!per_cvt->assigned);
1456 per_cvt->assigned = 0; 1445 per_cvt->assigned = 0;
@@ -1459,7 +1448,7 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1459 pin_idx = hinfo_to_pin_index(spec, hinfo); 1448 pin_idx = hinfo_to_pin_index(spec, hinfo);
1460 if (snd_BUG_ON(pin_idx < 0)) 1449 if (snd_BUG_ON(pin_idx < 0))
1461 return -EINVAL; 1450 return -EINVAL;
1462 per_pin = &spec->pins[pin_idx]; 1451 per_pin = get_pin(spec, pin_idx);
1463 1452
1464 snd_hda_spdif_ctls_unassign(codec, pin_idx); 1453 snd_hda_spdif_ctls_unassign(codec, pin_idx);
1465 per_pin->chmap_set = false; 1454 per_pin->chmap_set = false;
@@ -1553,7 +1542,7 @@ static int hdmi_chmap_ctl_get(struct snd_kcontrol *kcontrol,
1553 struct hda_codec *codec = info->private_data; 1542 struct hda_codec *codec = info->private_data;
1554 struct hdmi_spec *spec = codec->spec; 1543 struct hdmi_spec *spec = codec->spec;
1555 int pin_idx = kcontrol->private_value; 1544 int pin_idx = kcontrol->private_value;
1556 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx]; 1545 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1557 int i; 1546 int i;
1558 1547
1559 for (i = 0; i < ARRAY_SIZE(per_pin->chmap); i++) 1548 for (i = 0; i < ARRAY_SIZE(per_pin->chmap); i++)
@@ -1568,7 +1557,7 @@ static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
1568 struct hda_codec *codec = info->private_data; 1557 struct hda_codec *codec = info->private_data;
1569 struct hdmi_spec *spec = codec->spec; 1558 struct hdmi_spec *spec = codec->spec;
1570 int pin_idx = kcontrol->private_value; 1559 int pin_idx = kcontrol->private_value;
1571 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx]; 1560 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1572 unsigned int ctl_idx; 1561 unsigned int ctl_idx;
1573 struct snd_pcm_substream *substream; 1562 struct snd_pcm_substream *substream;
1574 unsigned char chmap[8]; 1563 unsigned char chmap[8];
@@ -1613,9 +1602,14 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec)
1613 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 1602 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1614 struct hda_pcm *info; 1603 struct hda_pcm *info;
1615 struct hda_pcm_stream *pstr; 1604 struct hda_pcm_stream *pstr;
1616 1605 struct hdmi_spec_per_pin *per_pin;
1617 info = &spec->pcm_rec[pin_idx]; 1606
1618 info->name = get_hdmi_pcm_name(pin_idx); 1607 per_pin = get_pin(spec, pin_idx);
1608 sprintf(per_pin->pcm_name, "HDMI %d", pin_idx);
1609 info = snd_array_new(&spec->pcm_rec);
1610 if (!info)
1611 return -ENOMEM;
1612 info->name = per_pin->pcm_name;
1619 info->pcm_type = HDA_PCM_TYPE_HDMI; 1613 info->pcm_type = HDA_PCM_TYPE_HDMI;
1620 info->own_chmap = true; 1614 info->own_chmap = true;
1621 1615
@@ -1626,7 +1620,7 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec)
1626 } 1620 }
1627 1621
1628 codec->num_pcms = spec->num_pins; 1622 codec->num_pcms = spec->num_pins;
1629 codec->pcm_info = spec->pcm_rec; 1623 codec->pcm_info = spec->pcm_rec.list;
1630 1624
1631 return 0; 1625 return 0;
1632} 1626}
@@ -1635,8 +1629,8 @@ static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
1635{ 1629{
1636 char hdmi_str[32] = "HDMI/DP"; 1630 char hdmi_str[32] = "HDMI/DP";
1637 struct hdmi_spec *spec = codec->spec; 1631 struct hdmi_spec *spec = codec->spec;
1638 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx]; 1632 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1639 int pcmdev = spec->pcm_rec[pin_idx].device; 1633 int pcmdev = get_pcm_rec(spec, pin_idx)->device;
1640 1634
1641 if (pcmdev > 0) 1635 if (pcmdev > 0)
1642 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev); 1636 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
@@ -1654,7 +1648,7 @@ static int generic_hdmi_build_controls(struct hda_codec *codec)
1654 int pin_idx; 1648 int pin_idx;
1655 1649
1656 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 1650 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1657 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx]; 1651 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1658 1652
1659 err = generic_hdmi_build_jack(codec, pin_idx); 1653 err = generic_hdmi_build_jack(codec, pin_idx);
1660 if (err < 0) 1654 if (err < 0)
@@ -1669,9 +1663,8 @@ static int generic_hdmi_build_controls(struct hda_codec *codec)
1669 snd_hda_spdif_ctls_unassign(codec, pin_idx); 1663 snd_hda_spdif_ctls_unassign(codec, pin_idx);
1670 1664
1671 /* add control for ELD Bytes */ 1665 /* add control for ELD Bytes */
1672 err = hdmi_create_eld_ctl(codec, 1666 err = hdmi_create_eld_ctl(codec, pin_idx,
1673 pin_idx, 1667 get_pcm_rec(spec, pin_idx)->device);
1674 spec->pcm_rec[pin_idx].device);
1675 1668
1676 if (err < 0) 1669 if (err < 0)
1677 return err; 1670 return err;
@@ -1709,7 +1702,7 @@ static int generic_hdmi_init_per_pins(struct hda_codec *codec)
1709 int pin_idx; 1702 int pin_idx;
1710 1703
1711 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 1704 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1712 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx]; 1705 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1713 struct hdmi_eld *eld = &per_pin->sink_eld; 1706 struct hdmi_eld *eld = &per_pin->sink_eld;
1714 1707
1715 per_pin->codec = codec; 1708 per_pin->codec = codec;
@@ -1726,7 +1719,7 @@ static int generic_hdmi_init(struct hda_codec *codec)
1726 int pin_idx; 1719 int pin_idx;
1727 1720
1728 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 1721 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1729 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx]; 1722 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1730 hda_nid_t pin_nid = per_pin->pin_nid; 1723 hda_nid_t pin_nid = per_pin->pin_nid;
1731 1724
1732 hdmi_init_pin(codec, pin_nid); 1725 hdmi_init_pin(codec, pin_nid);
@@ -1735,13 +1728,27 @@ static int generic_hdmi_init(struct hda_codec *codec)
1735 return 0; 1728 return 0;
1736} 1729}
1737 1730
1731static void hdmi_array_init(struct hdmi_spec *spec, int nums)
1732{
1733 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
1734 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
1735 snd_array_init(&spec->pcm_rec, sizeof(struct hda_pcm), nums);
1736}
1737
1738static void hdmi_array_free(struct hdmi_spec *spec)
1739{
1740 snd_array_free(&spec->pins);
1741 snd_array_free(&spec->cvts);
1742 snd_array_free(&spec->pcm_rec);
1743}
1744
1738static void generic_hdmi_free(struct hda_codec *codec) 1745static void generic_hdmi_free(struct hda_codec *codec)
1739{ 1746{
1740 struct hdmi_spec *spec = codec->spec; 1747 struct hdmi_spec *spec = codec->spec;
1741 int pin_idx; 1748 int pin_idx;
1742 1749
1743 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 1750 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1744 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx]; 1751 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1745 struct hdmi_eld *eld = &per_pin->sink_eld; 1752 struct hdmi_eld *eld = &per_pin->sink_eld;
1746 1753
1747 cancel_delayed_work(&per_pin->work); 1754 cancel_delayed_work(&per_pin->work);
@@ -1749,6 +1756,7 @@ static void generic_hdmi_free(struct hda_codec *codec)
1749 } 1756 }
1750 1757
1751 flush_workqueue(codec->bus->workq); 1758 flush_workqueue(codec->bus->workq);
1759 hdmi_array_free(spec);
1752 kfree(spec); 1760 kfree(spec);
1753} 1761}
1754 1762
@@ -1775,6 +1783,7 @@ static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
1775 1783
1776 /* override pins connection list */ 1784 /* override pins connection list */
1777 snd_printdd("hdmi: haswell: override pin connection 0x%x\n", nid); 1785 snd_printdd("hdmi: haswell: override pin connection 0x%x\n", nid);
1786 nconns = max(spec->num_cvts, 4);
1778 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids); 1787 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
1779} 1788}
1780 1789
@@ -1855,6 +1864,7 @@ static int patch_generic_hdmi(struct hda_codec *codec)
1855 return -ENOMEM; 1864 return -ENOMEM;
1856 1865
1857 codec->spec = spec; 1866 codec->spec = spec;
1867 hdmi_array_init(spec, 4);
1858 1868
1859 snd_hda_pick_fixup(codec, hdmi_models, hdmi_fixup_tbl, hdmi_fixups); 1869 snd_hda_pick_fixup(codec, hdmi_models, hdmi_fixup_tbl, hdmi_fixups);
1860 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 1870 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
@@ -1882,24 +1892,30 @@ static int patch_generic_hdmi(struct hda_codec *codec)
1882static int simple_playback_build_pcms(struct hda_codec *codec) 1892static int simple_playback_build_pcms(struct hda_codec *codec)
1883{ 1893{
1884 struct hdmi_spec *spec = codec->spec; 1894 struct hdmi_spec *spec = codec->spec;
1885 struct hda_pcm *info = spec->pcm_rec; 1895 struct hda_pcm *info;
1886 unsigned int chans; 1896 unsigned int chans;
1887 struct hda_pcm_stream *pstr; 1897 struct hda_pcm_stream *pstr;
1898 struct hdmi_spec_per_cvt *per_cvt;
1888 1899
1889 codec->num_pcms = 1; 1900 per_cvt = get_cvt(spec, 0);
1890 codec->pcm_info = info; 1901 chans = get_wcaps(codec, per_cvt->cvt_nid);
1891
1892 chans = get_wcaps(codec, spec->cvts[0].cvt_nid);
1893 chans = get_wcaps_channels(chans); 1902 chans = get_wcaps_channels(chans);
1894 1903
1895 info->name = get_hdmi_pcm_name(0); 1904 info = snd_array_new(&spec->pcm_rec);
1905 if (!info)
1906 return -ENOMEM;
1907 info->name = get_pin(spec, 0)->pcm_name;
1908 sprintf(info->name, "HDMI 0");
1896 info->pcm_type = HDA_PCM_TYPE_HDMI; 1909 info->pcm_type = HDA_PCM_TYPE_HDMI;
1897 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; 1910 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
1898 *pstr = spec->pcm_playback; 1911 *pstr = spec->pcm_playback;
1899 pstr->nid = spec->cvts[0].cvt_nid; 1912 pstr->nid = per_cvt->cvt_nid;
1900 if (pstr->channels_max <= 2 && chans && chans <= 16) 1913 if (pstr->channels_max <= 2 && chans && chans <= 16)
1901 pstr->channels_max = chans; 1914 pstr->channels_max = chans;
1902 1915
1916 codec->num_pcms = 1;
1917 codec->pcm_info = info;
1918
1903 return 0; 1919 return 0;
1904} 1920}
1905 1921
@@ -1919,11 +1935,12 @@ static void simple_hdmi_unsol_event(struct hda_codec *codec,
1919static int simple_playback_build_controls(struct hda_codec *codec) 1935static int simple_playback_build_controls(struct hda_codec *codec)
1920{ 1936{
1921 struct hdmi_spec *spec = codec->spec; 1937 struct hdmi_spec *spec = codec->spec;
1938 struct hdmi_spec_per_cvt *per_cvt;
1922 int err; 1939 int err;
1923 1940
1924 err = snd_hda_create_spdif_out_ctls(codec, 1941 per_cvt = get_cvt(spec, 0);
1925 spec->cvts[0].cvt_nid, 1942 err = snd_hda_create_spdif_out_ctls(codec, per_cvt->cvt_nid,
1926 spec->cvts[0].cvt_nid); 1943 per_cvt->cvt_nid);
1927 if (err < 0) 1944 if (err < 0)
1928 return err; 1945 return err;
1929 return simple_hdmi_build_jack(codec, 0); 1946 return simple_hdmi_build_jack(codec, 0);
@@ -1932,7 +1949,8 @@ static int simple_playback_build_controls(struct hda_codec *codec)
1932static int simple_playback_init(struct hda_codec *codec) 1949static int simple_playback_init(struct hda_codec *codec)
1933{ 1950{
1934 struct hdmi_spec *spec = codec->spec; 1951 struct hdmi_spec *spec = codec->spec;
1935 hda_nid_t pin = spec->pins[0].pin_nid; 1952 struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0);
1953 hda_nid_t pin = per_pin->pin_nid;
1936 1954
1937 snd_hda_codec_write(codec, pin, 0, 1955 snd_hda_codec_write(codec, pin, 0,
1938 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 1956 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
@@ -1948,6 +1966,7 @@ static void simple_playback_free(struct hda_codec *codec)
1948{ 1966{
1949 struct hdmi_spec *spec = codec->spec; 1967 struct hdmi_spec *spec = codec->spec;
1950 1968
1969 hdmi_array_free(spec);
1951 kfree(spec); 1970 kfree(spec);
1952} 1971}
1953 1972
@@ -2111,20 +2130,29 @@ static int patch_simple_hdmi(struct hda_codec *codec,
2111 hda_nid_t cvt_nid, hda_nid_t pin_nid) 2130 hda_nid_t cvt_nid, hda_nid_t pin_nid)
2112{ 2131{
2113 struct hdmi_spec *spec; 2132 struct hdmi_spec *spec;
2133 struct hdmi_spec_per_cvt *per_cvt;
2134 struct hdmi_spec_per_pin *per_pin;
2114 2135
2115 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 2136 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2116 if (!spec) 2137 if (!spec)
2117 return -ENOMEM; 2138 return -ENOMEM;
2118 2139
2119 codec->spec = spec; 2140 codec->spec = spec;
2141 hdmi_array_init(spec, 1);
2120 2142
2121 spec->multiout.num_dacs = 0; /* no analog */ 2143 spec->multiout.num_dacs = 0; /* no analog */
2122 spec->multiout.max_channels = 2; 2144 spec->multiout.max_channels = 2;
2123 spec->multiout.dig_out_nid = cvt_nid; 2145 spec->multiout.dig_out_nid = cvt_nid;
2124 spec->num_cvts = 1; 2146 spec->num_cvts = 1;
2125 spec->num_pins = 1; 2147 spec->num_pins = 1;
2126 spec->cvts[0].cvt_nid = cvt_nid; 2148 per_pin = snd_array_new(&spec->pins);
2127 spec->pins[0].pin_nid = pin_nid; 2149 per_cvt = snd_array_new(&spec->cvts);
2150 if (!per_pin || !per_cvt) {
2151 simple_playback_free(codec);
2152 return -ENOMEM;
2153 }
2154 per_cvt->cvt_nid = cvt_nid;
2155 per_pin->pin_nid = pin_nid;
2128 spec->pcm_playback = simple_pcm_playback; 2156 spec->pcm_playback = simple_pcm_playback;
2129 2157
2130 codec->patch_ops = simple_hdmi_patch_ops; 2158 codec->patch_ops = simple_hdmi_patch_ops;
@@ -2201,9 +2229,11 @@ static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
2201 int i; 2229 int i;
2202 struct hdmi_spec *spec = codec->spec; 2230 struct hdmi_spec *spec = codec->spec;
2203 struct hda_spdif_out *spdif; 2231 struct hda_spdif_out *spdif;
2232 struct hdmi_spec_per_cvt *per_cvt;
2204 2233
2205 mutex_lock(&codec->spdif_mutex); 2234 mutex_lock(&codec->spdif_mutex);
2206 spdif = snd_hda_spdif_out_of_nid(codec, spec->cvts[0].cvt_nid); 2235 per_cvt = get_cvt(spec, 0);
2236 spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
2207 2237
2208 chs = substream->runtime->channels; 2238 chs = substream->runtime->channels;
2209 2239
@@ -2325,13 +2355,17 @@ static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
2325{ 2355{
2326 struct hdmi_spec *spec = codec->spec; 2356 struct hdmi_spec *spec = codec->spec;
2327 int err = simple_playback_build_pcms(codec); 2357 int err = simple_playback_build_pcms(codec);
2328 spec->pcm_rec[0].own_chmap = true; 2358 if (!err) {
2359 struct hda_pcm *info = get_pcm_rec(spec, 0);
2360 info->own_chmap = true;
2361 }
2329 return err; 2362 return err;
2330} 2363}
2331 2364
2332static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec) 2365static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
2333{ 2366{
2334 struct hdmi_spec *spec = codec->spec; 2367 struct hdmi_spec *spec = codec->spec;
2368 struct hda_pcm *info;
2335 struct snd_pcm_chmap *chmap; 2369 struct snd_pcm_chmap *chmap;
2336 int err; 2370 int err;
2337 2371
@@ -2340,7 +2374,8 @@ static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
2340 return err; 2374 return err;
2341 2375
2342 /* add channel maps */ 2376 /* add channel maps */
2343 err = snd_pcm_add_chmap_ctls(spec->pcm_rec[0].pcm, 2377 info = get_pcm_rec(spec, 0);
2378 err = snd_pcm_add_chmap_ctls(info->pcm,
2344 SNDRV_PCM_STREAM_PLAYBACK, 2379 SNDRV_PCM_STREAM_PLAYBACK,
2345 snd_pcm_alt_chmaps, 8, 0, &chmap); 2380 snd_pcm_alt_chmaps, 8, 0, &chmap);
2346 if (err < 0) 2381 if (err < 0)
@@ -2395,6 +2430,7 @@ static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2395 struct snd_pcm_substream *substream) 2430 struct snd_pcm_substream *substream)
2396{ 2431{
2397 struct hdmi_spec *spec = codec->spec; 2432 struct hdmi_spec *spec = codec->spec;
2433 struct hdmi_spec_per_cvt *per_cvt = get_cvt(spec, 0);
2398 int chans = substream->runtime->channels; 2434 int chans = substream->runtime->channels;
2399 int i, err; 2435 int i, err;
2400 2436
@@ -2402,11 +2438,11 @@ static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2402 substream); 2438 substream);
2403 if (err < 0) 2439 if (err < 0)
2404 return err; 2440 return err;
2405 snd_hda_codec_write(codec, spec->cvts[0].cvt_nid, 0, 2441 snd_hda_codec_write(codec, per_cvt->cvt_nid, 0,
2406 AC_VERB_SET_CVT_CHAN_COUNT, chans - 1); 2442 AC_VERB_SET_CVT_CHAN_COUNT, chans - 1);
2407 /* FIXME: XXX */ 2443 /* FIXME: XXX */
2408 for (i = 0; i < chans; i++) { 2444 for (i = 0; i < chans; i++) {
2409 snd_hda_codec_write(codec, spec->cvts[0].cvt_nid, 0, 2445 snd_hda_codec_write(codec, per_cvt->cvt_nid, 0,
2410 AC_VERB_SET_HDMI_CHAN_SLOT, 2446 AC_VERB_SET_HDMI_CHAN_SLOT,
2411 (i << 4) | i); 2447 (i << 4) | i);
2412 } 2448 }
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index f15c36bde540..74bf5f6595b9 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -34,7 +34,6 @@
34#include "hda_codec.h" 34#include "hda_codec.h"
35#include "hda_local.h" 35#include "hda_local.h"
36#include "hda_auto_parser.h" 36#include "hda_auto_parser.h"
37#include "hda_beep.h"
38#include "hda_jack.h" 37#include "hda_jack.h"
39#include "hda_generic.h" 38#include "hda_generic.h"
40 39
@@ -53,6 +52,20 @@ enum {
53 ALC_INIT_GPIO3, 52 ALC_INIT_GPIO3,
54}; 53};
55 54
55enum {
56 ALC_HEADSET_MODE_UNKNOWN,
57 ALC_HEADSET_MODE_UNPLUGGED,
58 ALC_HEADSET_MODE_HEADSET,
59 ALC_HEADSET_MODE_MIC,
60 ALC_HEADSET_MODE_HEADPHONE,
61};
62
63enum {
64 ALC_HEADSET_TYPE_UNKNOWN,
65 ALC_HEADSET_TYPE_CTIA,
66 ALC_HEADSET_TYPE_OMTP,
67};
68
56struct alc_customize_define { 69struct alc_customize_define {
57 unsigned int sku_cfg; 70 unsigned int sku_cfg;
58 unsigned char port_connectivity; 71 unsigned char port_connectivity;
@@ -86,6 +99,13 @@ struct alc_spec {
86 int mute_led_polarity; 99 int mute_led_polarity;
87 hda_nid_t mute_led_nid; 100 hda_nid_t mute_led_nid;
88 101
102 unsigned int gpio_led; /* used for alc269_fixup_hp_gpio_led() */
103
104 hda_nid_t headset_mic_pin;
105 hda_nid_t headphone_mic_pin;
106 int current_headset_mode;
107 int current_headset_type;
108
89 /* hooks */ 109 /* hooks */
90 void (*init_hook)(struct hda_codec *codec); 110 void (*init_hook)(struct hda_codec *codec);
91#ifdef CONFIG_PM 111#ifdef CONFIG_PM
@@ -805,17 +825,7 @@ static inline void alc_shutup(struct hda_codec *codec)
805 snd_hda_shutup_pins(codec); 825 snd_hda_shutup_pins(codec);
806} 826}
807 827
808static void alc_free(struct hda_codec *codec) 828#define alc_free snd_hda_gen_free
809{
810 struct alc_spec *spec = codec->spec;
811
812 if (!spec)
813 return;
814
815 snd_hda_gen_spec_free(&spec->gen);
816 snd_hda_detach_beep_device(codec);
817 kfree(spec);
818}
819 829
820#ifdef CONFIG_PM 830#ifdef CONFIG_PM
821static void alc_power_eapd(struct hda_codec *codec) 831static void alc_power_eapd(struct hda_codec *codec)
@@ -1401,6 +1411,7 @@ static int patch_alc880(struct hda_codec *codec)
1401 1411
1402 spec = codec->spec; 1412 spec = codec->spec;
1403 spec->gen.need_dac_fix = 1; 1413 spec->gen.need_dac_fix = 1;
1414 spec->gen.beep_nid = 0x01;
1404 1415
1405 snd_hda_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl, 1416 snd_hda_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
1406 alc880_fixups); 1417 alc880_fixups);
@@ -1411,12 +1422,8 @@ static int patch_alc880(struct hda_codec *codec)
1411 if (err < 0) 1422 if (err < 0)
1412 goto error; 1423 goto error;
1413 1424
1414 if (!spec->gen.no_analog) { 1425 if (!spec->gen.no_analog)
1415 err = snd_hda_attach_beep_device(codec, 0x1);
1416 if (err < 0)
1417 goto error;
1418 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 1426 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
1419 }
1420 1427
1421 codec->patch_ops = alc_patch_ops; 1428 codec->patch_ops = alc_patch_ops;
1422 codec->patch_ops.unsol_event = alc880_unsol_event; 1429 codec->patch_ops.unsol_event = alc880_unsol_event;
@@ -1455,6 +1462,7 @@ enum {
1455 ALC260_FIXUP_HP_B1900, 1462 ALC260_FIXUP_HP_B1900,
1456 ALC260_FIXUP_KN1, 1463 ALC260_FIXUP_KN1,
1457 ALC260_FIXUP_FSC_S7020, 1464 ALC260_FIXUP_FSC_S7020,
1465 ALC260_FIXUP_FSC_S7020_JWSE,
1458}; 1466};
1459 1467
1460static void alc260_gpio1_automute(struct hda_codec *codec) 1468static void alc260_gpio1_automute(struct hda_codec *codec)
@@ -1516,14 +1524,17 @@ static void alc260_fixup_fsc_s7020(struct hda_codec *codec,
1516 const struct hda_fixup *fix, int action) 1524 const struct hda_fixup *fix, int action)
1517{ 1525{
1518 struct alc_spec *spec = codec->spec; 1526 struct alc_spec *spec = codec->spec;
1519 1527 if (action == HDA_FIXUP_ACT_PROBE)
1520 switch (action) {
1521 case HDA_FIXUP_ACT_PRE_PROBE:
1522 spec->gen.add_out_jack_modes = 1;
1523 break;
1524 case HDA_FIXUP_ACT_PROBE:
1525 spec->init_amp = ALC_INIT_NONE; 1528 spec->init_amp = ALC_INIT_NONE;
1526 break; 1529}
1530
1531static void alc260_fixup_fsc_s7020_jwse(struct hda_codec *codec,
1532 const struct hda_fixup *fix, int action)
1533{
1534 struct alc_spec *spec = codec->spec;
1535 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1536 spec->gen.add_jack_modes = 1;
1537 spec->gen.hp_mic = 1;
1527 } 1538 }
1528} 1539}
1529 1540
@@ -1586,6 +1597,12 @@ static const struct hda_fixup alc260_fixups[] = {
1586 .type = HDA_FIXUP_FUNC, 1597 .type = HDA_FIXUP_FUNC,
1587 .v.func = alc260_fixup_fsc_s7020, 1598 .v.func = alc260_fixup_fsc_s7020,
1588 }, 1599 },
1600 [ALC260_FIXUP_FSC_S7020_JWSE] = {
1601 .type = HDA_FIXUP_FUNC,
1602 .v.func = alc260_fixup_fsc_s7020_jwse,
1603 .chained = true,
1604 .chain_id = ALC260_FIXUP_FSC_S7020,
1605 },
1589}; 1606};
1590 1607
1591static const struct snd_pci_quirk alc260_fixup_tbl[] = { 1608static const struct snd_pci_quirk alc260_fixup_tbl[] = {
@@ -1602,6 +1619,14 @@ static const struct snd_pci_quirk alc260_fixup_tbl[] = {
1602 {} 1619 {}
1603}; 1620};
1604 1621
1622static const struct hda_model_fixup alc260_fixup_models[] = {
1623 {.id = ALC260_FIXUP_GPIO1, .name = "gpio1"},
1624 {.id = ALC260_FIXUP_COEF, .name = "coef"},
1625 {.id = ALC260_FIXUP_FSC_S7020, .name = "fujitsu"},
1626 {.id = ALC260_FIXUP_FSC_S7020_JWSE, .name = "fujitsu-jwse"},
1627 {}
1628};
1629
1605/* 1630/*
1606 */ 1631 */
1607static int patch_alc260(struct hda_codec *codec) 1632static int patch_alc260(struct hda_codec *codec)
@@ -1619,8 +1644,10 @@ static int patch_alc260(struct hda_codec *codec)
1619 * it's almost harmless. 1644 * it's almost harmless.
1620 */ 1645 */
1621 spec->gen.prefer_hp_amp = 1; 1646 spec->gen.prefer_hp_amp = 1;
1647 spec->gen.beep_nid = 0x01;
1622 1648
1623 snd_hda_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); 1649 snd_hda_pick_fixup(codec, alc260_fixup_models, alc260_fixup_tbl,
1650 alc260_fixups);
1624 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 1651 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1625 1652
1626 /* automatic parse from the BIOS config */ 1653 /* automatic parse from the BIOS config */
@@ -1628,12 +1655,8 @@ static int patch_alc260(struct hda_codec *codec)
1628 if (err < 0) 1655 if (err < 0)
1629 goto error; 1656 goto error;
1630 1657
1631 if (!spec->gen.no_analog) { 1658 if (!spec->gen.no_analog)
1632 err = snd_hda_attach_beep_device(codec, 0x1);
1633 if (err < 0)
1634 goto error;
1635 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT); 1659 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
1636 }
1637 1660
1638 codec->patch_ops = alc_patch_ops; 1661 codec->patch_ops = alc_patch_ops;
1639 spec->shutup = alc_eapd_shutup; 1662 spec->shutup = alc_eapd_shutup;
@@ -2132,17 +2155,16 @@ static int patch_alc882(struct hda_codec *codec)
2132 2155
2133 alc_auto_parse_customize_define(codec); 2156 alc_auto_parse_customize_define(codec);
2134 2157
2158 if (has_cdefine_beep(codec))
2159 spec->gen.beep_nid = 0x01;
2160
2135 /* automatic parse from the BIOS config */ 2161 /* automatic parse from the BIOS config */
2136 err = alc882_parse_auto_config(codec); 2162 err = alc882_parse_auto_config(codec);
2137 if (err < 0) 2163 if (err < 0)
2138 goto error; 2164 goto error;
2139 2165
2140 if (!spec->gen.no_analog && has_cdefine_beep(codec)) { 2166 if (!spec->gen.no_analog && spec->gen.beep_nid)
2141 err = snd_hda_attach_beep_device(codec, 0x1);
2142 if (err < 0)
2143 goto error;
2144 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 2167 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
2145 }
2146 2168
2147 codec->patch_ops = alc_patch_ops; 2169 codec->patch_ops = alc_patch_ops;
2148 2170
@@ -2295,17 +2317,16 @@ static int patch_alc262(struct hda_codec *codec)
2295 2317
2296 alc_auto_parse_customize_define(codec); 2318 alc_auto_parse_customize_define(codec);
2297 2319
2320 if (has_cdefine_beep(codec))
2321 spec->gen.beep_nid = 0x01;
2322
2298 /* automatic parse from the BIOS config */ 2323 /* automatic parse from the BIOS config */
2299 err = alc262_parse_auto_config(codec); 2324 err = alc262_parse_auto_config(codec);
2300 if (err < 0) 2325 if (err < 0)
2301 goto error; 2326 goto error;
2302 2327
2303 if (!spec->gen.no_analog && has_cdefine_beep(codec)) { 2328 if (!spec->gen.no_analog && spec->gen.beep_nid)
2304 err = snd_hda_attach_beep_device(codec, 0x1);
2305 if (err < 0)
2306 goto error;
2307 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 2329 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
2308 }
2309 2330
2310 codec->patch_ops = alc_patch_ops; 2331 codec->patch_ops = alc_patch_ops;
2311 spec->shutup = alc_eapd_shutup; 2332 spec->shutup = alc_eapd_shutup;
@@ -2386,16 +2407,7 @@ static const struct snd_pci_quirk alc268_fixup_tbl[] = {
2386static int alc268_parse_auto_config(struct hda_codec *codec) 2407static int alc268_parse_auto_config(struct hda_codec *codec)
2387{ 2408{
2388 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 }; 2409 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2389 struct alc_spec *spec = codec->spec; 2410 return alc_parse_auto_config(codec, NULL, alc268_ssids);
2390 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
2391 if (err > 0) {
2392 if (!spec->gen.no_analog &&
2393 spec->gen.autocfg.speaker_pins[0] != 0x1d) {
2394 add_mixer(spec, alc268_beep_mixer);
2395 snd_hda_add_verbs(codec, alc268_beep_init_verbs);
2396 }
2397 }
2398 return err;
2399} 2411}
2400 2412
2401/* 2413/*
@@ -2403,7 +2415,7 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
2403static int patch_alc268(struct hda_codec *codec) 2415static int patch_alc268(struct hda_codec *codec)
2404{ 2416{
2405 struct alc_spec *spec; 2417 struct alc_spec *spec;
2406 int i, has_beep, err; 2418 int err;
2407 2419
2408 /* ALC268 has no aa-loopback mixer */ 2420 /* ALC268 has no aa-loopback mixer */
2409 err = alc_alloc_spec(codec, 0); 2421 err = alc_alloc_spec(codec, 0);
@@ -2411,6 +2423,7 @@ static int patch_alc268(struct hda_codec *codec)
2411 return err; 2423 return err;
2412 2424
2413 spec = codec->spec; 2425 spec = codec->spec;
2426 spec->gen.beep_nid = 0x01;
2414 2427
2415 snd_hda_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups); 2428 snd_hda_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
2416 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 2429 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
@@ -2420,18 +2433,10 @@ static int patch_alc268(struct hda_codec *codec)
2420 if (err < 0) 2433 if (err < 0)
2421 goto error; 2434 goto error;
2422 2435
2423 has_beep = 0; 2436 if (err > 0 && !spec->gen.no_analog &&
2424 for (i = 0; i < spec->num_mixers; i++) { 2437 spec->gen.autocfg.speaker_pins[0] != 0x1d) {
2425 if (spec->mixers[i] == alc268_beep_mixer) { 2438 add_mixer(spec, alc268_beep_mixer);
2426 has_beep = 1; 2439 snd_hda_add_verbs(codec, alc268_beep_init_verbs);
2427 break;
2428 }
2429 }
2430
2431 if (has_beep) {
2432 err = snd_hda_attach_beep_device(codec, 0x1);
2433 if (err < 0)
2434 goto error;
2435 if (!query_amp_caps(codec, 0x1d, HDA_INPUT)) 2440 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
2436 /* override the amp caps for beep generator */ 2441 /* override the amp caps for beep generator */
2437 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT, 2442 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
@@ -2631,7 +2636,8 @@ static void alc271_fixup_dmic(struct hda_codec *codec,
2631 }; 2636 };
2632 unsigned int cfg; 2637 unsigned int cfg;
2633 2638
2634 if (strcmp(codec->chip_name, "ALC271X")) 2639 if (strcmp(codec->chip_name, "ALC271X") &&
2640 strcmp(codec->chip_name, "ALC269VB"))
2635 return; 2641 return;
2636 cfg = snd_hda_codec_get_pincfg(codec, 0x12); 2642 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
2637 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED) 2643 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
@@ -2693,6 +2699,34 @@ static void alc269_fixup_quanta_mute(struct hda_codec *codec,
2693 spec->gen.automute_hook = alc269_quanta_automute; 2699 spec->gen.automute_hook = alc269_quanta_automute;
2694} 2700}
2695 2701
2702static void alc269_x101_hp_automute_hook(struct hda_codec *codec,
2703 struct hda_jack_tbl *jack)
2704{
2705 struct alc_spec *spec = codec->spec;
2706 int vref;
2707 msleep(200);
2708 snd_hda_gen_hp_automute(codec, jack);
2709
2710 vref = spec->gen.hp_jack_present ? PIN_VREF80 : 0;
2711 msleep(100);
2712 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2713 vref);
2714 msleep(500);
2715 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2716 vref);
2717}
2718
2719static void alc269_fixup_x101_headset_mic(struct hda_codec *codec,
2720 const struct hda_fixup *fix, int action)
2721{
2722 struct alc_spec *spec = codec->spec;
2723 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2724 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
2725 spec->gen.hp_automute_hook = alc269_x101_hp_automute_hook;
2726 }
2727}
2728
2729
2696/* update mute-LED according to the speaker mute state via mic VREF pin */ 2730/* update mute-LED according to the speaker mute state via mic VREF pin */
2697static void alc269_fixup_mic_mute_hook(void *private_data, int enabled) 2731static void alc269_fixup_mic_mute_hook(void *private_data, int enabled)
2698{ 2732{
@@ -2757,6 +2791,356 @@ static void alc269_fixup_hp_mute_led_mic2(struct hda_codec *codec,
2757 } 2791 }
2758} 2792}
2759 2793
2794/* turn on/off mute LED per vmaster hook */
2795static void alc269_fixup_hp_gpio_mute_hook(void *private_data, int enabled)
2796{
2797 struct hda_codec *codec = private_data;
2798 struct alc_spec *spec = codec->spec;
2799 unsigned int oldval = spec->gpio_led;
2800
2801 if (enabled)
2802 spec->gpio_led &= ~0x08;
2803 else
2804 spec->gpio_led |= 0x08;
2805 if (spec->gpio_led != oldval)
2806 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
2807 spec->gpio_led);
2808}
2809
2810/* turn on/off mic-mute LED per capture hook */
2811static void alc269_fixup_hp_gpio_mic_mute_hook(struct hda_codec *codec,
2812 struct snd_ctl_elem_value *ucontrol)
2813{
2814 struct alc_spec *spec = codec->spec;
2815 unsigned int oldval = spec->gpio_led;
2816
2817 if (!ucontrol)
2818 return;
2819
2820 if (ucontrol->value.integer.value[0] ||
2821 ucontrol->value.integer.value[1])
2822 spec->gpio_led &= ~0x10;
2823 else
2824 spec->gpio_led |= 0x10;
2825 if (spec->gpio_led != oldval)
2826 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
2827 spec->gpio_led);
2828}
2829
2830static void alc269_fixup_hp_gpio_led(struct hda_codec *codec,
2831 const struct hda_fixup *fix, int action)
2832{
2833 struct alc_spec *spec = codec->spec;
2834 static const struct hda_verb gpio_init[] = {
2835 { 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
2836 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
2837 {}
2838 };
2839
2840 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2841 spec->gen.vmaster_mute.hook = alc269_fixup_hp_gpio_mute_hook;
2842 spec->gen.cap_sync_hook = alc269_fixup_hp_gpio_mic_mute_hook;
2843 spec->gpio_led = 0;
2844 snd_hda_add_verbs(codec, gpio_init);
2845 }
2846}
2847
2848static void alc_headset_mode_unplugged(struct hda_codec *codec)
2849{
2850 int val;
2851
2852 switch (codec->vendor_id) {
2853 case 0x10ec0283:
2854 alc_write_coef_idx(codec, 0x1b, 0x0c0b);
2855 alc_write_coef_idx(codec, 0x45, 0xc429);
2856 val = alc_read_coef_idx(codec, 0x35);
2857 alc_write_coef_idx(codec, 0x35, val & 0xbfff);
2858 alc_write_coef_idx(codec, 0x06, 0x2104);
2859 alc_write_coef_idx(codec, 0x1a, 0x0001);
2860 alc_write_coef_idx(codec, 0x26, 0x0004);
2861 alc_write_coef_idx(codec, 0x32, 0x42a3);
2862 break;
2863 case 0x10ec0292:
2864 alc_write_coef_idx(codec, 0x76, 0x000e);
2865 alc_write_coef_idx(codec, 0x6c, 0x2400);
2866 alc_write_coef_idx(codec, 0x18, 0x7308);
2867 alc_write_coef_idx(codec, 0x6b, 0xc429);
2868 break;
2869 case 0x10ec0668:
2870 alc_write_coef_idx(codec, 0x15, 0x0d40);
2871 alc_write_coef_idx(codec, 0xb7, 0x802b);
2872 break;
2873 }
2874 snd_printdd("Headset jack set to unplugged mode.\n");
2875}
2876
2877
2878static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
2879 hda_nid_t mic_pin)
2880{
2881 int val;
2882
2883 switch (codec->vendor_id) {
2884 case 0x10ec0283:
2885 alc_write_coef_idx(codec, 0x45, 0xc429);
2886 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
2887 val = alc_read_coef_idx(codec, 0x35);
2888 alc_write_coef_idx(codec, 0x35, val | 1<<14);
2889 alc_write_coef_idx(codec, 0x06, 0x2100);
2890 alc_write_coef_idx(codec, 0x1a, 0x0021);
2891 alc_write_coef_idx(codec, 0x26, 0x008c);
2892 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
2893 break;
2894 case 0x10ec0292:
2895 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
2896 alc_write_coef_idx(codec, 0x19, 0xa208);
2897 alc_write_coef_idx(codec, 0x2e, 0xacf0);
2898 break;
2899 case 0x10ec0668:
2900 alc_write_coef_idx(codec, 0x11, 0x0001);
2901 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
2902 alc_write_coef_idx(codec, 0xb7, 0x802b);
2903 alc_write_coef_idx(codec, 0xb5, 0x1040);
2904 val = alc_read_coef_idx(codec, 0xc3);
2905 alc_write_coef_idx(codec, 0xc3, val | 1<<12);
2906 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
2907 break;
2908 }
2909 snd_printdd("Headset jack set to mic-in mode.\n");
2910}
2911
2912static void alc_headset_mode_default(struct hda_codec *codec)
2913{
2914 switch (codec->vendor_id) {
2915 case 0x10ec0283:
2916 alc_write_coef_idx(codec, 0x06, 0x2100);
2917 alc_write_coef_idx(codec, 0x32, 0x4ea3);
2918 break;
2919 case 0x10ec0292:
2920 alc_write_coef_idx(codec, 0x76, 0x000e);
2921 alc_write_coef_idx(codec, 0x6c, 0x2400);
2922 alc_write_coef_idx(codec, 0x6b, 0xc429);
2923 alc_write_coef_idx(codec, 0x18, 0x7308);
2924 break;
2925 case 0x10ec0668:
2926 alc_write_coef_idx(codec, 0x11, 0x0041);
2927 alc_write_coef_idx(codec, 0x15, 0x0d40);
2928 alc_write_coef_idx(codec, 0xb7, 0x802b);
2929 break;
2930 }
2931 snd_printdd("Headset jack set to headphone (default) mode.\n");
2932}
2933
2934/* Iphone type */
2935static void alc_headset_mode_ctia(struct hda_codec *codec)
2936{
2937 switch (codec->vendor_id) {
2938 case 0x10ec0283:
2939 alc_write_coef_idx(codec, 0x45, 0xd429);
2940 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
2941 alc_write_coef_idx(codec, 0x32, 0x4ea3);
2942 break;
2943 case 0x10ec0292:
2944 alc_write_coef_idx(codec, 0x6b, 0xd429);
2945 alc_write_coef_idx(codec, 0x76, 0x0008);
2946 alc_write_coef_idx(codec, 0x18, 0x7388);
2947 break;
2948 case 0x10ec0668:
2949 alc_write_coef_idx(codec, 0x15, 0x0d60);
2950 alc_write_coef_idx(codec, 0xc3, 0x0000);
2951 break;
2952 }
2953 snd_printdd("Headset jack set to iPhone-style headset mode.\n");
2954}
2955
2956/* Nokia type */
2957static void alc_headset_mode_omtp(struct hda_codec *codec)
2958{
2959 switch (codec->vendor_id) {
2960 case 0x10ec0283:
2961 alc_write_coef_idx(codec, 0x45, 0xe429);
2962 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
2963 alc_write_coef_idx(codec, 0x32, 0x4ea3);
2964 break;
2965 case 0x10ec0292:
2966 alc_write_coef_idx(codec, 0x6b, 0xe429);
2967 alc_write_coef_idx(codec, 0x76, 0x0008);
2968 alc_write_coef_idx(codec, 0x18, 0x7388);
2969 break;
2970 case 0x10ec0668:
2971 alc_write_coef_idx(codec, 0x15, 0x0d50);
2972 alc_write_coef_idx(codec, 0xc3, 0x0000);
2973 break;
2974 }
2975 snd_printdd("Headset jack set to Nokia-style headset mode.\n");
2976}
2977
2978static void alc_determine_headset_type(struct hda_codec *codec)
2979{
2980 int val;
2981 bool is_ctia = false;
2982 struct alc_spec *spec = codec->spec;
2983
2984 switch (codec->vendor_id) {
2985 case 0x10ec0283:
2986 alc_write_coef_idx(codec, 0x45, 0xd029);
2987 msleep(300);
2988 val = alc_read_coef_idx(codec, 0x46);
2989 is_ctia = (val & 0x0070) == 0x0070;
2990 break;
2991 case 0x10ec0292:
2992 alc_write_coef_idx(codec, 0x6b, 0xd429);
2993 msleep(300);
2994 val = alc_read_coef_idx(codec, 0x6c);
2995 is_ctia = (val & 0x001c) == 0x001c;
2996 break;
2997 case 0x10ec0668:
2998 alc_write_coef_idx(codec, 0x11, 0x0001);
2999 alc_write_coef_idx(codec, 0xb7, 0x802b);
3000 alc_write_coef_idx(codec, 0x15, 0x0d60);
3001 alc_write_coef_idx(codec, 0xc3, 0x0c00);
3002 msleep(300);
3003 val = alc_read_coef_idx(codec, 0xbe);
3004 is_ctia = (val & 0x1c02) == 0x1c02;
3005 break;
3006 }
3007
3008 snd_printdd("Headset jack detected iPhone-style headset: %s\n",
3009 is_ctia ? "yes" : "no");
3010 spec->current_headset_type = is_ctia ? ALC_HEADSET_TYPE_CTIA : ALC_HEADSET_TYPE_OMTP;
3011}
3012
3013static void alc_update_headset_mode(struct hda_codec *codec)
3014{
3015 struct alc_spec *spec = codec->spec;
3016
3017 hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
3018 hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3019
3020 int new_headset_mode;
3021
3022 if (!snd_hda_jack_detect(codec, hp_pin))
3023 new_headset_mode = ALC_HEADSET_MODE_UNPLUGGED;
3024 else if (mux_pin == spec->headset_mic_pin)
3025 new_headset_mode = ALC_HEADSET_MODE_HEADSET;
3026 else if (mux_pin == spec->headphone_mic_pin)
3027 new_headset_mode = ALC_HEADSET_MODE_MIC;
3028 else
3029 new_headset_mode = ALC_HEADSET_MODE_HEADPHONE;
3030
3031 if (new_headset_mode == spec->current_headset_mode)
3032 return;
3033
3034 switch (new_headset_mode) {
3035 case ALC_HEADSET_MODE_UNPLUGGED:
3036 alc_headset_mode_unplugged(codec);
3037 spec->gen.hp_jack_present = false;
3038 break;
3039 case ALC_HEADSET_MODE_HEADSET:
3040 if (spec->current_headset_type == ALC_HEADSET_TYPE_UNKNOWN)
3041 alc_determine_headset_type(codec);
3042 if (spec->current_headset_type == ALC_HEADSET_TYPE_CTIA)
3043 alc_headset_mode_ctia(codec);
3044 else if (spec->current_headset_type == ALC_HEADSET_TYPE_OMTP)
3045 alc_headset_mode_omtp(codec);
3046 spec->gen.hp_jack_present = true;
3047 break;
3048 case ALC_HEADSET_MODE_MIC:
3049 alc_headset_mode_mic_in(codec, hp_pin, spec->headphone_mic_pin);
3050 spec->gen.hp_jack_present = false;
3051 break;
3052 case ALC_HEADSET_MODE_HEADPHONE:
3053 alc_headset_mode_default(codec);
3054 spec->gen.hp_jack_present = true;
3055 break;
3056 }
3057 if (new_headset_mode != ALC_HEADSET_MODE_MIC) {
3058 snd_hda_set_pin_ctl_cache(codec, hp_pin,
3059 AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3060 if (spec->headphone_mic_pin)
3061 snd_hda_set_pin_ctl_cache(codec, spec->headphone_mic_pin,
3062 PIN_VREFHIZ);
3063 }
3064 spec->current_headset_mode = new_headset_mode;
3065
3066 snd_hda_gen_update_outputs(codec);
3067}
3068
3069static void alc_update_headset_mode_hook(struct hda_codec *codec,
3070 struct snd_ctl_elem_value *ucontrol)
3071{
3072 alc_update_headset_mode(codec);
3073}
3074
3075static void alc_update_headset_jack_cb(struct hda_codec *codec, struct hda_jack_tbl *jack)
3076{
3077 struct alc_spec *spec = codec->spec;
3078 spec->current_headset_type = ALC_HEADSET_MODE_UNKNOWN;
3079 snd_hda_gen_hp_automute(codec, jack);
3080}
3081
3082static void alc_probe_headset_mode(struct hda_codec *codec)
3083{
3084 int i;
3085 struct alc_spec *spec = codec->spec;
3086 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
3087
3088 /* Find mic pins */
3089 for (i = 0; i < cfg->num_inputs; i++) {
3090 if (cfg->inputs[i].is_headset_mic && !spec->headset_mic_pin)
3091 spec->headset_mic_pin = cfg->inputs[i].pin;
3092 if (cfg->inputs[i].is_headphone_mic && !spec->headphone_mic_pin)
3093 spec->headphone_mic_pin = cfg->inputs[i].pin;
3094 }
3095
3096 spec->gen.cap_sync_hook = alc_update_headset_mode_hook;
3097 spec->gen.automute_hook = alc_update_headset_mode;
3098 spec->gen.hp_automute_hook = alc_update_headset_jack_cb;
3099}
3100
3101static void alc_fixup_headset_mode(struct hda_codec *codec,
3102 const struct hda_fixup *fix, int action)
3103{
3104 struct alc_spec *spec = codec->spec;
3105
3106 switch (action) {
3107 case HDA_FIXUP_ACT_PRE_PROBE:
3108 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC | HDA_PINCFG_HEADPHONE_MIC;
3109 break;
3110 case HDA_FIXUP_ACT_PROBE:
3111 alc_probe_headset_mode(codec);
3112 break;
3113 case HDA_FIXUP_ACT_INIT:
3114 spec->current_headset_mode = 0;
3115 alc_update_headset_mode(codec);
3116 break;
3117 }
3118}
3119
3120static void alc_fixup_headset_mode_no_hp_mic(struct hda_codec *codec,
3121 const struct hda_fixup *fix, int action)
3122{
3123 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3124 struct alc_spec *spec = codec->spec;
3125 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
3126 }
3127 else
3128 alc_fixup_headset_mode(codec, fix, action);
3129}
3130
3131static void alc_fixup_headset_mode_alc668(struct hda_codec *codec,
3132 const struct hda_fixup *fix, int action)
3133{
3134 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3135 int val;
3136 alc_write_coef_idx(codec, 0xc4, 0x8000);
3137 val = alc_read_coef_idx(codec, 0xc2);
3138 alc_write_coef_idx(codec, 0xc2, val & 0xfe);
3139 snd_hda_set_pin_ctl_cache(codec, 0x18, 0);
3140 }
3141 alc_fixup_headset_mode(codec, fix, action);
3142}
3143
2760static void alc271_hp_gate_mic_jack(struct hda_codec *codec, 3144static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
2761 const struct hda_fixup *fix, 3145 const struct hda_fixup *fix,
2762 int action) 3146 int action)
@@ -2792,11 +3176,20 @@ enum {
2792 ALC269_FIXUP_HP_MUTE_LED, 3176 ALC269_FIXUP_HP_MUTE_LED,
2793 ALC269_FIXUP_HP_MUTE_LED_MIC1, 3177 ALC269_FIXUP_HP_MUTE_LED_MIC1,
2794 ALC269_FIXUP_HP_MUTE_LED_MIC2, 3178 ALC269_FIXUP_HP_MUTE_LED_MIC2,
3179 ALC269_FIXUP_HP_GPIO_LED,
2795 ALC269_FIXUP_INV_DMIC, 3180 ALC269_FIXUP_INV_DMIC,
2796 ALC269_FIXUP_LENOVO_DOCK, 3181 ALC269_FIXUP_LENOVO_DOCK,
2797 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT, 3182 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
3183 ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
3184 ALC269_FIXUP_DELL2_MIC_NO_PRESENCE,
3185 ALC269_FIXUP_HEADSET_MODE,
3186 ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC,
3187 ALC269_FIXUP_ASUS_X101_FUNC,
3188 ALC269_FIXUP_ASUS_X101_VERB,
3189 ALC269_FIXUP_ASUS_X101,
2798 ALC271_FIXUP_AMIC_MIC2, 3190 ALC271_FIXUP_AMIC_MIC2,
2799 ALC271_FIXUP_HP_GATE_MIC_JACK, 3191 ALC271_FIXUP_HP_GATE_MIC_JACK,
3192 ALC269_FIXUP_ACER_AC700,
2800}; 3193};
2801 3194
2802static const struct hda_fixup alc269_fixups[] = { 3195static const struct hda_fixup alc269_fixups[] = {
@@ -2931,6 +3324,10 @@ static const struct hda_fixup alc269_fixups[] = {
2931 .type = HDA_FIXUP_FUNC, 3324 .type = HDA_FIXUP_FUNC,
2932 .v.func = alc269_fixup_hp_mute_led_mic2, 3325 .v.func = alc269_fixup_hp_mute_led_mic2,
2933 }, 3326 },
3327 [ALC269_FIXUP_HP_GPIO_LED] = {
3328 .type = HDA_FIXUP_FUNC,
3329 .v.func = alc269_fixup_hp_gpio_led,
3330 },
2934 [ALC269_FIXUP_INV_DMIC] = { 3331 [ALC269_FIXUP_INV_DMIC] = {
2935 .type = HDA_FIXUP_FUNC, 3332 .type = HDA_FIXUP_FUNC,
2936 .v.func = alc_fixup_inv_dmic_0x12, 3333 .v.func = alc_fixup_inv_dmic_0x12,
@@ -2949,6 +3346,59 @@ static const struct hda_fixup alc269_fixups[] = {
2949 .type = HDA_FIXUP_FUNC, 3346 .type = HDA_FIXUP_FUNC,
2950 .v.func = alc269_fixup_pincfg_no_hp_to_lineout, 3347 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
2951 }, 3348 },
3349 [ALC269_FIXUP_DELL1_MIC_NO_PRESENCE] = {
3350 .type = HDA_FIXUP_PINS,
3351 .v.pins = (const struct hda_pintbl[]) {
3352 { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
3353 { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
3354 { }
3355 },
3356 .chained = true,
3357 .chain_id = ALC269_FIXUP_HEADSET_MODE
3358 },
3359 [ALC269_FIXUP_DELL2_MIC_NO_PRESENCE] = {
3360 .type = HDA_FIXUP_PINS,
3361 .v.pins = (const struct hda_pintbl[]) {
3362 { 0x16, 0x21014020 }, /* dock line out */
3363 { 0x19, 0x21a19030 }, /* dock mic */
3364 { 0x1a, 0x01a1913c }, /* use as headset mic, without its own jack detect */
3365 { }
3366 },
3367 .chained = true,
3368 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
3369 },
3370 [ALC269_FIXUP_HEADSET_MODE] = {
3371 .type = HDA_FIXUP_FUNC,
3372 .v.func = alc_fixup_headset_mode,
3373 },
3374 [ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC] = {
3375 .type = HDA_FIXUP_FUNC,
3376 .v.func = alc_fixup_headset_mode_no_hp_mic,
3377 },
3378 [ALC269_FIXUP_ASUS_X101_FUNC] = {
3379 .type = HDA_FIXUP_FUNC,
3380 .v.func = alc269_fixup_x101_headset_mic,
3381 },
3382 [ALC269_FIXUP_ASUS_X101_VERB] = {
3383 .type = HDA_FIXUP_VERBS,
3384 .v.verbs = (const struct hda_verb[]) {
3385 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3386 {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
3387 {0x20, AC_VERB_SET_PROC_COEF, 0x0310},
3388 { }
3389 },
3390 .chained = true,
3391 .chain_id = ALC269_FIXUP_ASUS_X101_FUNC
3392 },
3393 [ALC269_FIXUP_ASUS_X101] = {
3394 .type = HDA_FIXUP_PINS,
3395 .v.pins = (const struct hda_pintbl[]) {
3396 { 0x18, 0x04a1182c }, /* Headset mic */
3397 { }
3398 },
3399 .chained = true,
3400 .chain_id = ALC269_FIXUP_ASUS_X101_VERB
3401 },
2952 [ALC271_FIXUP_AMIC_MIC2] = { 3402 [ALC271_FIXUP_AMIC_MIC2] = {
2953 .type = HDA_FIXUP_PINS, 3403 .type = HDA_FIXUP_PINS,
2954 .v.pins = (const struct hda_pintbl[]) { 3404 .v.pins = (const struct hda_pintbl[]) {
@@ -2965,12 +3415,46 @@ static const struct hda_fixup alc269_fixups[] = {
2965 .chained = true, 3415 .chained = true,
2966 .chain_id = ALC271_FIXUP_AMIC_MIC2, 3416 .chain_id = ALC271_FIXUP_AMIC_MIC2,
2967 }, 3417 },
3418 [ALC269_FIXUP_ACER_AC700] = {
3419 .type = HDA_FIXUP_PINS,
3420 .v.pins = (const struct hda_pintbl[]) {
3421 { 0x12, 0x99a3092f }, /* int-mic */
3422 { 0x14, 0x99130110 }, /* speaker */
3423 { 0x18, 0x03a11c20 }, /* mic */
3424 { 0x1e, 0x0346101e }, /* SPDIF1 */
3425 { 0x21, 0x0321101f }, /* HP out */
3426 { }
3427 },
3428 .chained = true,
3429 .chain_id = ALC271_FIXUP_DMIC,
3430 },
2968}; 3431};
2969 3432
2970static const struct snd_pci_quirk alc269_fixup_tbl[] = { 3433static const struct snd_pci_quirk alc269_fixup_tbl[] = {
2971 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC), 3434 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
2972 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC), 3435 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
3436 SND_PCI_QUIRK(0x1028, 0x05bd, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3437 SND_PCI_QUIRK(0x1028, 0x05be, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3438 SND_PCI_QUIRK(0x1028, 0x05c4, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3439 SND_PCI_QUIRK(0x1028, 0x05c5, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3440 SND_PCI_QUIRK(0x1028, 0x05c6, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3441 SND_PCI_QUIRK(0x1028, 0x05c7, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3442 SND_PCI_QUIRK(0x1028, 0x05c8, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3443 SND_PCI_QUIRK(0x1028, 0x05c9, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3444 SND_PCI_QUIRK(0x1028, 0x05ca, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3445 SND_PCI_QUIRK(0x1028, 0x05cb, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3446 SND_PCI_QUIRK(0x1028, 0x05e9, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3447 SND_PCI_QUIRK(0x1028, 0x05ea, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3448 SND_PCI_QUIRK(0x1028, 0x05eb, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3449 SND_PCI_QUIRK(0x1028, 0x05ec, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3450 SND_PCI_QUIRK(0x1028, 0x05ed, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3451 SND_PCI_QUIRK(0x1028, 0x05ee, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3452 SND_PCI_QUIRK(0x1028, 0x05f3, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3453 SND_PCI_QUIRK(0x1028, 0x05f4, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3454 SND_PCI_QUIRK(0x1028, 0x05f5, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3455 SND_PCI_QUIRK(0x1028, 0x05f6, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
2973 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2), 3456 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
3457 SND_PCI_QUIRK(0x103c, 0x18e6, "HP", ALC269_FIXUP_HP_GPIO_LED),
2974 SND_PCI_QUIRK(0x103c, 0x1973, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1), 3458 SND_PCI_QUIRK(0x103c, 0x1973, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
2975 SND_PCI_QUIRK(0x103c, 0x1983, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1), 3459 SND_PCI_QUIRK(0x103c, 0x1983, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
2976 SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED), 3460 SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED),
@@ -2983,11 +3467,13 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
2983 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC), 3467 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
2984 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), 3468 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
2985 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), 3469 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
3470 SND_PCI_QUIRK(0x1043, 0x8516, "ASUS X101CH", ALC269_FIXUP_ASUS_X101),
2986 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2), 3471 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
2987 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), 3472 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
2988 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), 3473 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
2989 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO), 3474 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
2990 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), 3475 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
3476 SND_PCI_QUIRK(0x1025, 0x047c, "Acer AC700", ALC269_FIXUP_ACER_AC700),
2991 SND_PCI_QUIRK(0x1025, 0x0740, "Acer AO725", ALC271_FIXUP_HP_GATE_MIC_JACK), 3477 SND_PCI_QUIRK(0x1025, 0x0740, "Acer AO725", ALC271_FIXUP_HP_GATE_MIC_JACK),
2992 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK), 3478 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
2993 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC), 3479 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
@@ -3063,6 +3549,7 @@ static const struct hda_model_fixup alc269_fixup_models[] = {
3063 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"}, 3549 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
3064 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"}, 3550 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
3065 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"}, 3551 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
3552 {.id = ALC269_FIXUP_HP_GPIO_LED, .name = "hp-gpio-led"},
3066 {} 3553 {}
3067}; 3554};
3068 3555
@@ -3131,6 +3618,9 @@ static int patch_alc269(struct hda_codec *codec)
3131 3618
3132 alc_auto_parse_customize_define(codec); 3619 alc_auto_parse_customize_define(codec);
3133 3620
3621 if (has_cdefine_beep(codec))
3622 spec->gen.beep_nid = 0x01;
3623
3134 switch (codec->vendor_id) { 3624 switch (codec->vendor_id) {
3135 case 0x10ec0269: 3625 case 0x10ec0269:
3136 spec->codec_variant = ALC269_TYPE_ALC269VA; 3626 spec->codec_variant = ALC269_TYPE_ALC269VA;
@@ -3179,12 +3669,8 @@ static int patch_alc269(struct hda_codec *codec)
3179 if (err < 0) 3669 if (err < 0)
3180 goto error; 3670 goto error;
3181 3671
3182 if (!spec->gen.no_analog && has_cdefine_beep(codec)) { 3672 if (!spec->gen.no_analog && spec->gen.beep_nid)
3183 err = snd_hda_attach_beep_device(codec, 0x1);
3184 if (err < 0)
3185 goto error;
3186 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); 3673 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
3187 }
3188 3674
3189 codec->patch_ops = alc_patch_ops; 3675 codec->patch_ops = alc_patch_ops;
3190#ifdef CONFIG_PM 3676#ifdef CONFIG_PM
@@ -3292,6 +3778,7 @@ static int patch_alc861(struct hda_codec *codec)
3292 return err; 3778 return err;
3293 3779
3294 spec = codec->spec; 3780 spec = codec->spec;
3781 spec->gen.beep_nid = 0x23;
3295 3782
3296 snd_hda_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); 3783 snd_hda_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
3297 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 3784 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
@@ -3301,12 +3788,8 @@ static int patch_alc861(struct hda_codec *codec)
3301 if (err < 0) 3788 if (err < 0)
3302 goto error; 3789 goto error;
3303 3790
3304 if (!spec->gen.no_analog) { 3791 if (!spec->gen.no_analog)
3305 err = snd_hda_attach_beep_device(codec, 0x23);
3306 if (err < 0)
3307 goto error;
3308 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT); 3792 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
3309 }
3310 3793
3311 codec->patch_ops = alc_patch_ops; 3794 codec->patch_ops = alc_patch_ops;
3312#ifdef CONFIG_PM 3795#ifdef CONFIG_PM
@@ -3387,6 +3870,7 @@ static int patch_alc861vd(struct hda_codec *codec)
3387 return err; 3870 return err;
3388 3871
3389 spec = codec->spec; 3872 spec = codec->spec;
3873 spec->gen.beep_nid = 0x23;
3390 3874
3391 snd_hda_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); 3875 snd_hda_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
3392 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 3876 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
@@ -3396,12 +3880,8 @@ static int patch_alc861vd(struct hda_codec *codec)
3396 if (err < 0) 3880 if (err < 0)
3397 goto error; 3881 goto error;
3398 3882
3399 if (!spec->gen.no_analog) { 3883 if (!spec->gen.no_analog)
3400 err = snd_hda_attach_beep_device(codec, 0x23);
3401 if (err < 0)
3402 goto error;
3403 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 3884 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3404 }
3405 3885
3406 codec->patch_ops = alc_patch_ops; 3886 codec->patch_ops = alc_patch_ops;
3407 3887
@@ -3480,6 +3960,8 @@ enum {
3480 ALC662_FIXUP_NO_JACK_DETECT, 3960 ALC662_FIXUP_NO_JACK_DETECT,
3481 ALC662_FIXUP_ZOTAC_Z68, 3961 ALC662_FIXUP_ZOTAC_Z68,
3482 ALC662_FIXUP_INV_DMIC, 3962 ALC662_FIXUP_INV_DMIC,
3963 ALC668_FIXUP_DELL_MIC_NO_PRESENCE,
3964 ALC668_FIXUP_HEADSET_MODE,
3483}; 3965};
3484 3966
3485static const struct hda_fixup alc662_fixups[] = { 3967static const struct hda_fixup alc662_fixups[] = {
@@ -3640,6 +4122,20 @@ static const struct hda_fixup alc662_fixups[] = {
3640 .type = HDA_FIXUP_FUNC, 4122 .type = HDA_FIXUP_FUNC,
3641 .v.func = alc_fixup_inv_dmic_0x12, 4123 .v.func = alc_fixup_inv_dmic_0x12,
3642 }, 4124 },
4125 [ALC668_FIXUP_DELL_MIC_NO_PRESENCE] = {
4126 .type = HDA_FIXUP_PINS,
4127 .v.pins = (const struct hda_pintbl[]) {
4128 { 0x19, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
4129 { 0x1b, 0x03a1113c }, /* use as headset mic, without its own jack detect */
4130 { }
4131 },
4132 .chained = true,
4133 .chain_id = ALC668_FIXUP_HEADSET_MODE
4134 },
4135 [ALC668_FIXUP_HEADSET_MODE] = {
4136 .type = HDA_FIXUP_FUNC,
4137 .v.func = alc_fixup_headset_mode_alc668,
4138 },
3643}; 4139};
3644 4140
3645static const struct snd_pci_quirk alc662_fixup_tbl[] = { 4141static const struct snd_pci_quirk alc662_fixup_tbl[] = {
@@ -3648,6 +4144,8 @@ static const struct snd_pci_quirk alc662_fixup_tbl[] = {
3648 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE), 4144 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
3649 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC), 4145 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
3650 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), 4146 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
4147 SND_PCI_QUIRK(0x1028, 0x05d8, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
4148 SND_PCI_QUIRK(0x1028, 0x05db, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
3651 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), 4149 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
3652 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT), 4150 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
3653 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2), 4151 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
@@ -3784,6 +4282,9 @@ static int patch_alc662(struct hda_codec *codec)
3784 4282
3785 alc_auto_parse_customize_define(codec); 4283 alc_auto_parse_customize_define(codec);
3786 4284
4285 if (has_cdefine_beep(codec))
4286 spec->gen.beep_nid = 0x01;
4287
3787 if ((alc_get_coef0(codec) & (1 << 14)) && 4288 if ((alc_get_coef0(codec) & (1 << 14)) &&
3788 codec->bus->pci->subsystem_vendor == 0x1025 && 4289 codec->bus->pci->subsystem_vendor == 0x1025 &&
3789 spec->cdefine.platform_type == 1) { 4290 spec->cdefine.platform_type == 1) {
@@ -3796,10 +4297,7 @@ static int patch_alc662(struct hda_codec *codec)
3796 if (err < 0) 4297 if (err < 0)
3797 goto error; 4298 goto error;
3798 4299
3799 if (!spec->gen.no_analog && has_cdefine_beep(codec)) { 4300 if (!spec->gen.no_analog && spec->gen.beep_nid) {
3800 err = snd_hda_attach_beep_device(codec, 0x1);
3801 if (err < 0)
3802 goto error;
3803 switch (codec->vendor_id) { 4301 switch (codec->vendor_id) {
3804 case 0x10ec0662: 4302 case 0x10ec0662:
3805 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 4303 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index dafe04ae8c72..1d9d6427e0bf 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -211,7 +211,6 @@ struct sigmatel_spec {
211 211
212 /* beep widgets */ 212 /* beep widgets */
213 hda_nid_t anabeep_nid; 213 hda_nid_t anabeep_nid;
214 hda_nid_t digbeep_nid;
215 214
216 /* SPDIF-out mux */ 215 /* SPDIF-out mux */
217 const char * const *spdif_labels; 216 const char * const *spdif_labels;
@@ -3529,8 +3528,12 @@ static int stac_parse_auto_config(struct hda_codec *codec)
3529{ 3528{
3530 struct sigmatel_spec *spec = codec->spec; 3529 struct sigmatel_spec *spec = codec->spec;
3531 int err; 3530 int err;
3531 int flags = 0;
3532 3532
3533 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0); 3533 if (spec->headset_jack)
3534 flags |= HDA_PINCFG_HEADSET_MIC;
3535
3536 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, flags);
3534 if (err < 0) 3537 if (err < 0)
3535 return err; 3538 return err;
3536 3539
@@ -3560,16 +3563,13 @@ static int stac_parse_auto_config(struct hda_codec *codec)
3560 3563
3561 /* setup digital beep controls and input device */ 3564 /* setup digital beep controls and input device */
3562#ifdef CONFIG_SND_HDA_INPUT_BEEP 3565#ifdef CONFIG_SND_HDA_INPUT_BEEP
3563 if (spec->digbeep_nid > 0) { 3566 if (spec->gen.beep_nid) {
3564 hda_nid_t nid = spec->digbeep_nid; 3567 hda_nid_t nid = spec->gen.beep_nid;
3565 unsigned int caps; 3568 unsigned int caps;
3566 3569
3567 err = stac_auto_create_beep_ctls(codec, nid); 3570 err = stac_auto_create_beep_ctls(codec, nid);
3568 if (err < 0) 3571 if (err < 0)
3569 return err; 3572 return err;
3570 err = snd_hda_attach_beep_device(codec, nid);
3571 if (err < 0)
3572 return err;
3573 if (codec->beep) { 3573 if (codec->beep) {
3574 /* IDT/STAC codecs have linear beep tone parameter */ 3574 /* IDT/STAC codecs have linear beep tone parameter */
3575 codec->beep->linear_tone = spec->linear_tone_beep; 3575 codec->beep->linear_tone = spec->linear_tone_beep;
@@ -3657,17 +3657,7 @@ static void stac_shutup(struct hda_codec *codec)
3657 ~spec->eapd_mask); 3657 ~spec->eapd_mask);
3658} 3658}
3659 3659
3660static void stac_free(struct hda_codec *codec) 3660#define stac_free snd_hda_gen_free
3661{
3662 struct sigmatel_spec *spec = codec->spec;
3663
3664 if (!spec)
3665 return;
3666
3667 snd_hda_gen_spec_free(&spec->gen);
3668 kfree(spec);
3669 snd_hda_detach_beep_device(codec);
3670}
3671 3661
3672#ifdef CONFIG_PROC_FS 3662#ifdef CONFIG_PROC_FS
3673static void stac92hd_proc_hook(struct snd_info_buffer *buffer, 3663static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
@@ -3797,6 +3787,7 @@ static int patch_stac9200(struct hda_codec *codec)
3797 spec->gen.own_eapd_ctl = 1; 3787 spec->gen.own_eapd_ctl = 1;
3798 3788
3799 codec->patch_ops = stac_patch_ops; 3789 codec->patch_ops = stac_patch_ops;
3790 codec->power_filter = snd_hda_codec_eapd_power_filter;
3800 3791
3801 snd_hda_add_verbs(codec, stac9200_eapd_init); 3792 snd_hda_add_verbs(codec, stac9200_eapd_init);
3802 3793
@@ -3884,7 +3875,7 @@ static int patch_stac92hd73xx(struct hda_codec *codec)
3884 spec->aloopback_mask = 0x01; 3875 spec->aloopback_mask = 0x01;
3885 spec->aloopback_shift = 8; 3876 spec->aloopback_shift = 8;
3886 3877
3887 spec->digbeep_nid = 0x1c; 3878 spec->gen.beep_nid = 0x1c; /* digital beep */
3888 3879
3889 /* GPIO0 High = Enable EAPD */ 3880 /* GPIO0 High = Enable EAPD */
3890 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1; 3881 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
@@ -3968,7 +3959,7 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
3968 spec->gen.power_down_unused = 1; 3959 spec->gen.power_down_unused = 1;
3969 spec->gen.mixer_nid = 0x1b; 3960 spec->gen.mixer_nid = 0x1b;
3970 3961
3971 spec->digbeep_nid = 0x21; 3962 spec->gen.beep_nid = 0x21; /* digital beep */
3972 spec->pwr_nids = stac92hd83xxx_pwr_nids; 3963 spec->pwr_nids = stac92hd83xxx_pwr_nids;
3973 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids); 3964 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
3974 spec->default_polarity = -1; /* no default cfg */ 3965 spec->default_polarity = -1; /* no default cfg */
@@ -4016,7 +4007,7 @@ static int patch_stac92hd95(struct hda_codec *codec)
4016 spec->gen.own_eapd_ctl = 1; 4007 spec->gen.own_eapd_ctl = 1;
4017 spec->gen.power_down_unused = 1; 4008 spec->gen.power_down_unused = 1;
4018 4009
4019 spec->digbeep_nid = 0x19; 4010 spec->gen.beep_nid = 0x19; /* digital beep */
4020 spec->pwr_nids = stac92hd95_pwr_nids; 4011 spec->pwr_nids = stac92hd95_pwr_nids;
4021 spec->num_pwrs = ARRAY_SIZE(stac92hd95_pwr_nids); 4012 spec->num_pwrs = ARRAY_SIZE(stac92hd95_pwr_nids);
4022 spec->default_polarity = -1; /* no default cfg */ 4013 spec->default_polarity = -1; /* no default cfg */
@@ -4091,7 +4082,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
4091 spec->aloopback_shift = 0; 4082 spec->aloopback_shift = 0;
4092 4083
4093 spec->powerdown_adcs = 1; 4084 spec->powerdown_adcs = 1;
4094 spec->digbeep_nid = 0x26; 4085 spec->gen.beep_nid = 0x26; /* digital beep */
4095 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids); 4086 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
4096 spec->pwr_nids = stac92hd71bxx_pwr_nids; 4087 spec->pwr_nids = stac92hd71bxx_pwr_nids;
4097 4088
@@ -4173,7 +4164,7 @@ static int patch_stac927x(struct hda_codec *codec)
4173 spec->have_spdif_mux = 1; 4164 spec->have_spdif_mux = 1;
4174 spec->spdif_labels = stac927x_spdif_labels; 4165 spec->spdif_labels = stac927x_spdif_labels;
4175 4166
4176 spec->digbeep_nid = 0x23; 4167 spec->gen.beep_nid = 0x23; /* digital beep */
4177 4168
4178 /* GPIO0 High = Enable EAPD */ 4169 /* GPIO0 High = Enable EAPD */
4179 spec->eapd_mask = spec->gpio_mask = 0x01; 4170 spec->eapd_mask = spec->gpio_mask = 0x01;
@@ -4232,7 +4223,7 @@ static int patch_stac9205(struct hda_codec *codec)
4232 spec->gen.own_eapd_ctl = 1; 4223 spec->gen.own_eapd_ctl = 1;
4233 spec->have_spdif_mux = 1; 4224 spec->have_spdif_mux = 1;
4234 4225
4235 spec->digbeep_nid = 0x23; 4226 spec->gen.beep_nid = 0x23; /* digital beep */
4236 4227
4237 snd_hda_add_verbs(codec, stac9205_core_init); 4228 snd_hda_add_verbs(codec, stac9205_core_init);
4238 spec->aloopback_ctl = &stac9205_loopback; 4229 spec->aloopback_ctl = &stac9205_loopback;
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index c35338a8771d..e0dadcf2030d 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -626,11 +626,31 @@ static void via_set_jack_unsol_events(struct hda_codec *codec)
626 } 626 }
627} 627}
628 628
629static const struct badness_table via_main_out_badness = {
630 .no_primary_dac = 0x10000,
631 .no_dac = 0x4000,
632 .shared_primary = 0x10000,
633 .shared_surr = 0x20,
634 .shared_clfe = 0x20,
635 .shared_surr_main = 0x20,
636};
637static const struct badness_table via_extra_out_badness = {
638 .no_primary_dac = 0x4000,
639 .no_dac = 0x4000,
640 .shared_primary = 0x12,
641 .shared_surr = 0x20,
642 .shared_clfe = 0x20,
643 .shared_surr_main = 0x10,
644};
645
629static int via_parse_auto_config(struct hda_codec *codec) 646static int via_parse_auto_config(struct hda_codec *codec)
630{ 647{
631 struct via_spec *spec = codec->spec; 648 struct via_spec *spec = codec->spec;
632 int err; 649 int err;
633 650
651 spec->gen.main_out_badness = &via_main_out_badness;
652 spec->gen.extra_out_badness = &via_extra_out_badness;
653
634 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0); 654 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
635 if (err < 0) 655 if (err < 0)
636 return err; 656 return err;
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 223c3d9cc69e..9ea05e956474 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -969,6 +969,7 @@ static int snd_hdspm_create_pcm(struct snd_card *card,
969 struct hdspm *hdspm); 969 struct hdspm *hdspm);
970 970
971static inline void snd_hdspm_initialize_midi_flush(struct hdspm *hdspm); 971static inline void snd_hdspm_initialize_midi_flush(struct hdspm *hdspm);
972static inline int hdspm_get_pll_freq(struct hdspm *hdspm);
972static int hdspm_update_simple_mixer_controls(struct hdspm *hdspm); 973static int hdspm_update_simple_mixer_controls(struct hdspm *hdspm);
973static int hdspm_autosync_ref(struct hdspm *hdspm); 974static int hdspm_autosync_ref(struct hdspm *hdspm);
974static int snd_hdspm_set_defaults(struct hdspm *hdspm); 975static int snd_hdspm_set_defaults(struct hdspm *hdspm);
@@ -1075,6 +1076,20 @@ static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm)
1075 return ret; 1076 return ret;
1076} 1077}
1077 1078
1079/* round arbitary sample rates to commonly known rates */
1080static int hdspm_round_frequency(int rate)
1081{
1082 if (rate < 38050)
1083 return 32000;
1084 if (rate < 46008)
1085 return 44100;
1086 else
1087 return 48000;
1088}
1089
1090static int hdspm_tco_sync_check(struct hdspm *hdspm);
1091static int hdspm_sync_in_sync_check(struct hdspm *hdspm);
1092
1078/* check for external sample rate */ 1093/* check for external sample rate */
1079static int hdspm_external_sample_rate(struct hdspm *hdspm) 1094static int hdspm_external_sample_rate(struct hdspm *hdspm)
1080{ 1095{
@@ -1216,22 +1231,45 @@ static int hdspm_external_sample_rate(struct hdspm *hdspm)
1216 break; 1231 break;
1217 } 1232 }
1218 1233
1219 /* QS and DS rates normally can not be detected 1234 } /* endif HDSPM_madiLock */
1220 * automatically by the card. Only exception is MADI 1235
1221 * in 96k frame mode. 1236 /* check sample rate from TCO or SYNC_IN */
1222 * 1237 {
1223 * So if we read SS values (32 .. 48k), check for 1238 bool is_valid_input = 0;
1224 * user-provided DS/QS bits in the control register 1239 bool has_sync = 0;
1225 * and multiply the base frequency accordingly. 1240
1226 */ 1241 syncref = hdspm_autosync_ref(hdspm);
1227 if (rate <= 48000) { 1242 if (HDSPM_AUTOSYNC_FROM_TCO == syncref) {
1228 if (hdspm->control_register & HDSPM_QuadSpeed) 1243 is_valid_input = 1;
1229 rate *= 4; 1244 has_sync = (HDSPM_SYNC_CHECK_SYNC ==
1230 else if (hdspm->control_register & 1245 hdspm_tco_sync_check(hdspm));
1231 HDSPM_DoubleSpeed) 1246 } else if (HDSPM_AUTOSYNC_FROM_SYNC_IN == syncref) {
1232 rate *= 2; 1247 is_valid_input = 1;
1248 has_sync = (HDSPM_SYNC_CHECK_SYNC ==
1249 hdspm_sync_in_sync_check(hdspm));
1250 }
1251
1252 if (is_valid_input && has_sync) {
1253 rate = hdspm_round_frequency(
1254 hdspm_get_pll_freq(hdspm));
1233 } 1255 }
1234 } 1256 }
1257
1258 /* QS and DS rates normally can not be detected
1259 * automatically by the card. Only exception is MADI
1260 * in 96k frame mode.
1261 *
1262 * So if we read SS values (32 .. 48k), check for
1263 * user-provided DS/QS bits in the control register
1264 * and multiply the base frequency accordingly.
1265 */
1266 if (rate <= 48000) {
1267 if (hdspm->control_register & HDSPM_QuadSpeed)
1268 rate *= 4;
1269 else if (hdspm->control_register &
1270 HDSPM_DoubleSpeed)
1271 rate *= 2;
1272 }
1235 break; 1273 break;
1236 } 1274 }
1237 1275
@@ -1979,16 +2017,25 @@ static void hdspm_midi_tasklet(unsigned long arg)
1979/* get the system sample rate which is set */ 2017/* get the system sample rate which is set */
1980 2018
1981 2019
2020static inline int hdspm_get_pll_freq(struct hdspm *hdspm)
2021{
2022 unsigned int period, rate;
2023
2024 period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
2025 rate = hdspm_calc_dds_value(hdspm, period);
2026
2027 return rate;
2028}
2029
1982/** 2030/**
1983 * Calculate the real sample rate from the 2031 * Calculate the real sample rate from the
1984 * current DDS value. 2032 * current DDS value.
1985 **/ 2033 **/
1986static int hdspm_get_system_sample_rate(struct hdspm *hdspm) 2034static int hdspm_get_system_sample_rate(struct hdspm *hdspm)
1987{ 2035{
1988 unsigned int period, rate; 2036 unsigned int rate;
1989 2037
1990 period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); 2038 rate = hdspm_get_pll_freq(hdspm);
1991 rate = hdspm_calc_dds_value(hdspm, period);
1992 2039
1993 if (rate > 207000) { 2040 if (rate > 207000) {
1994 /* Unreasonable high sample rate as seen on PCI MADI cards. */ 2041 /* Unreasonable high sample rate as seen on PCI MADI cards. */
@@ -2128,6 +2175,16 @@ static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx)
2128 return (status >> (idx*4)) & 0xF; 2175 return (status >> (idx*4)) & 0xF;
2129} 2176}
2130 2177
2178#define ENUMERATED_CTL_INFO(info, texts) \
2179{ \
2180 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; \
2181 uinfo->count = 1; \
2182 uinfo->value.enumerated.items = ARRAY_SIZE(texts); \
2183 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) \
2184 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; \
2185 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); \
2186}
2187
2131 2188
2132 2189
2133#define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \ 2190#define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
@@ -2143,14 +2200,7 @@ static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx)
2143static int snd_hdspm_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, 2200static int snd_hdspm_info_autosync_sample_rate(struct snd_kcontrol *kcontrol,
2144 struct snd_ctl_elem_info *uinfo) 2201 struct snd_ctl_elem_info *uinfo)
2145{ 2202{
2146 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2203 ENUMERATED_CTL_INFO(uinfo, texts_freq);
2147 uinfo->count = 1;
2148 uinfo->value.enumerated.items = 10;
2149
2150 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2151 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2152 strcpy(uinfo->value.enumerated.name,
2153 texts_freq[uinfo->value.enumerated.item]);
2154 return 0; 2204 return 0;
2155} 2205}
2156 2206
@@ -2316,15 +2366,7 @@ static int snd_hdspm_info_system_clock_mode(struct snd_kcontrol *kcontrol,
2316 struct snd_ctl_elem_info *uinfo) 2366 struct snd_ctl_elem_info *uinfo)
2317{ 2367{
2318 static char *texts[] = { "Master", "AutoSync" }; 2368 static char *texts[] = { "Master", "AutoSync" };
2319 2369 ENUMERATED_CTL_INFO(uinfo, texts);
2320 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2321 uinfo->count = 1;
2322 uinfo->value.enumerated.items = 2;
2323 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2324 uinfo->value.enumerated.item =
2325 uinfo->value.enumerated.items - 1;
2326 strcpy(uinfo->value.enumerated.name,
2327 texts[uinfo->value.enumerated.item]);
2328 return 0; 2370 return 0;
2329} 2371}
2330 2372
@@ -2888,6 +2930,112 @@ static int snd_hdspm_get_autosync_ref(struct snd_kcontrol *kcontrol,
2888 return 0; 2930 return 0;
2889} 2931}
2890 2932
2933
2934
2935#define HDSPM_TCO_VIDEO_INPUT_FORMAT(xname, xindex) \
2936{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2937 .name = xname, \
2938 .access = SNDRV_CTL_ELEM_ACCESS_READ |\
2939 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2940 .info = snd_hdspm_info_tco_video_input_format, \
2941 .get = snd_hdspm_get_tco_video_input_format, \
2942}
2943
2944static int snd_hdspm_info_tco_video_input_format(struct snd_kcontrol *kcontrol,
2945 struct snd_ctl_elem_info *uinfo)
2946{
2947 static char *texts[] = {"No video", "NTSC", "PAL"};
2948 ENUMERATED_CTL_INFO(uinfo, texts);
2949 return 0;
2950}
2951
2952static int snd_hdspm_get_tco_video_input_format(struct snd_kcontrol *kcontrol,
2953 struct snd_ctl_elem_value *ucontrol)
2954{
2955 u32 status;
2956 int ret = 0;
2957
2958 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2959 status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
2960 switch (status & (HDSPM_TCO1_Video_Input_Format_NTSC |
2961 HDSPM_TCO1_Video_Input_Format_PAL)) {
2962 case HDSPM_TCO1_Video_Input_Format_NTSC:
2963 /* ntsc */
2964 ret = 1;
2965 break;
2966 case HDSPM_TCO1_Video_Input_Format_PAL:
2967 /* pal */
2968 ret = 2;
2969 break;
2970 default:
2971 /* no video */
2972 ret = 0;
2973 break;
2974 }
2975 ucontrol->value.enumerated.item[0] = ret;
2976 return 0;
2977}
2978
2979
2980
2981#define HDSPM_TCO_LTC_FRAMES(xname, xindex) \
2982{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2983 .name = xname, \
2984 .access = SNDRV_CTL_ELEM_ACCESS_READ |\
2985 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2986 .info = snd_hdspm_info_tco_ltc_frames, \
2987 .get = snd_hdspm_get_tco_ltc_frames, \
2988}
2989
2990static int snd_hdspm_info_tco_ltc_frames(struct snd_kcontrol *kcontrol,
2991 struct snd_ctl_elem_info *uinfo)
2992{
2993 static char *texts[] = {"No lock", "24 fps", "25 fps", "29.97 fps",
2994 "30 fps"};
2995 ENUMERATED_CTL_INFO(uinfo, texts);
2996 return 0;
2997}
2998
2999static int hdspm_tco_ltc_frames(struct hdspm *hdspm)
3000{
3001 u32 status;
3002 int ret = 0;
3003
3004 status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
3005 if (status & HDSPM_TCO1_LTC_Input_valid) {
3006 switch (status & (HDSPM_TCO1_LTC_Format_LSB |
3007 HDSPM_TCO1_LTC_Format_MSB)) {
3008 case 0:
3009 /* 24 fps */
3010 ret = 1;
3011 break;
3012 case HDSPM_TCO1_LTC_Format_LSB:
3013 /* 25 fps */
3014 ret = 2;
3015 break;
3016 case HDSPM_TCO1_LTC_Format_MSB:
3017 /* 25 fps */
3018 ret = 3;
3019 break;
3020 default:
3021 /* 30 fps */
3022 ret = 4;
3023 break;
3024 }
3025 }
3026
3027 return ret;
3028}
3029
3030static int snd_hdspm_get_tco_ltc_frames(struct snd_kcontrol *kcontrol,
3031 struct snd_ctl_elem_value *ucontrol)
3032{
3033 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3034
3035 ucontrol->value.enumerated.item[0] = hdspm_tco_ltc_frames(hdspm);
3036 return 0;
3037}
3038
2891#define HDSPM_TOGGLE_SETTING(xname, xindex) \ 3039#define HDSPM_TOGGLE_SETTING(xname, xindex) \
2892{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 3040{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2893 .name = xname, \ 3041 .name = xname, \
@@ -2974,17 +3122,7 @@ static int snd_hdspm_info_input_select(struct snd_kcontrol *kcontrol,
2974 struct snd_ctl_elem_info *uinfo) 3122 struct snd_ctl_elem_info *uinfo)
2975{ 3123{
2976 static char *texts[] = { "optical", "coaxial" }; 3124 static char *texts[] = { "optical", "coaxial" };
2977 3125 ENUMERATED_CTL_INFO(uinfo, texts);
2978 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2979 uinfo->count = 1;
2980 uinfo->value.enumerated.items = 2;
2981
2982 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2983 uinfo->value.enumerated.item =
2984 uinfo->value.enumerated.items - 1;
2985 strcpy(uinfo->value.enumerated.name,
2986 texts[uinfo->value.enumerated.item]);
2987
2988 return 0; 3126 return 0;
2989} 3127}
2990 3128
@@ -3046,17 +3184,7 @@ static int snd_hdspm_info_ds_wire(struct snd_kcontrol *kcontrol,
3046 struct snd_ctl_elem_info *uinfo) 3184 struct snd_ctl_elem_info *uinfo)
3047{ 3185{
3048 static char *texts[] = { "Single", "Double" }; 3186 static char *texts[] = { "Single", "Double" };
3049 3187 ENUMERATED_CTL_INFO(uinfo, texts);
3050 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3051 uinfo->count = 1;
3052 uinfo->value.enumerated.items = 2;
3053
3054 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3055 uinfo->value.enumerated.item =
3056 uinfo->value.enumerated.items - 1;
3057 strcpy(uinfo->value.enumerated.name,
3058 texts[uinfo->value.enumerated.item]);
3059
3060 return 0; 3188 return 0;
3061} 3189}
3062 3190
@@ -3129,17 +3257,7 @@ static int snd_hdspm_info_qs_wire(struct snd_kcontrol *kcontrol,
3129 struct snd_ctl_elem_info *uinfo) 3257 struct snd_ctl_elem_info *uinfo)
3130{ 3258{
3131 static char *texts[] = { "Single", "Double", "Quad" }; 3259 static char *texts[] = { "Single", "Double", "Quad" };
3132 3260 ENUMERATED_CTL_INFO(uinfo, texts);
3133 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3134 uinfo->count = 1;
3135 uinfo->value.enumerated.items = 3;
3136
3137 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3138 uinfo->value.enumerated.item =
3139 uinfo->value.enumerated.items - 1;
3140 strcpy(uinfo->value.enumerated.name,
3141 texts[uinfo->value.enumerated.item]);
3142
3143 return 0; 3261 return 0;
3144} 3262}
3145 3263
@@ -3215,17 +3333,7 @@ static int snd_hdspm_info_madi_speedmode(struct snd_kcontrol *kcontrol,
3215 struct snd_ctl_elem_info *uinfo) 3333 struct snd_ctl_elem_info *uinfo)
3216{ 3334{
3217 static char *texts[] = { "Single", "Double", "Quad" }; 3335 static char *texts[] = { "Single", "Double", "Quad" };
3218 3336 ENUMERATED_CTL_INFO(uinfo, texts);
3219 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3220 uinfo->count = 1;
3221 uinfo->value.enumerated.items = 3;
3222
3223 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3224 uinfo->value.enumerated.item =
3225 uinfo->value.enumerated.items - 1;
3226 strcpy(uinfo->value.enumerated.name,
3227 texts[uinfo->value.enumerated.item]);
3228
3229 return 0; 3337 return 0;
3230} 3338}
3231 3339
@@ -3445,19 +3553,30 @@ static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol,
3445 .get = snd_hdspm_get_sync_check \ 3553 .get = snd_hdspm_get_sync_check \
3446} 3554}
3447 3555
3556#define HDSPM_TCO_LOCK_CHECK(xname, xindex) \
3557{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3558 .name = xname, \
3559 .private_value = xindex, \
3560 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3561 .info = snd_hdspm_tco_info_lock_check, \
3562 .get = snd_hdspm_get_sync_check \
3563}
3564
3565
3448 3566
3449static int snd_hdspm_info_sync_check(struct snd_kcontrol *kcontrol, 3567static int snd_hdspm_info_sync_check(struct snd_kcontrol *kcontrol,
3450 struct snd_ctl_elem_info *uinfo) 3568 struct snd_ctl_elem_info *uinfo)
3451{ 3569{
3452 static char *texts[] = { "No Lock", "Lock", "Sync", "N/A" }; 3570 static char *texts[] = { "No Lock", "Lock", "Sync", "N/A" };
3453 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 3571 ENUMERATED_CTL_INFO(uinfo, texts);
3454 uinfo->count = 1; 3572 return 0;
3455 uinfo->value.enumerated.items = 4; 3573}
3456 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 3574
3457 uinfo->value.enumerated.item = 3575static int snd_hdspm_tco_info_lock_check(struct snd_kcontrol *kcontrol,
3458 uinfo->value.enumerated.items - 1; 3576 struct snd_ctl_elem_info *uinfo)
3459 strcpy(uinfo->value.enumerated.name, 3577{
3460 texts[uinfo->value.enumerated.item]); 3578 static char *texts[] = { "No Lock", "Lock" };
3579 ENUMERATED_CTL_INFO(uinfo, texts);
3461 return 0; 3580 return 0;
3462} 3581}
3463 3582
@@ -3590,6 +3709,14 @@ static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx)
3590 return 0; 3709 return 0;
3591} 3710}
3592 3711
3712static int hdspm_tco_input_check(struct hdspm *hdspm, u32 mask)
3713{
3714 u32 status;
3715 status = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
3716
3717 return (status & mask) ? 1 : 0;
3718}
3719
3593 3720
3594static int hdspm_tco_sync_check(struct hdspm *hdspm) 3721static int hdspm_tco_sync_check(struct hdspm *hdspm)
3595{ 3722{
@@ -3697,6 +3824,22 @@ static int snd_hdspm_get_sync_check(struct snd_kcontrol *kcontrol,
3697 3824
3698 } 3825 }
3699 3826
3827 if (hdspm->tco) {
3828 switch (kcontrol->private_value) {
3829 case 11:
3830 /* Check TCO for lock state of its current input */
3831 val = hdspm_tco_input_check(hdspm, HDSPM_TCO1_TCO_lock);
3832 break;
3833 case 12:
3834 /* Check TCO for valid time code on LTC input. */
3835 val = hdspm_tco_input_check(hdspm,
3836 HDSPM_TCO1_LTC_Input_valid);
3837 break;
3838 default:
3839 break;
3840 }
3841 }
3842
3700 if (-1 == val) 3843 if (-1 == val)
3701 val = 3; 3844 val = 3;
3702 3845
@@ -3813,17 +3956,7 @@ static int snd_hdspm_info_tco_sample_rate(struct snd_kcontrol *kcontrol,
3813 struct snd_ctl_elem_info *uinfo) 3956 struct snd_ctl_elem_info *uinfo)
3814{ 3957{
3815 static char *texts[] = { "44.1 kHz", "48 kHz" }; 3958 static char *texts[] = { "44.1 kHz", "48 kHz" };
3816 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 3959 ENUMERATED_CTL_INFO(uinfo, texts);
3817 uinfo->count = 1;
3818 uinfo->value.enumerated.items = 2;
3819
3820 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3821 uinfo->value.enumerated.item =
3822 uinfo->value.enumerated.items - 1;
3823
3824 strcpy(uinfo->value.enumerated.name,
3825 texts[uinfo->value.enumerated.item]);
3826
3827 return 0; 3960 return 0;
3828} 3961}
3829 3962
@@ -3869,17 +4002,7 @@ static int snd_hdspm_info_tco_pull(struct snd_kcontrol *kcontrol,
3869 struct snd_ctl_elem_info *uinfo) 4002 struct snd_ctl_elem_info *uinfo)
3870{ 4003{
3871 static char *texts[] = { "0", "+ 0.1 %", "- 0.1 %", "+ 4 %", "- 4 %" }; 4004 static char *texts[] = { "0", "+ 0.1 %", "- 0.1 %", "+ 4 %", "- 4 %" };
3872 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 4005 ENUMERATED_CTL_INFO(uinfo, texts);
3873 uinfo->count = 1;
3874 uinfo->value.enumerated.items = 5;
3875
3876 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3877 uinfo->value.enumerated.item =
3878 uinfo->value.enumerated.items - 1;
3879
3880 strcpy(uinfo->value.enumerated.name,
3881 texts[uinfo->value.enumerated.item]);
3882
3883 return 0; 4006 return 0;
3884} 4007}
3885 4008
@@ -3924,17 +4047,7 @@ static int snd_hdspm_info_tco_wck_conversion(struct snd_kcontrol *kcontrol,
3924 struct snd_ctl_elem_info *uinfo) 4047 struct snd_ctl_elem_info *uinfo)
3925{ 4048{
3926 static char *texts[] = { "1:1", "44.1 -> 48", "48 -> 44.1" }; 4049 static char *texts[] = { "1:1", "44.1 -> 48", "48 -> 44.1" };
3927 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 4050 ENUMERATED_CTL_INFO(uinfo, texts);
3928 uinfo->count = 1;
3929 uinfo->value.enumerated.items = 3;
3930
3931 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3932 uinfo->value.enumerated.item =
3933 uinfo->value.enumerated.items - 1;
3934
3935 strcpy(uinfo->value.enumerated.name,
3936 texts[uinfo->value.enumerated.item]);
3937
3938 return 0; 4051 return 0;
3939} 4052}
3940 4053
@@ -3981,17 +4094,7 @@ static int snd_hdspm_info_tco_frame_rate(struct snd_kcontrol *kcontrol,
3981{ 4094{
3982 static char *texts[] = { "24 fps", "25 fps", "29.97fps", 4095 static char *texts[] = { "24 fps", "25 fps", "29.97fps",
3983 "29.97 dfps", "30 fps", "30 dfps" }; 4096 "29.97 dfps", "30 fps", "30 dfps" };
3984 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 4097 ENUMERATED_CTL_INFO(uinfo, texts);
3985 uinfo->count = 1;
3986 uinfo->value.enumerated.items = 6;
3987
3988 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3989 uinfo->value.enumerated.item =
3990 uinfo->value.enumerated.items - 1;
3991
3992 strcpy(uinfo->value.enumerated.name,
3993 texts[uinfo->value.enumerated.item]);
3994
3995 return 0; 4098 return 0;
3996} 4099}
3997 4100
@@ -4037,17 +4140,7 @@ static int snd_hdspm_info_tco_sync_source(struct snd_kcontrol *kcontrol,
4037 struct snd_ctl_elem_info *uinfo) 4140 struct snd_ctl_elem_info *uinfo)
4038{ 4141{
4039 static char *texts[] = { "LTC", "Video", "WCK" }; 4142 static char *texts[] = { "LTC", "Video", "WCK" };
4040 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 4143 ENUMERATED_CTL_INFO(uinfo, texts);
4041 uinfo->count = 1;
4042 uinfo->value.enumerated.items = 3;
4043
4044 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
4045 uinfo->value.enumerated.item =
4046 uinfo->value.enumerated.items - 1;
4047
4048 strcpy(uinfo->value.enumerated.name,
4049 texts[uinfo->value.enumerated.item]);
4050
4051 return 0; 4144 return 0;
4052} 4145}
4053 4146
@@ -4145,6 +4238,7 @@ static struct snd_kcontrol_new snd_hdspm_controls_madi[] = {
4145 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 3), 4238 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 3),
4146 HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut), 4239 HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut),
4147 HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch), 4240 HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch),
4241 HDSPM_TOGGLE_SETTING("Disable 96K frames", HDSPM_SMUX),
4148 HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms), 4242 HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms),
4149 HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp), 4243 HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp),
4150 HDSPM_INPUT_SELECT("Input Select", 0), 4244 HDSPM_INPUT_SELECT("Input Select", 0),
@@ -4272,7 +4366,11 @@ static struct snd_kcontrol_new snd_hdspm_controls_tco[] = {
4272 HDSPM_TCO_WCK_CONVERSION("TCO WCK Conversion", 0), 4366 HDSPM_TCO_WCK_CONVERSION("TCO WCK Conversion", 0),
4273 HDSPM_TCO_FRAME_RATE("TCO Frame Rate", 0), 4367 HDSPM_TCO_FRAME_RATE("TCO Frame Rate", 0),
4274 HDSPM_TCO_SYNC_SOURCE("TCO Sync Source", 0), 4368 HDSPM_TCO_SYNC_SOURCE("TCO Sync Source", 0),
4275 HDSPM_TCO_WORD_TERM("TCO Word Term", 0) 4369 HDSPM_TCO_WORD_TERM("TCO Word Term", 0),
4370 HDSPM_TCO_LOCK_CHECK("TCO Input Check", 11),
4371 HDSPM_TCO_LOCK_CHECK("TCO LTC Valid", 12),
4372 HDSPM_TCO_LTC_FRAMES("TCO Detected Frame Rate", 0),
4373 HDSPM_TCO_VIDEO_INPUT_FORMAT("Video Input Format", 0)
4276}; 4374};
4277 4375
4278 4376
diff --git a/sound/sound_core.c b/sound/sound_core.c
index bb23009edc8d..359753fc24e1 100644
--- a/sound/sound_core.c
+++ b/sound/sound_core.c
@@ -352,7 +352,9 @@ static struct sound_unit *chains[SOUND_STEP];
352 * @dev: device pointer 352 * @dev: device pointer
353 * 353 *
354 * Allocate a special sound device by minor number from the sound 354 * Allocate a special sound device by minor number from the sound
355 * subsystem. The allocated number is returned on success. On failure 355 * subsystem.
356 *
357 * Return: The allocated number is returned on success. On failure,
356 * a negative error code is returned. 358 * a negative error code is returned.
357 */ 359 */
358 360
@@ -436,8 +438,10 @@ EXPORT_SYMBOL(register_sound_special);
436 * @dev: Unit number to allocate 438 * @dev: Unit number to allocate
437 * 439 *
438 * Allocate a mixer device. Unit is the number of the mixer requested. 440 * Allocate a mixer device. Unit is the number of the mixer requested.
439 * Pass -1 to request the next free mixer unit. On success the allocated 441 * Pass -1 to request the next free mixer unit.
440 * number is returned, on failure a negative error code is returned. 442 *
443 * Return: On success, the allocated number is returned. On failure,
444 * a negative error code is returned.
441 */ 445 */
442 446
443int register_sound_mixer(const struct file_operations *fops, int dev) 447int register_sound_mixer(const struct file_operations *fops, int dev)
@@ -454,8 +458,10 @@ EXPORT_SYMBOL(register_sound_mixer);
454 * @dev: Unit number to allocate 458 * @dev: Unit number to allocate
455 * 459 *
456 * Allocate a midi device. Unit is the number of the midi device requested. 460 * Allocate a midi device. Unit is the number of the midi device requested.
457 * Pass -1 to request the next free midi unit. On success the allocated 461 * Pass -1 to request the next free midi unit.
458 * number is returned, on failure a negative error code is returned. 462 *
463 * Return: On success, the allocated number is returned. On failure,
464 * a negative error code is returned.
459 */ 465 */
460 466
461int register_sound_midi(const struct file_operations *fops, int dev) 467int register_sound_midi(const struct file_operations *fops, int dev)
@@ -477,11 +483,13 @@ EXPORT_SYMBOL(register_sound_midi);
477 * @dev: Unit number to allocate 483 * @dev: Unit number to allocate
478 * 484 *
479 * Allocate a DSP device. Unit is the number of the DSP requested. 485 * Allocate a DSP device. Unit is the number of the DSP requested.
480 * Pass -1 to request the next free DSP unit. On success the allocated 486 * Pass -1 to request the next free DSP unit.
481 * number is returned, on failure a negative error code is returned.
482 * 487 *
483 * This function allocates both the audio and dsp device entries together 488 * This function allocates both the audio and dsp device entries together
484 * and will always allocate them as a matching pair - eg dsp3/audio3 489 * and will always allocate them as a matching pair - eg dsp3/audio3
490 *
491 * Return: On success, the allocated number is returned. On failure,
492 * a negative error code is returned.
485 */ 493 */
486 494
487int register_sound_dsp(const struct file_operations *fops, int dev) 495int register_sound_dsp(const struct file_operations *fops, int dev)
diff --git a/sound/spi/at73c213.c b/sound/spi/at73c213.c
index 4dd60d8a4889..a1a24b979ed2 100644
--- a/sound/spi/at73c213.c
+++ b/sound/spi/at73c213.c
@@ -1075,10 +1075,11 @@ out:
1075 return 0; 1075 return 0;
1076} 1076}
1077 1077
1078#ifdef CONFIG_PM 1078#ifdef CONFIG_PM_SLEEP
1079static int snd_at73c213_suspend(struct spi_device *spi, pm_message_t msg) 1079
1080static int snd_at73c213_suspend(struct device *dev)
1080{ 1081{
1081 struct snd_card *card = dev_get_drvdata(&spi->dev); 1082 struct snd_card *card = dev_get_drvdata(dev);
1082 struct snd_at73c213 *chip = card->private_data; 1083 struct snd_at73c213 *chip = card->private_data;
1083 1084
1084 ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS)); 1085 ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS));
@@ -1087,9 +1088,9 @@ static int snd_at73c213_suspend(struct spi_device *spi, pm_message_t msg)
1087 return 0; 1088 return 0;
1088} 1089}
1089 1090
1090static int snd_at73c213_resume(struct spi_device *spi) 1091static int snd_at73c213_resume(struct device *dev)
1091{ 1092{
1092 struct snd_card *card = dev_get_drvdata(&spi->dev); 1093 struct snd_card *card = dev_get_drvdata(dev);
1093 struct snd_at73c213 *chip = card->private_data; 1094 struct snd_at73c213 *chip = card->private_data;
1094 1095
1095 clk_enable(chip->board->dac_clk); 1096 clk_enable(chip->board->dac_clk);
@@ -1097,18 +1098,21 @@ static int snd_at73c213_resume(struct spi_device *spi)
1097 1098
1098 return 0; 1099 return 0;
1099} 1100}
1101
1102static SIMPLE_DEV_PM_OPS(at73c213_pm_ops, snd_at73c213_suspend,
1103 snd_at73c213_resume);
1104#define AT73C213_PM_OPS (&at73c213_pm_ops)
1105
1100#else 1106#else
1101#define snd_at73c213_suspend NULL 1107#define AT73C213_PM_OPS NULL
1102#define snd_at73c213_resume NULL
1103#endif 1108#endif
1104 1109
1105static struct spi_driver at73c213_driver = { 1110static struct spi_driver at73c213_driver = {
1106 .driver = { 1111 .driver = {
1107 .name = "at73c213", 1112 .name = "at73c213",
1113 .pm = AT73C213_PM_OPS,
1108 }, 1114 },
1109 .probe = snd_at73c213_probe, 1115 .probe = snd_at73c213_probe,
1110 .suspend = snd_at73c213_suspend,
1111 .resume = snd_at73c213_resume,
1112 .remove = snd_at73c213_remove, 1116 .remove = snd_at73c213_remove,
1113}; 1117};
1114 1118
diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c
index fde9a7a29cb6..67330af21b0e 100644
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -16,6 +16,7 @@
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/ 17*/
18 18
19#include <linux/device.h>
19#include <linux/spinlock.h> 20#include <linux/spinlock.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21#include <linux/init.h> 22#include <linux/init.h>
@@ -39,8 +40,8 @@
39#define ENDPOINT_CAPTURE 2 40#define ENDPOINT_CAPTURE 2
40#define ENDPOINT_PLAYBACK 6 41#define ENDPOINT_PLAYBACK 6
41 42
42#define MAKE_CHECKBYTE(dev,stream,i) \ 43#define MAKE_CHECKBYTE(cdev,stream,i) \
43 (stream << 1) | (~(i / (dev->n_streams * BYTES_PER_SAMPLE_USB)) & 1) 44 (stream << 1) | (~(i / (cdev->n_streams * BYTES_PER_SAMPLE_USB)) & 1)
44 45
45static struct snd_pcm_hardware snd_usb_caiaq_pcm_hardware = { 46static struct snd_pcm_hardware snd_usb_caiaq_pcm_hardware = {
46 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 47 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
@@ -60,32 +61,32 @@ static struct snd_pcm_hardware snd_usb_caiaq_pcm_hardware = {
60}; 61};
61 62
62static void 63static void
63activate_substream(struct snd_usb_caiaqdev *dev, 64activate_substream(struct snd_usb_caiaqdev *cdev,
64 struct snd_pcm_substream *sub) 65 struct snd_pcm_substream *sub)
65{ 66{
66 spin_lock(&dev->spinlock); 67 spin_lock(&cdev->spinlock);
67 68
68 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 69 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
69 dev->sub_playback[sub->number] = sub; 70 cdev->sub_playback[sub->number] = sub;
70 else 71 else
71 dev->sub_capture[sub->number] = sub; 72 cdev->sub_capture[sub->number] = sub;
72 73
73 spin_unlock(&dev->spinlock); 74 spin_unlock(&cdev->spinlock);
74} 75}
75 76
76static void 77static void
77deactivate_substream(struct snd_usb_caiaqdev *dev, 78deactivate_substream(struct snd_usb_caiaqdev *cdev,
78 struct snd_pcm_substream *sub) 79 struct snd_pcm_substream *sub)
79{ 80{
80 unsigned long flags; 81 unsigned long flags;
81 spin_lock_irqsave(&dev->spinlock, flags); 82 spin_lock_irqsave(&cdev->spinlock, flags);
82 83
83 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 84 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
84 dev->sub_playback[sub->number] = NULL; 85 cdev->sub_playback[sub->number] = NULL;
85 else 86 else
86 dev->sub_capture[sub->number] = NULL; 87 cdev->sub_capture[sub->number] = NULL;
87 88
88 spin_unlock_irqrestore(&dev->spinlock, flags); 89 spin_unlock_irqrestore(&cdev->spinlock, flags);
89} 90}
90 91
91static int 92static int
@@ -98,28 +99,30 @@ all_substreams_zero(struct snd_pcm_substream **subs)
98 return 1; 99 return 1;
99} 100}
100 101
101static int stream_start(struct snd_usb_caiaqdev *dev) 102static int stream_start(struct snd_usb_caiaqdev *cdev)
102{ 103{
103 int i, ret; 104 int i, ret;
105 struct device *dev = caiaqdev_to_dev(cdev);
104 106
105 debug("%s(%p)\n", __func__, dev); 107 dev_dbg(dev, "%s(%p)\n", __func__, cdev);
106 108
107 if (dev->streaming) 109 if (cdev->streaming)
108 return -EINVAL; 110 return -EINVAL;
109 111
110 memset(dev->sub_playback, 0, sizeof(dev->sub_playback)); 112 memset(cdev->sub_playback, 0, sizeof(cdev->sub_playback));
111 memset(dev->sub_capture, 0, sizeof(dev->sub_capture)); 113 memset(cdev->sub_capture, 0, sizeof(cdev->sub_capture));
112 dev->input_panic = 0; 114 cdev->input_panic = 0;
113 dev->output_panic = 0; 115 cdev->output_panic = 0;
114 dev->first_packet = 4; 116 cdev->first_packet = 4;
115 dev->streaming = 1; 117 cdev->streaming = 1;
116 dev->warned = 0; 118 cdev->warned = 0;
117 119
118 for (i = 0; i < N_URBS; i++) { 120 for (i = 0; i < N_URBS; i++) {
119 ret = usb_submit_urb(dev->data_urbs_in[i], GFP_ATOMIC); 121 ret = usb_submit_urb(cdev->data_urbs_in[i], GFP_ATOMIC);
120 if (ret) { 122 if (ret) {
121 log("unable to trigger read #%d! (ret %d)\n", i, ret); 123 dev_err(dev, "unable to trigger read #%d! (ret %d)\n",
122 dev->streaming = 0; 124 i, ret);
125 cdev->streaming = 0;
123 return -EPIPE; 126 return -EPIPE;
124 } 127 }
125 } 128 }
@@ -127,46 +130,51 @@ static int stream_start(struct snd_usb_caiaqdev *dev)
127 return 0; 130 return 0;
128} 131}
129 132
130static void stream_stop(struct snd_usb_caiaqdev *dev) 133static void stream_stop(struct snd_usb_caiaqdev *cdev)
131{ 134{
132 int i; 135 int i;
136 struct device *dev = caiaqdev_to_dev(cdev);
133 137
134 debug("%s(%p)\n", __func__, dev); 138 dev_dbg(dev, "%s(%p)\n", __func__, cdev);
135 if (!dev->streaming) 139 if (!cdev->streaming)
136 return; 140 return;
137 141
138 dev->streaming = 0; 142 cdev->streaming = 0;
139 143
140 for (i = 0; i < N_URBS; i++) { 144 for (i = 0; i < N_URBS; i++) {
141 usb_kill_urb(dev->data_urbs_in[i]); 145 usb_kill_urb(cdev->data_urbs_in[i]);
142 146
143 if (test_bit(i, &dev->outurb_active_mask)) 147 if (test_bit(i, &cdev->outurb_active_mask))
144 usb_kill_urb(dev->data_urbs_out[i]); 148 usb_kill_urb(cdev->data_urbs_out[i]);
145 } 149 }
146 150
147 dev->outurb_active_mask = 0; 151 cdev->outurb_active_mask = 0;
148} 152}
149 153
150static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream) 154static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream)
151{ 155{
152 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 156 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream);
153 debug("%s(%p)\n", __func__, substream); 157 struct device *dev = caiaqdev_to_dev(cdev);
154 substream->runtime->hw = dev->pcm_info; 158
159 dev_dbg(dev, "%s(%p)\n", __func__, substream);
160 substream->runtime->hw = cdev->pcm_info;
155 snd_pcm_limit_hw_rates(substream->runtime); 161 snd_pcm_limit_hw_rates(substream->runtime);
162
156 return 0; 163 return 0;
157} 164}
158 165
159static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream) 166static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
160{ 167{
161 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 168 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream);
169 struct device *dev = caiaqdev_to_dev(cdev);
162 170
163 debug("%s(%p)\n", __func__, substream); 171 dev_dbg(dev, "%s(%p)\n", __func__, substream);
164 if (all_substreams_zero(dev->sub_playback) && 172 if (all_substreams_zero(cdev->sub_playback) &&
165 all_substreams_zero(dev->sub_capture)) { 173 all_substreams_zero(cdev->sub_capture)) {
166 /* when the last client has stopped streaming, 174 /* when the last client has stopped streaming,
167 * all sample rates are allowed again */ 175 * all sample rates are allowed again */
168 stream_stop(dev); 176 stream_stop(cdev);
169 dev->pcm_info.rates = dev->samplerates; 177 cdev->pcm_info.rates = cdev->samplerates;
170 } 178 }
171 179
172 return 0; 180 return 0;
@@ -175,15 +183,13 @@ static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
175static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub, 183static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub,
176 struct snd_pcm_hw_params *hw_params) 184 struct snd_pcm_hw_params *hw_params)
177{ 185{
178 debug("%s(%p)\n", __func__, sub);
179 return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params)); 186 return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params));
180} 187}
181 188
182static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub) 189static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub)
183{ 190{
184 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); 191 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub);
185 debug("%s(%p)\n", __func__, sub); 192 deactivate_substream(cdev, sub);
186 deactivate_substream(dev, sub);
187 return snd_pcm_lib_free_pages(sub); 193 return snd_pcm_lib_free_pages(sub);
188} 194}
189 195
@@ -199,15 +205,16 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
199{ 205{
200 int bytes_per_sample, bpp, ret, i; 206 int bytes_per_sample, bpp, ret, i;
201 int index = substream->number; 207 int index = substream->number;
202 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 208 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream);
203 struct snd_pcm_runtime *runtime = substream->runtime; 209 struct snd_pcm_runtime *runtime = substream->runtime;
210 struct device *dev = caiaqdev_to_dev(cdev);
204 211
205 debug("%s(%p)\n", __func__, substream); 212 dev_dbg(dev, "%s(%p)\n", __func__, substream);
206 213
207 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 214 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
208 int out_pos; 215 int out_pos;
209 216
210 switch (dev->spec.data_alignment) { 217 switch (cdev->spec.data_alignment) {
211 case 0: 218 case 0:
212 case 2: 219 case 2:
213 out_pos = BYTES_PER_SAMPLE + 1; 220 out_pos = BYTES_PER_SAMPLE + 1;
@@ -218,12 +225,12 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
218 break; 225 break;
219 } 226 }
220 227
221 dev->period_out_count[index] = out_pos; 228 cdev->period_out_count[index] = out_pos;
222 dev->audio_out_buf_pos[index] = out_pos; 229 cdev->audio_out_buf_pos[index] = out_pos;
223 } else { 230 } else {
224 int in_pos; 231 int in_pos;
225 232
226 switch (dev->spec.data_alignment) { 233 switch (cdev->spec.data_alignment) {
227 case 0: 234 case 0:
228 in_pos = BYTES_PER_SAMPLE + 2; 235 in_pos = BYTES_PER_SAMPLE + 2;
229 break; 236 break;
@@ -236,44 +243,44 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
236 break; 243 break;
237 } 244 }
238 245
239 dev->period_in_count[index] = in_pos; 246 cdev->period_in_count[index] = in_pos;
240 dev->audio_in_buf_pos[index] = in_pos; 247 cdev->audio_in_buf_pos[index] = in_pos;
241 } 248 }
242 249
243 if (dev->streaming) 250 if (cdev->streaming)
244 return 0; 251 return 0;
245 252
246 /* the first client that opens a stream defines the sample rate 253 /* the first client that opens a stream defines the sample rate
247 * setting for all subsequent calls, until the last client closed. */ 254 * setting for all subsequent calls, until the last client closed. */
248 for (i=0; i < ARRAY_SIZE(rates); i++) 255 for (i=0; i < ARRAY_SIZE(rates); i++)
249 if (runtime->rate == rates[i]) 256 if (runtime->rate == rates[i])
250 dev->pcm_info.rates = 1 << i; 257 cdev->pcm_info.rates = 1 << i;
251 258
252 snd_pcm_limit_hw_rates(runtime); 259 snd_pcm_limit_hw_rates(runtime);
253 260
254 bytes_per_sample = BYTES_PER_SAMPLE; 261 bytes_per_sample = BYTES_PER_SAMPLE;
255 if (dev->spec.data_alignment >= 2) 262 if (cdev->spec.data_alignment >= 2)
256 bytes_per_sample++; 263 bytes_per_sample++;
257 264
258 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE) 265 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE)
259 * bytes_per_sample * CHANNELS_PER_STREAM * dev->n_streams; 266 * bytes_per_sample * CHANNELS_PER_STREAM * cdev->n_streams;
260 267
261 if (bpp > MAX_ENDPOINT_SIZE) 268 if (bpp > MAX_ENDPOINT_SIZE)
262 bpp = MAX_ENDPOINT_SIZE; 269 bpp = MAX_ENDPOINT_SIZE;
263 270
264 ret = snd_usb_caiaq_set_audio_params(dev, runtime->rate, 271 ret = snd_usb_caiaq_set_audio_params(cdev, runtime->rate,
265 runtime->sample_bits, bpp); 272 runtime->sample_bits, bpp);
266 if (ret) 273 if (ret)
267 return ret; 274 return ret;
268 275
269 ret = stream_start(dev); 276 ret = stream_start(cdev);
270 if (ret) 277 if (ret)
271 return ret; 278 return ret;
272 279
273 dev->output_running = 0; 280 cdev->output_running = 0;
274 wait_event_timeout(dev->prepare_wait_queue, dev->output_running, HZ); 281 wait_event_timeout(cdev->prepare_wait_queue, cdev->output_running, HZ);
275 if (!dev->output_running) { 282 if (!cdev->output_running) {
276 stream_stop(dev); 283 stream_stop(cdev);
277 return -EPIPE; 284 return -EPIPE;
278 } 285 }
279 286
@@ -282,18 +289,19 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
282 289
283static int snd_usb_caiaq_pcm_trigger(struct snd_pcm_substream *sub, int cmd) 290static int snd_usb_caiaq_pcm_trigger(struct snd_pcm_substream *sub, int cmd)
284{ 291{
285 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); 292 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub);
293 struct device *dev = caiaqdev_to_dev(cdev);
286 294
287 debug("%s(%p) cmd %d\n", __func__, sub, cmd); 295 dev_dbg(dev, "%s(%p) cmd %d\n", __func__, sub, cmd);
288 296
289 switch (cmd) { 297 switch (cmd) {
290 case SNDRV_PCM_TRIGGER_START: 298 case SNDRV_PCM_TRIGGER_START:
291 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 299 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
292 activate_substream(dev, sub); 300 activate_substream(cdev, sub);
293 break; 301 break;
294 case SNDRV_PCM_TRIGGER_STOP: 302 case SNDRV_PCM_TRIGGER_STOP:
295 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 303 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
296 deactivate_substream(dev, sub); 304 deactivate_substream(cdev, sub);
297 break; 305 break;
298 default: 306 default:
299 return -EINVAL; 307 return -EINVAL;
@@ -306,25 +314,25 @@ static snd_pcm_uframes_t
306snd_usb_caiaq_pcm_pointer(struct snd_pcm_substream *sub) 314snd_usb_caiaq_pcm_pointer(struct snd_pcm_substream *sub)
307{ 315{
308 int index = sub->number; 316 int index = sub->number;
309 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); 317 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub);
310 snd_pcm_uframes_t ptr; 318 snd_pcm_uframes_t ptr;
311 319
312 spin_lock(&dev->spinlock); 320 spin_lock(&cdev->spinlock);
313 321
314 if (dev->input_panic || dev->output_panic) { 322 if (cdev->input_panic || cdev->output_panic) {
315 ptr = SNDRV_PCM_POS_XRUN; 323 ptr = SNDRV_PCM_POS_XRUN;
316 goto unlock; 324 goto unlock;
317 } 325 }
318 326
319 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 327 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
320 ptr = bytes_to_frames(sub->runtime, 328 ptr = bytes_to_frames(sub->runtime,
321 dev->audio_out_buf_pos[index]); 329 cdev->audio_out_buf_pos[index]);
322 else 330 else
323 ptr = bytes_to_frames(sub->runtime, 331 ptr = bytes_to_frames(sub->runtime,
324 dev->audio_in_buf_pos[index]); 332 cdev->audio_in_buf_pos[index]);
325 333
326unlock: 334unlock:
327 spin_unlock(&dev->spinlock); 335 spin_unlock(&cdev->spinlock);
328 return ptr; 336 return ptr;
329} 337}
330 338
@@ -340,21 +348,21 @@ static struct snd_pcm_ops snd_usb_caiaq_ops = {
340 .pointer = snd_usb_caiaq_pcm_pointer 348 .pointer = snd_usb_caiaq_pcm_pointer
341}; 349};
342 350
343static void check_for_elapsed_periods(struct snd_usb_caiaqdev *dev, 351static void check_for_elapsed_periods(struct snd_usb_caiaqdev *cdev,
344 struct snd_pcm_substream **subs) 352 struct snd_pcm_substream **subs)
345{ 353{
346 int stream, pb, *cnt; 354 int stream, pb, *cnt;
347 struct snd_pcm_substream *sub; 355 struct snd_pcm_substream *sub;
348 356
349 for (stream = 0; stream < dev->n_streams; stream++) { 357 for (stream = 0; stream < cdev->n_streams; stream++) {
350 sub = subs[stream]; 358 sub = subs[stream];
351 if (!sub) 359 if (!sub)
352 continue; 360 continue;
353 361
354 pb = snd_pcm_lib_period_bytes(sub); 362 pb = snd_pcm_lib_period_bytes(sub);
355 cnt = (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) ? 363 cnt = (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
356 &dev->period_out_count[stream] : 364 &cdev->period_out_count[stream] :
357 &dev->period_in_count[stream]; 365 &cdev->period_in_count[stream];
358 366
359 if (*cnt >= pb) { 367 if (*cnt >= pb) {
360 snd_pcm_period_elapsed(sub); 368 snd_pcm_period_elapsed(sub);
@@ -363,7 +371,7 @@ static void check_for_elapsed_periods(struct snd_usb_caiaqdev *dev,
363 } 371 }
364} 372}
365 373
366static void read_in_urb_mode0(struct snd_usb_caiaqdev *dev, 374static void read_in_urb_mode0(struct snd_usb_caiaqdev *cdev,
367 const struct urb *urb, 375 const struct urb *urb,
368 const struct usb_iso_packet_descriptor *iso) 376 const struct usb_iso_packet_descriptor *iso)
369{ 377{
@@ -371,27 +379,27 @@ static void read_in_urb_mode0(struct snd_usb_caiaqdev *dev,
371 struct snd_pcm_substream *sub; 379 struct snd_pcm_substream *sub;
372 int stream, i; 380 int stream, i;
373 381
374 if (all_substreams_zero(dev->sub_capture)) 382 if (all_substreams_zero(cdev->sub_capture))
375 return; 383 return;
376 384
377 for (i = 0; i < iso->actual_length;) { 385 for (i = 0; i < iso->actual_length;) {
378 for (stream = 0; stream < dev->n_streams; stream++, i++) { 386 for (stream = 0; stream < cdev->n_streams; stream++, i++) {
379 sub = dev->sub_capture[stream]; 387 sub = cdev->sub_capture[stream];
380 if (sub) { 388 if (sub) {
381 struct snd_pcm_runtime *rt = sub->runtime; 389 struct snd_pcm_runtime *rt = sub->runtime;
382 char *audio_buf = rt->dma_area; 390 char *audio_buf = rt->dma_area;
383 int sz = frames_to_bytes(rt, rt->buffer_size); 391 int sz = frames_to_bytes(rt, rt->buffer_size);
384 audio_buf[dev->audio_in_buf_pos[stream]++] 392 audio_buf[cdev->audio_in_buf_pos[stream]++]
385 = usb_buf[i]; 393 = usb_buf[i];
386 dev->period_in_count[stream]++; 394 cdev->period_in_count[stream]++;
387 if (dev->audio_in_buf_pos[stream] == sz) 395 if (cdev->audio_in_buf_pos[stream] == sz)
388 dev->audio_in_buf_pos[stream] = 0; 396 cdev->audio_in_buf_pos[stream] = 0;
389 } 397 }
390 } 398 }
391 } 399 }
392} 400}
393 401
394static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev, 402static void read_in_urb_mode2(struct snd_usb_caiaqdev *cdev,
395 const struct urb *urb, 403 const struct urb *urb,
396 const struct usb_iso_packet_descriptor *iso) 404 const struct usb_iso_packet_descriptor *iso)
397{ 405{
@@ -401,48 +409,49 @@ static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
401 int stream, i; 409 int stream, i;
402 410
403 for (i = 0; i < iso->actual_length;) { 411 for (i = 0; i < iso->actual_length;) {
404 if (i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 0) { 412 if (i % (cdev->n_streams * BYTES_PER_SAMPLE_USB) == 0) {
405 for (stream = 0; 413 for (stream = 0;
406 stream < dev->n_streams; 414 stream < cdev->n_streams;
407 stream++, i++) { 415 stream++, i++) {
408 if (dev->first_packet) 416 if (cdev->first_packet)
409 continue; 417 continue;
410 418
411 check_byte = MAKE_CHECKBYTE(dev, stream, i); 419 check_byte = MAKE_CHECKBYTE(cdev, stream, i);
412 420
413 if ((usb_buf[i] & 0x3f) != check_byte) 421 if ((usb_buf[i] & 0x3f) != check_byte)
414 dev->input_panic = 1; 422 cdev->input_panic = 1;
415 423
416 if (usb_buf[i] & 0x80) 424 if (usb_buf[i] & 0x80)
417 dev->output_panic = 1; 425 cdev->output_panic = 1;
418 } 426 }
419 } 427 }
420 dev->first_packet = 0; 428 cdev->first_packet = 0;
421 429
422 for (stream = 0; stream < dev->n_streams; stream++, i++) { 430 for (stream = 0; stream < cdev->n_streams; stream++, i++) {
423 sub = dev->sub_capture[stream]; 431 sub = cdev->sub_capture[stream];
424 if (dev->input_panic) 432 if (cdev->input_panic)
425 usb_buf[i] = 0; 433 usb_buf[i] = 0;
426 434
427 if (sub) { 435 if (sub) {
428 struct snd_pcm_runtime *rt = sub->runtime; 436 struct snd_pcm_runtime *rt = sub->runtime;
429 char *audio_buf = rt->dma_area; 437 char *audio_buf = rt->dma_area;
430 int sz = frames_to_bytes(rt, rt->buffer_size); 438 int sz = frames_to_bytes(rt, rt->buffer_size);
431 audio_buf[dev->audio_in_buf_pos[stream]++] = 439 audio_buf[cdev->audio_in_buf_pos[stream]++] =
432 usb_buf[i]; 440 usb_buf[i];
433 dev->period_in_count[stream]++; 441 cdev->period_in_count[stream]++;
434 if (dev->audio_in_buf_pos[stream] == sz) 442 if (cdev->audio_in_buf_pos[stream] == sz)
435 dev->audio_in_buf_pos[stream] = 0; 443 cdev->audio_in_buf_pos[stream] = 0;
436 } 444 }
437 } 445 }
438 } 446 }
439} 447}
440 448
441static void read_in_urb_mode3(struct snd_usb_caiaqdev *dev, 449static void read_in_urb_mode3(struct snd_usb_caiaqdev *cdev,
442 const struct urb *urb, 450 const struct urb *urb,
443 const struct usb_iso_packet_descriptor *iso) 451 const struct usb_iso_packet_descriptor *iso)
444{ 452{
445 unsigned char *usb_buf = urb->transfer_buffer + iso->offset; 453 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
454 struct device *dev = caiaqdev_to_dev(cdev);
446 int stream, i; 455 int stream, i;
447 456
448 /* paranoia check */ 457 /* paranoia check */
@@ -450,12 +459,12 @@ static void read_in_urb_mode3(struct snd_usb_caiaqdev *dev,
450 return; 459 return;
451 460
452 for (i = 0; i < iso->actual_length;) { 461 for (i = 0; i < iso->actual_length;) {
453 for (stream = 0; stream < dev->n_streams; stream++) { 462 for (stream = 0; stream < cdev->n_streams; stream++) {
454 struct snd_pcm_substream *sub = dev->sub_capture[stream]; 463 struct snd_pcm_substream *sub = cdev->sub_capture[stream];
455 char *audio_buf = NULL; 464 char *audio_buf = NULL;
456 int c, n, sz = 0; 465 int c, n, sz = 0;
457 466
458 if (sub && !dev->input_panic) { 467 if (sub && !cdev->input_panic) {
459 struct snd_pcm_runtime *rt = sub->runtime; 468 struct snd_pcm_runtime *rt = sub->runtime;
460 audio_buf = rt->dma_area; 469 audio_buf = rt->dma_area;
461 sz = frames_to_bytes(rt, rt->buffer_size); 470 sz = frames_to_bytes(rt, rt->buffer_size);
@@ -465,23 +474,23 @@ static void read_in_urb_mode3(struct snd_usb_caiaqdev *dev,
465 /* 3 audio data bytes, followed by 1 check byte */ 474 /* 3 audio data bytes, followed by 1 check byte */
466 if (audio_buf) { 475 if (audio_buf) {
467 for (n = 0; n < BYTES_PER_SAMPLE; n++) { 476 for (n = 0; n < BYTES_PER_SAMPLE; n++) {
468 audio_buf[dev->audio_in_buf_pos[stream]++] = usb_buf[i+n]; 477 audio_buf[cdev->audio_in_buf_pos[stream]++] = usb_buf[i+n];
469 478
470 if (dev->audio_in_buf_pos[stream] == sz) 479 if (cdev->audio_in_buf_pos[stream] == sz)
471 dev->audio_in_buf_pos[stream] = 0; 480 cdev->audio_in_buf_pos[stream] = 0;
472 } 481 }
473 482
474 dev->period_in_count[stream] += BYTES_PER_SAMPLE; 483 cdev->period_in_count[stream] += BYTES_PER_SAMPLE;
475 } 484 }
476 485
477 i += BYTES_PER_SAMPLE; 486 i += BYTES_PER_SAMPLE;
478 487
479 if (usb_buf[i] != ((stream << 1) | c) && 488 if (usb_buf[i] != ((stream << 1) | c) &&
480 !dev->first_packet) { 489 !cdev->first_packet) {
481 if (!dev->input_panic) 490 if (!cdev->input_panic)
482 printk(" EXPECTED: %02x got %02x, c %d, stream %d, i %d\n", 491 dev_warn(dev, " EXPECTED: %02x got %02x, c %d, stream %d, i %d\n",
483 ((stream << 1) | c), usb_buf[i], c, stream, i); 492 ((stream << 1) | c), usb_buf[i], c, stream, i);
484 dev->input_panic = 1; 493 cdev->input_panic = 1;
485 } 494 }
486 495
487 i++; 496 i++;
@@ -489,41 +498,43 @@ static void read_in_urb_mode3(struct snd_usb_caiaqdev *dev,
489 } 498 }
490 } 499 }
491 500
492 if (dev->first_packet > 0) 501 if (cdev->first_packet > 0)
493 dev->first_packet--; 502 cdev->first_packet--;
494} 503}
495 504
496static void read_in_urb(struct snd_usb_caiaqdev *dev, 505static void read_in_urb(struct snd_usb_caiaqdev *cdev,
497 const struct urb *urb, 506 const struct urb *urb,
498 const struct usb_iso_packet_descriptor *iso) 507 const struct usb_iso_packet_descriptor *iso)
499{ 508{
500 if (!dev->streaming) 509 struct device *dev = caiaqdev_to_dev(cdev);
510
511 if (!cdev->streaming)
501 return; 512 return;
502 513
503 if (iso->actual_length < dev->bpp) 514 if (iso->actual_length < cdev->bpp)
504 return; 515 return;
505 516
506 switch (dev->spec.data_alignment) { 517 switch (cdev->spec.data_alignment) {
507 case 0: 518 case 0:
508 read_in_urb_mode0(dev, urb, iso); 519 read_in_urb_mode0(cdev, urb, iso);
509 break; 520 break;
510 case 2: 521 case 2:
511 read_in_urb_mode2(dev, urb, iso); 522 read_in_urb_mode2(cdev, urb, iso);
512 break; 523 break;
513 case 3: 524 case 3:
514 read_in_urb_mode3(dev, urb, iso); 525 read_in_urb_mode3(cdev, urb, iso);
515 break; 526 break;
516 } 527 }
517 528
518 if ((dev->input_panic || dev->output_panic) && !dev->warned) { 529 if ((cdev->input_panic || cdev->output_panic) && !cdev->warned) {
519 debug("streaming error detected %s %s\n", 530 dev_warn(dev, "streaming error detected %s %s\n",
520 dev->input_panic ? "(input)" : "", 531 cdev->input_panic ? "(input)" : "",
521 dev->output_panic ? "(output)" : ""); 532 cdev->output_panic ? "(output)" : "");
522 dev->warned = 1; 533 cdev->warned = 1;
523 } 534 }
524} 535}
525 536
526static void fill_out_urb_mode_0(struct snd_usb_caiaqdev *dev, 537static void fill_out_urb_mode_0(struct snd_usb_caiaqdev *cdev,
527 struct urb *urb, 538 struct urb *urb,
528 const struct usb_iso_packet_descriptor *iso) 539 const struct usb_iso_packet_descriptor *iso)
529{ 540{
@@ -532,32 +543,32 @@ static void fill_out_urb_mode_0(struct snd_usb_caiaqdev *dev,
532 int stream, i; 543 int stream, i;
533 544
534 for (i = 0; i < iso->length;) { 545 for (i = 0; i < iso->length;) {
535 for (stream = 0; stream < dev->n_streams; stream++, i++) { 546 for (stream = 0; stream < cdev->n_streams; stream++, i++) {
536 sub = dev->sub_playback[stream]; 547 sub = cdev->sub_playback[stream];
537 if (sub) { 548 if (sub) {
538 struct snd_pcm_runtime *rt = sub->runtime; 549 struct snd_pcm_runtime *rt = sub->runtime;
539 char *audio_buf = rt->dma_area; 550 char *audio_buf = rt->dma_area;
540 int sz = frames_to_bytes(rt, rt->buffer_size); 551 int sz = frames_to_bytes(rt, rt->buffer_size);
541 usb_buf[i] = 552 usb_buf[i] =
542 audio_buf[dev->audio_out_buf_pos[stream]]; 553 audio_buf[cdev->audio_out_buf_pos[stream]];
543 dev->period_out_count[stream]++; 554 cdev->period_out_count[stream]++;
544 dev->audio_out_buf_pos[stream]++; 555 cdev->audio_out_buf_pos[stream]++;
545 if (dev->audio_out_buf_pos[stream] == sz) 556 if (cdev->audio_out_buf_pos[stream] == sz)
546 dev->audio_out_buf_pos[stream] = 0; 557 cdev->audio_out_buf_pos[stream] = 0;
547 } else 558 } else
548 usb_buf[i] = 0; 559 usb_buf[i] = 0;
549 } 560 }
550 561
551 /* fill in the check bytes */ 562 /* fill in the check bytes */
552 if (dev->spec.data_alignment == 2 && 563 if (cdev->spec.data_alignment == 2 &&
553 i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 564 i % (cdev->n_streams * BYTES_PER_SAMPLE_USB) ==
554 (dev->n_streams * CHANNELS_PER_STREAM)) 565 (cdev->n_streams * CHANNELS_PER_STREAM))
555 for (stream = 0; stream < dev->n_streams; stream++, i++) 566 for (stream = 0; stream < cdev->n_streams; stream++, i++)
556 usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i); 567 usb_buf[i] = MAKE_CHECKBYTE(cdev, stream, i);
557 } 568 }
558} 569}
559 570
560static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *dev, 571static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *cdev,
561 struct urb *urb, 572 struct urb *urb,
562 const struct usb_iso_packet_descriptor *iso) 573 const struct usb_iso_packet_descriptor *iso)
563{ 574{
@@ -565,8 +576,8 @@ static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *dev,
565 int stream, i; 576 int stream, i;
566 577
567 for (i = 0; i < iso->length;) { 578 for (i = 0; i < iso->length;) {
568 for (stream = 0; stream < dev->n_streams; stream++) { 579 for (stream = 0; stream < cdev->n_streams; stream++) {
569 struct snd_pcm_substream *sub = dev->sub_playback[stream]; 580 struct snd_pcm_substream *sub = cdev->sub_playback[stream];
570 char *audio_buf = NULL; 581 char *audio_buf = NULL;
571 int c, n, sz = 0; 582 int c, n, sz = 0;
572 583
@@ -579,17 +590,17 @@ static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *dev,
579 for (c = 0; c < CHANNELS_PER_STREAM; c++) { 590 for (c = 0; c < CHANNELS_PER_STREAM; c++) {
580 for (n = 0; n < BYTES_PER_SAMPLE; n++) { 591 for (n = 0; n < BYTES_PER_SAMPLE; n++) {
581 if (audio_buf) { 592 if (audio_buf) {
582 usb_buf[i+n] = audio_buf[dev->audio_out_buf_pos[stream]++]; 593 usb_buf[i+n] = audio_buf[cdev->audio_out_buf_pos[stream]++];
583 594
584 if (dev->audio_out_buf_pos[stream] == sz) 595 if (cdev->audio_out_buf_pos[stream] == sz)
585 dev->audio_out_buf_pos[stream] = 0; 596 cdev->audio_out_buf_pos[stream] = 0;
586 } else { 597 } else {
587 usb_buf[i+n] = 0; 598 usb_buf[i+n] = 0;
588 } 599 }
589 } 600 }
590 601
591 if (audio_buf) 602 if (audio_buf)
592 dev->period_out_count[stream] += BYTES_PER_SAMPLE; 603 cdev->period_out_count[stream] += BYTES_PER_SAMPLE;
593 604
594 i += BYTES_PER_SAMPLE; 605 i += BYTES_PER_SAMPLE;
595 606
@@ -600,17 +611,17 @@ static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *dev,
600 } 611 }
601} 612}
602 613
603static inline void fill_out_urb(struct snd_usb_caiaqdev *dev, 614static inline void fill_out_urb(struct snd_usb_caiaqdev *cdev,
604 struct urb *urb, 615 struct urb *urb,
605 const struct usb_iso_packet_descriptor *iso) 616 const struct usb_iso_packet_descriptor *iso)
606{ 617{
607 switch (dev->spec.data_alignment) { 618 switch (cdev->spec.data_alignment) {
608 case 0: 619 case 0:
609 case 2: 620 case 2:
610 fill_out_urb_mode_0(dev, urb, iso); 621 fill_out_urb_mode_0(cdev, urb, iso);
611 break; 622 break;
612 case 3: 623 case 3:
613 fill_out_urb_mode_3(dev, urb, iso); 624 fill_out_urb_mode_3(cdev, urb, iso);
614 break; 625 break;
615 } 626 }
616} 627}
@@ -618,7 +629,8 @@ static inline void fill_out_urb(struct snd_usb_caiaqdev *dev,
618static void read_completed(struct urb *urb) 629static void read_completed(struct urb *urb)
619{ 630{
620 struct snd_usb_caiaq_cb_info *info = urb->context; 631 struct snd_usb_caiaq_cb_info *info = urb->context;
621 struct snd_usb_caiaqdev *dev; 632 struct snd_usb_caiaqdev *cdev;
633 struct device *dev;
622 struct urb *out = NULL; 634 struct urb *out = NULL;
623 int i, frame, len, send_it = 0, outframe = 0; 635 int i, frame, len, send_it = 0, outframe = 0;
624 size_t offset = 0; 636 size_t offset = 0;
@@ -626,20 +638,21 @@ static void read_completed(struct urb *urb)
626 if (urb->status || !info) 638 if (urb->status || !info)
627 return; 639 return;
628 640
629 dev = info->dev; 641 cdev = info->cdev;
642 dev = caiaqdev_to_dev(cdev);
630 643
631 if (!dev->streaming) 644 if (!cdev->streaming)
632 return; 645 return;
633 646
634 /* find an unused output urb that is unused */ 647 /* find an unused output urb that is unused */
635 for (i = 0; i < N_URBS; i++) 648 for (i = 0; i < N_URBS; i++)
636 if (test_and_set_bit(i, &dev->outurb_active_mask) == 0) { 649 if (test_and_set_bit(i, &cdev->outurb_active_mask) == 0) {
637 out = dev->data_urbs_out[i]; 650 out = cdev->data_urbs_out[i];
638 break; 651 break;
639 } 652 }
640 653
641 if (!out) { 654 if (!out) {
642 log("Unable to find an output urb to use\n"); 655 dev_err(dev, "Unable to find an output urb to use\n");
643 goto requeue; 656 goto requeue;
644 } 657 }
645 658
@@ -656,12 +669,12 @@ static void read_completed(struct urb *urb)
656 offset += len; 669 offset += len;
657 670
658 if (len > 0) { 671 if (len > 0) {
659 spin_lock(&dev->spinlock); 672 spin_lock(&cdev->spinlock);
660 fill_out_urb(dev, out, &out->iso_frame_desc[outframe]); 673 fill_out_urb(cdev, out, &out->iso_frame_desc[outframe]);
661 read_in_urb(dev, urb, &urb->iso_frame_desc[frame]); 674 read_in_urb(cdev, urb, &urb->iso_frame_desc[frame]);
662 spin_unlock(&dev->spinlock); 675 spin_unlock(&cdev->spinlock);
663 check_for_elapsed_periods(dev, dev->sub_playback); 676 check_for_elapsed_periods(cdev, cdev->sub_playback);
664 check_for_elapsed_periods(dev, dev->sub_capture); 677 check_for_elapsed_periods(cdev, cdev->sub_capture);
665 send_it = 1; 678 send_it = 1;
666 } 679 }
667 680
@@ -674,7 +687,7 @@ static void read_completed(struct urb *urb)
674 usb_submit_urb(out, GFP_ATOMIC); 687 usb_submit_urb(out, GFP_ATOMIC);
675 } else { 688 } else {
676 struct snd_usb_caiaq_cb_info *oinfo = out->context; 689 struct snd_usb_caiaq_cb_info *oinfo = out->context;
677 clear_bit(oinfo->index, &dev->outurb_active_mask); 690 clear_bit(oinfo->index, &cdev->outurb_active_mask);
678 } 691 }
679 692
680requeue: 693requeue:
@@ -693,21 +706,22 @@ requeue:
693static void write_completed(struct urb *urb) 706static void write_completed(struct urb *urb)
694{ 707{
695 struct snd_usb_caiaq_cb_info *info = urb->context; 708 struct snd_usb_caiaq_cb_info *info = urb->context;
696 struct snd_usb_caiaqdev *dev = info->dev; 709 struct snd_usb_caiaqdev *cdev = info->cdev;
697 710
698 if (!dev->output_running) { 711 if (!cdev->output_running) {
699 dev->output_running = 1; 712 cdev->output_running = 1;
700 wake_up(&dev->prepare_wait_queue); 713 wake_up(&cdev->prepare_wait_queue);
701 } 714 }
702 715
703 clear_bit(info->index, &dev->outurb_active_mask); 716 clear_bit(info->index, &cdev->outurb_active_mask);
704} 717}
705 718
706static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret) 719static struct urb **alloc_urbs(struct snd_usb_caiaqdev *cdev, int dir, int *ret)
707{ 720{
708 int i, frame; 721 int i, frame;
709 struct urb **urbs; 722 struct urb **urbs;
710 struct usb_device *usb_dev = dev->chip.dev; 723 struct usb_device *usb_dev = cdev->chip.dev;
724 struct device *dev = caiaqdev_to_dev(cdev);
711 unsigned int pipe; 725 unsigned int pipe;
712 726
713 pipe = (dir == SNDRV_PCM_STREAM_PLAYBACK) ? 727 pipe = (dir == SNDRV_PCM_STREAM_PLAYBACK) ?
@@ -716,7 +730,7 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret)
716 730
717 urbs = kmalloc(N_URBS * sizeof(*urbs), GFP_KERNEL); 731 urbs = kmalloc(N_URBS * sizeof(*urbs), GFP_KERNEL);
718 if (!urbs) { 732 if (!urbs) {
719 log("unable to kmalloc() urbs, OOM!?\n"); 733 dev_err(dev, "unable to kmalloc() urbs, OOM!?\n");
720 *ret = -ENOMEM; 734 *ret = -ENOMEM;
721 return NULL; 735 return NULL;
722 } 736 }
@@ -724,7 +738,7 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret)
724 for (i = 0; i < N_URBS; i++) { 738 for (i = 0; i < N_URBS; i++) {
725 urbs[i] = usb_alloc_urb(FRAMES_PER_URB, GFP_KERNEL); 739 urbs[i] = usb_alloc_urb(FRAMES_PER_URB, GFP_KERNEL);
726 if (!urbs[i]) { 740 if (!urbs[i]) {
727 log("unable to usb_alloc_urb(), OOM!?\n"); 741 dev_err(dev, "unable to usb_alloc_urb(), OOM!?\n");
728 *ret = -ENOMEM; 742 *ret = -ENOMEM;
729 return urbs; 743 return urbs;
730 } 744 }
@@ -732,7 +746,7 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret)
732 urbs[i]->transfer_buffer = 746 urbs[i]->transfer_buffer =
733 kmalloc(FRAMES_PER_URB * BYTES_PER_FRAME, GFP_KERNEL); 747 kmalloc(FRAMES_PER_URB * BYTES_PER_FRAME, GFP_KERNEL);
734 if (!urbs[i]->transfer_buffer) { 748 if (!urbs[i]->transfer_buffer) {
735 log("unable to kmalloc() transfer buffer, OOM!?\n"); 749 dev_err(dev, "unable to kmalloc() transfer buffer, OOM!?\n");
736 *ret = -ENOMEM; 750 *ret = -ENOMEM;
737 return urbs; 751 return urbs;
738 } 752 }
@@ -749,7 +763,7 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret)
749 urbs[i]->pipe = pipe; 763 urbs[i]->pipe = pipe;
750 urbs[i]->transfer_buffer_length = FRAMES_PER_URB 764 urbs[i]->transfer_buffer_length = FRAMES_PER_URB
751 * BYTES_PER_FRAME; 765 * BYTES_PER_FRAME;
752 urbs[i]->context = &dev->data_cb_info[i]; 766 urbs[i]->context = &cdev->data_cb_info[i];
753 urbs[i]->interval = 1; 767 urbs[i]->interval = 1;
754 urbs[i]->transfer_flags = URB_ISO_ASAP; 768 urbs[i]->transfer_flags = URB_ISO_ASAP;
755 urbs[i]->number_of_packets = FRAMES_PER_URB; 769 urbs[i]->number_of_packets = FRAMES_PER_URB;
@@ -780,110 +794,113 @@ static void free_urbs(struct urb **urbs)
780 kfree(urbs); 794 kfree(urbs);
781} 795}
782 796
783int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev) 797int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *cdev)
784{ 798{
785 int i, ret; 799 int i, ret;
800 struct device *dev = caiaqdev_to_dev(cdev);
786 801
787 dev->n_audio_in = max(dev->spec.num_analog_audio_in, 802 cdev->n_audio_in = max(cdev->spec.num_analog_audio_in,
788 dev->spec.num_digital_audio_in) / 803 cdev->spec.num_digital_audio_in) /
789 CHANNELS_PER_STREAM; 804 CHANNELS_PER_STREAM;
790 dev->n_audio_out = max(dev->spec.num_analog_audio_out, 805 cdev->n_audio_out = max(cdev->spec.num_analog_audio_out,
791 dev->spec.num_digital_audio_out) / 806 cdev->spec.num_digital_audio_out) /
792 CHANNELS_PER_STREAM; 807 CHANNELS_PER_STREAM;
793 dev->n_streams = max(dev->n_audio_in, dev->n_audio_out); 808 cdev->n_streams = max(cdev->n_audio_in, cdev->n_audio_out);
794 809
795 debug("dev->n_audio_in = %d\n", dev->n_audio_in); 810 dev_dbg(dev, "cdev->n_audio_in = %d\n", cdev->n_audio_in);
796 debug("dev->n_audio_out = %d\n", dev->n_audio_out); 811 dev_dbg(dev, "cdev->n_audio_out = %d\n", cdev->n_audio_out);
797 debug("dev->n_streams = %d\n", dev->n_streams); 812 dev_dbg(dev, "cdev->n_streams = %d\n", cdev->n_streams);
798 813
799 if (dev->n_streams > MAX_STREAMS) { 814 if (cdev->n_streams > MAX_STREAMS) {
800 log("unable to initialize device, too many streams.\n"); 815 dev_err(dev, "unable to initialize device, too many streams.\n");
801 return -EINVAL; 816 return -EINVAL;
802 } 817 }
803 818
804 ret = snd_pcm_new(dev->chip.card, dev->product_name, 0, 819 ret = snd_pcm_new(cdev->chip.card, cdev->product_name, 0,
805 dev->n_audio_out, dev->n_audio_in, &dev->pcm); 820 cdev->n_audio_out, cdev->n_audio_in, &cdev->pcm);
806 821
807 if (ret < 0) { 822 if (ret < 0) {
808 log("snd_pcm_new() returned %d\n", ret); 823 dev_err(dev, "snd_pcm_new() returned %d\n", ret);
809 return ret; 824 return ret;
810 } 825 }
811 826
812 dev->pcm->private_data = dev; 827 cdev->pcm->private_data = cdev;
813 strlcpy(dev->pcm->name, dev->product_name, sizeof(dev->pcm->name)); 828 strlcpy(cdev->pcm->name, cdev->product_name, sizeof(cdev->pcm->name));
814 829
815 memset(dev->sub_playback, 0, sizeof(dev->sub_playback)); 830 memset(cdev->sub_playback, 0, sizeof(cdev->sub_playback));
816 memset(dev->sub_capture, 0, sizeof(dev->sub_capture)); 831 memset(cdev->sub_capture, 0, sizeof(cdev->sub_capture));
817 832
818 memcpy(&dev->pcm_info, &snd_usb_caiaq_pcm_hardware, 833 memcpy(&cdev->pcm_info, &snd_usb_caiaq_pcm_hardware,
819 sizeof(snd_usb_caiaq_pcm_hardware)); 834 sizeof(snd_usb_caiaq_pcm_hardware));
820 835
821 /* setup samplerates */ 836 /* setup samplerates */
822 dev->samplerates = dev->pcm_info.rates; 837 cdev->samplerates = cdev->pcm_info.rates;
823 switch (dev->chip.usb_id) { 838 switch (cdev->chip.usb_id) {
824 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): 839 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
825 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): 840 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
826 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_SESSIONIO): 841 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_SESSIONIO):
827 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_GUITARRIGMOBILE): 842 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_GUITARRIGMOBILE):
828 dev->samplerates |= SNDRV_PCM_RATE_192000; 843 cdev->samplerates |= SNDRV_PCM_RATE_192000;
829 /* fall thru */ 844 /* fall thru */
830 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO2DJ): 845 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO2DJ):
831 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ): 846 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
832 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ): 847 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
833 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORAUDIO2): 848 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORAUDIO2):
834 dev->samplerates |= SNDRV_PCM_RATE_88200; 849 cdev->samplerates |= SNDRV_PCM_RATE_88200;
835 break; 850 break;
836 } 851 }
837 852
838 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_PLAYBACK, 853 snd_pcm_set_ops(cdev->pcm, SNDRV_PCM_STREAM_PLAYBACK,
839 &snd_usb_caiaq_ops); 854 &snd_usb_caiaq_ops);
840 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_CAPTURE, 855 snd_pcm_set_ops(cdev->pcm, SNDRV_PCM_STREAM_CAPTURE,
841 &snd_usb_caiaq_ops); 856 &snd_usb_caiaq_ops);
842 857
843 snd_pcm_lib_preallocate_pages_for_all(dev->pcm, 858 snd_pcm_lib_preallocate_pages_for_all(cdev->pcm,
844 SNDRV_DMA_TYPE_CONTINUOUS, 859 SNDRV_DMA_TYPE_CONTINUOUS,
845 snd_dma_continuous_data(GFP_KERNEL), 860 snd_dma_continuous_data(GFP_KERNEL),
846 MAX_BUFFER_SIZE, MAX_BUFFER_SIZE); 861 MAX_BUFFER_SIZE, MAX_BUFFER_SIZE);
847 862
848 dev->data_cb_info = 863 cdev->data_cb_info =
849 kmalloc(sizeof(struct snd_usb_caiaq_cb_info) * N_URBS, 864 kmalloc(sizeof(struct snd_usb_caiaq_cb_info) * N_URBS,
850 GFP_KERNEL); 865 GFP_KERNEL);
851 866
852 if (!dev->data_cb_info) 867 if (!cdev->data_cb_info)
853 return -ENOMEM; 868 return -ENOMEM;
854 869
855 dev->outurb_active_mask = 0; 870 cdev->outurb_active_mask = 0;
856 BUILD_BUG_ON(N_URBS > (sizeof(dev->outurb_active_mask) * 8)); 871 BUILD_BUG_ON(N_URBS > (sizeof(cdev->outurb_active_mask) * 8));
857 872
858 for (i = 0; i < N_URBS; i++) { 873 for (i = 0; i < N_URBS; i++) {
859 dev->data_cb_info[i].dev = dev; 874 cdev->data_cb_info[i].cdev = cdev;
860 dev->data_cb_info[i].index = i; 875 cdev->data_cb_info[i].index = i;
861 } 876 }
862 877
863 dev->data_urbs_in = alloc_urbs(dev, SNDRV_PCM_STREAM_CAPTURE, &ret); 878 cdev->data_urbs_in = alloc_urbs(cdev, SNDRV_PCM_STREAM_CAPTURE, &ret);
864 if (ret < 0) { 879 if (ret < 0) {
865 kfree(dev->data_cb_info); 880 kfree(cdev->data_cb_info);
866 free_urbs(dev->data_urbs_in); 881 free_urbs(cdev->data_urbs_in);
867 return ret; 882 return ret;
868 } 883 }
869 884
870 dev->data_urbs_out = alloc_urbs(dev, SNDRV_PCM_STREAM_PLAYBACK, &ret); 885 cdev->data_urbs_out = alloc_urbs(cdev, SNDRV_PCM_STREAM_PLAYBACK, &ret);
871 if (ret < 0) { 886 if (ret < 0) {
872 kfree(dev->data_cb_info); 887 kfree(cdev->data_cb_info);
873 free_urbs(dev->data_urbs_in); 888 free_urbs(cdev->data_urbs_in);
874 free_urbs(dev->data_urbs_out); 889 free_urbs(cdev->data_urbs_out);
875 return ret; 890 return ret;
876 } 891 }
877 892
878 return 0; 893 return 0;
879} 894}
880 895
881void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *dev) 896void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *cdev)
882{ 897{
883 debug("%s(%p)\n", __func__, dev); 898 struct device *dev = caiaqdev_to_dev(cdev);
884 stream_stop(dev); 899
885 free_urbs(dev->data_urbs_in); 900 dev_dbg(dev, "%s(%p)\n", __func__, cdev);
886 free_urbs(dev->data_urbs_out); 901 stream_stop(cdev);
887 kfree(dev->data_cb_info); 902 free_urbs(cdev->data_urbs_in);
903 free_urbs(cdev->data_urbs_out);
904 kfree(cdev->data_cb_info);
888} 905}
889 906
diff --git a/sound/usb/caiaq/audio.h b/sound/usb/caiaq/audio.h
index 8ab1f8d9529e..bdf155300a8a 100644
--- a/sound/usb/caiaq/audio.h
+++ b/sound/usb/caiaq/audio.h
@@ -1,7 +1,7 @@
1#ifndef CAIAQ_AUDIO_H 1#ifndef CAIAQ_AUDIO_H
2#define CAIAQ_AUDIO_H 2#define CAIAQ_AUDIO_H
3 3
4int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev); 4int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *cdev);
5void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *dev); 5void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *cdev);
6 6
7#endif /* CAIAQ_AUDIO_H */ 7#endif /* CAIAQ_AUDIO_H */
diff --git a/sound/usb/caiaq/control.c b/sound/usb/caiaq/control.c
index adb8d03267a0..ae6b50f9ed56 100644
--- a/sound/usb/caiaq/control.c
+++ b/sound/usb/caiaq/control.c
@@ -17,6 +17,7 @@
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 19
20#include <linux/device.h>
20#include <linux/init.h> 21#include <linux/init.h>
21#include <linux/usb.h> 22#include <linux/usb.h>
22#include <sound/control.h> 23#include <sound/control.h>
@@ -32,7 +33,7 @@ static int control_info(struct snd_kcontrol *kcontrol,
32 struct snd_ctl_elem_info *uinfo) 33 struct snd_ctl_elem_info *uinfo)
33{ 34{
34 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol); 35 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
35 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card); 36 struct snd_usb_caiaqdev *cdev = caiaqdev(chip->card);
36 int pos = kcontrol->private_value; 37 int pos = kcontrol->private_value;
37 int is_intval = pos & CNT_INTVAL; 38 int is_intval = pos & CNT_INTVAL;
38 int maxval = 63; 39 int maxval = 63;
@@ -40,7 +41,7 @@ static int control_info(struct snd_kcontrol *kcontrol,
40 uinfo->count = 1; 41 uinfo->count = 1;
41 pos &= ~CNT_INTVAL; 42 pos &= ~CNT_INTVAL;
42 43
43 switch (dev->chip.usb_id) { 44 switch (cdev->chip.usb_id) {
44 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ): 45 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
45 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ): 46 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
46 if (pos == 0) { 47 if (pos == 0) {
@@ -78,15 +79,15 @@ static int control_get(struct snd_kcontrol *kcontrol,
78 struct snd_ctl_elem_value *ucontrol) 79 struct snd_ctl_elem_value *ucontrol)
79{ 80{
80 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol); 81 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
81 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card); 82 struct snd_usb_caiaqdev *cdev = caiaqdev(chip->card);
82 int pos = kcontrol->private_value; 83 int pos = kcontrol->private_value;
83 84
84 if (pos & CNT_INTVAL) 85 if (pos & CNT_INTVAL)
85 ucontrol->value.integer.value[0] 86 ucontrol->value.integer.value[0]
86 = dev->control_state[pos & ~CNT_INTVAL]; 87 = cdev->control_state[pos & ~CNT_INTVAL];
87 else 88 else
88 ucontrol->value.integer.value[0] 89 ucontrol->value.integer.value[0]
89 = !!(dev->control_state[pos / 8] & (1 << pos % 8)); 90 = !!(cdev->control_state[pos / 8] & (1 << pos % 8));
90 91
91 return 0; 92 return 0;
92} 93}
@@ -95,43 +96,43 @@ static int control_put(struct snd_kcontrol *kcontrol,
95 struct snd_ctl_elem_value *ucontrol) 96 struct snd_ctl_elem_value *ucontrol)
96{ 97{
97 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol); 98 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
98 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card); 99 struct snd_usb_caiaqdev *cdev = caiaqdev(chip->card);
99 int pos = kcontrol->private_value; 100 int pos = kcontrol->private_value;
100 int v = ucontrol->value.integer.value[0]; 101 int v = ucontrol->value.integer.value[0];
101 unsigned char cmd = EP1_CMD_WRITE_IO; 102 unsigned char cmd = EP1_CMD_WRITE_IO;
102 103
103 if (dev->chip.usb_id == 104 if (cdev->chip.usb_id ==
104 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1)) 105 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1))
105 cmd = EP1_CMD_DIMM_LEDS; 106 cmd = EP1_CMD_DIMM_LEDS;
106 107
107 if (pos & CNT_INTVAL) { 108 if (pos & CNT_INTVAL) {
108 int i = pos & ~CNT_INTVAL; 109 int i = pos & ~CNT_INTVAL;
109 110
110 dev->control_state[i] = v; 111 cdev->control_state[i] = v;
111 112
112 if (dev->chip.usb_id == 113 if (cdev->chip.usb_id ==
113 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4)) { 114 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4)) {
114 int actual_len; 115 int actual_len;
115 116
116 dev->ep8_out_buf[0] = i; 117 cdev->ep8_out_buf[0] = i;
117 dev->ep8_out_buf[1] = v; 118 cdev->ep8_out_buf[1] = v;
118 119
119 usb_bulk_msg(dev->chip.dev, 120 usb_bulk_msg(cdev->chip.dev,
120 usb_sndbulkpipe(dev->chip.dev, 8), 121 usb_sndbulkpipe(cdev->chip.dev, 8),
121 dev->ep8_out_buf, sizeof(dev->ep8_out_buf), 122 cdev->ep8_out_buf, sizeof(cdev->ep8_out_buf),
122 &actual_len, 200); 123 &actual_len, 200);
123 } else { 124 } else {
124 snd_usb_caiaq_send_command(dev, cmd, 125 snd_usb_caiaq_send_command(cdev, cmd,
125 dev->control_state, sizeof(dev->control_state)); 126 cdev->control_state, sizeof(cdev->control_state));
126 } 127 }
127 } else { 128 } else {
128 if (v) 129 if (v)
129 dev->control_state[pos / 8] |= 1 << (pos % 8); 130 cdev->control_state[pos / 8] |= 1 << (pos % 8);
130 else 131 else
131 dev->control_state[pos / 8] &= ~(1 << (pos % 8)); 132 cdev->control_state[pos / 8] &= ~(1 << (pos % 8));
132 133
133 snd_usb_caiaq_send_command(dev, cmd, 134 snd_usb_caiaq_send_command(cdev, cmd,
134 dev->control_state, sizeof(dev->control_state)); 135 cdev->control_state, sizeof(cdev->control_state));
135 } 136 }
136 137
137 return 1; 138 return 1;
@@ -490,7 +491,7 @@ static struct caiaq_controller kontrols4_controller[] = {
490}; 491};
491 492
492static int add_controls(struct caiaq_controller *c, int num, 493static int add_controls(struct caiaq_controller *c, int num,
493 struct snd_usb_caiaqdev *dev) 494 struct snd_usb_caiaqdev *cdev)
494{ 495{
495 int i, ret; 496 int i, ret;
496 struct snd_kcontrol *kc; 497 struct snd_kcontrol *kc;
@@ -498,8 +499,8 @@ static int add_controls(struct caiaq_controller *c, int num,
498 for (i = 0; i < num; i++, c++) { 499 for (i = 0; i < num; i++, c++) {
499 kcontrol_template.name = c->name; 500 kcontrol_template.name = c->name;
500 kcontrol_template.private_value = c->index; 501 kcontrol_template.private_value = c->index;
501 kc = snd_ctl_new1(&kcontrol_template, dev); 502 kc = snd_ctl_new1(&kcontrol_template, cdev);
502 ret = snd_ctl_add(dev->chip.card, kc); 503 ret = snd_ctl_add(cdev->chip.card, kc);
503 if (ret < 0) 504 if (ret < 0)
504 return ret; 505 return ret;
505 } 506 }
@@ -507,50 +508,50 @@ static int add_controls(struct caiaq_controller *c, int num,
507 return 0; 508 return 0;
508} 509}
509 510
510int snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *dev) 511int snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *cdev)
511{ 512{
512 int ret = 0; 513 int ret = 0;
513 514
514 switch (dev->chip.usb_id) { 515 switch (cdev->chip.usb_id) {
515 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): 516 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
516 ret = add_controls(ak1_controller, 517 ret = add_controls(ak1_controller,
517 ARRAY_SIZE(ak1_controller), dev); 518 ARRAY_SIZE(ak1_controller), cdev);
518 break; 519 break;
519 520
520 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): 521 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
521 ret = add_controls(rk2_controller, 522 ret = add_controls(rk2_controller,
522 ARRAY_SIZE(rk2_controller), dev); 523 ARRAY_SIZE(rk2_controller), cdev);
523 break; 524 break;
524 525
525 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): 526 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
526 ret = add_controls(rk3_controller, 527 ret = add_controls(rk3_controller,
527 ARRAY_SIZE(rk3_controller), dev); 528 ARRAY_SIZE(rk3_controller), cdev);
528 break; 529 break;
529 530
530 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): 531 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
531 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): 532 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
532 ret = add_controls(kore_controller, 533 ret = add_controls(kore_controller,
533 ARRAY_SIZE(kore_controller), dev); 534 ARRAY_SIZE(kore_controller), cdev);
534 break; 535 break;
535 536
536 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ): 537 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
537 ret = add_controls(a8dj_controller, 538 ret = add_controls(a8dj_controller,
538 ARRAY_SIZE(a8dj_controller), dev); 539 ARRAY_SIZE(a8dj_controller), cdev);
539 break; 540 break;
540 541
541 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ): 542 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
542 ret = add_controls(a4dj_controller, 543 ret = add_controls(a4dj_controller,
543 ARRAY_SIZE(a4dj_controller), dev); 544 ARRAY_SIZE(a4dj_controller), cdev);
544 break; 545 break;
545 546
546 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 547 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
547 ret = add_controls(kontrolx1_controller, 548 ret = add_controls(kontrolx1_controller,
548 ARRAY_SIZE(kontrolx1_controller), dev); 549 ARRAY_SIZE(kontrolx1_controller), cdev);
549 break; 550 break;
550 551
551 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): 552 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
552 ret = add_controls(kontrols4_controller, 553 ret = add_controls(kontrols4_controller,
553 ARRAY_SIZE(kontrols4_controller), dev); 554 ARRAY_SIZE(kontrols4_controller), cdev);
554 break; 555 break;
555 } 556 }
556 557
diff --git a/sound/usb/caiaq/control.h b/sound/usb/caiaq/control.h
index 2e7ab1aa4fb3..501c4883aef6 100644
--- a/sound/usb/caiaq/control.h
+++ b/sound/usb/caiaq/control.h
@@ -1,6 +1,6 @@
1#ifndef CAIAQ_CONTROL_H 1#ifndef CAIAQ_CONTROL_H
2#define CAIAQ_CONTROL_H 2#define CAIAQ_CONTROL_H
3 3
4int snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *dev); 4int snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *cdev);
5 5
6#endif /* CAIAQ_CONTROL_H */ 6#endif /* CAIAQ_CONTROL_H */
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index e4d6dbb0342d..48b63ccc78c7 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -20,6 +20,7 @@
20*/ 20*/
21 21
22#include <linux/moduleparam.h> 22#include <linux/moduleparam.h>
23#include <linux/device.h>
23#include <linux/interrupt.h> 24#include <linux/interrupt.h>
24#include <linux/module.h> 25#include <linux/module.h>
25#include <linux/init.h> 26#include <linux/init.h>
@@ -158,67 +159,68 @@ static struct usb_device_id snd_usb_id_table[] = {
158static void usb_ep1_command_reply_dispatch (struct urb* urb) 159static void usb_ep1_command_reply_dispatch (struct urb* urb)
159{ 160{
160 int ret; 161 int ret;
161 struct snd_usb_caiaqdev *dev = urb->context; 162 struct device *dev = &urb->dev->dev;
163 struct snd_usb_caiaqdev *cdev = urb->context;
162 unsigned char *buf = urb->transfer_buffer; 164 unsigned char *buf = urb->transfer_buffer;
163 165
164 if (urb->status || !dev) { 166 if (urb->status || !cdev) {
165 log("received EP1 urb->status = %i\n", urb->status); 167 dev_warn(dev, "received EP1 urb->status = %i\n", urb->status);
166 return; 168 return;
167 } 169 }
168 170
169 switch(buf[0]) { 171 switch(buf[0]) {
170 case EP1_CMD_GET_DEVICE_INFO: 172 case EP1_CMD_GET_DEVICE_INFO:
171 memcpy(&dev->spec, buf+1, sizeof(struct caiaq_device_spec)); 173 memcpy(&cdev->spec, buf+1, sizeof(struct caiaq_device_spec));
172 dev->spec.fw_version = le16_to_cpu(dev->spec.fw_version); 174 cdev->spec.fw_version = le16_to_cpu(cdev->spec.fw_version);
173 debug("device spec (firmware %d): audio: %d in, %d out, " 175 dev_dbg(dev, "device spec (firmware %d): audio: %d in, %d out, "
174 "MIDI: %d in, %d out, data alignment %d\n", 176 "MIDI: %d in, %d out, data alignment %d\n",
175 dev->spec.fw_version, 177 cdev->spec.fw_version,
176 dev->spec.num_analog_audio_in, 178 cdev->spec.num_analog_audio_in,
177 dev->spec.num_analog_audio_out, 179 cdev->spec.num_analog_audio_out,
178 dev->spec.num_midi_in, 180 cdev->spec.num_midi_in,
179 dev->spec.num_midi_out, 181 cdev->spec.num_midi_out,
180 dev->spec.data_alignment); 182 cdev->spec.data_alignment);
181 183
182 dev->spec_received++; 184 cdev->spec_received++;
183 wake_up(&dev->ep1_wait_queue); 185 wake_up(&cdev->ep1_wait_queue);
184 break; 186 break;
185 case EP1_CMD_AUDIO_PARAMS: 187 case EP1_CMD_AUDIO_PARAMS:
186 dev->audio_parm_answer = buf[1]; 188 cdev->audio_parm_answer = buf[1];
187 wake_up(&dev->ep1_wait_queue); 189 wake_up(&cdev->ep1_wait_queue);
188 break; 190 break;
189 case EP1_CMD_MIDI_READ: 191 case EP1_CMD_MIDI_READ:
190 snd_usb_caiaq_midi_handle_input(dev, buf[1], buf + 3, buf[2]); 192 snd_usb_caiaq_midi_handle_input(cdev, buf[1], buf + 3, buf[2]);
191 break; 193 break;
192 case EP1_CMD_READ_IO: 194 case EP1_CMD_READ_IO:
193 if (dev->chip.usb_id == 195 if (cdev->chip.usb_id ==
194 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ)) { 196 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ)) {
195 if (urb->actual_length > sizeof(dev->control_state)) 197 if (urb->actual_length > sizeof(cdev->control_state))
196 urb->actual_length = sizeof(dev->control_state); 198 urb->actual_length = sizeof(cdev->control_state);
197 memcpy(dev->control_state, buf + 1, urb->actual_length); 199 memcpy(cdev->control_state, buf + 1, urb->actual_length);
198 wake_up(&dev->ep1_wait_queue); 200 wake_up(&cdev->ep1_wait_queue);
199 break; 201 break;
200 } 202 }
201#ifdef CONFIG_SND_USB_CAIAQ_INPUT 203#ifdef CONFIG_SND_USB_CAIAQ_INPUT
202 case EP1_CMD_READ_ERP: 204 case EP1_CMD_READ_ERP:
203 case EP1_CMD_READ_ANALOG: 205 case EP1_CMD_READ_ANALOG:
204 snd_usb_caiaq_input_dispatch(dev, buf, urb->actual_length); 206 snd_usb_caiaq_input_dispatch(cdev, buf, urb->actual_length);
205#endif 207#endif
206 break; 208 break;
207 } 209 }
208 210
209 dev->ep1_in_urb.actual_length = 0; 211 cdev->ep1_in_urb.actual_length = 0;
210 ret = usb_submit_urb(&dev->ep1_in_urb, GFP_ATOMIC); 212 ret = usb_submit_urb(&cdev->ep1_in_urb, GFP_ATOMIC);
211 if (ret < 0) 213 if (ret < 0)
212 log("unable to submit urb. OOM!?\n"); 214 dev_err(dev, "unable to submit urb. OOM!?\n");
213} 215}
214 216
215int snd_usb_caiaq_send_command(struct snd_usb_caiaqdev *dev, 217int snd_usb_caiaq_send_command(struct snd_usb_caiaqdev *cdev,
216 unsigned char command, 218 unsigned char command,
217 const unsigned char *buffer, 219 const unsigned char *buffer,
218 int len) 220 int len)
219{ 221{
220 int actual_len; 222 int actual_len;
221 struct usb_device *usb_dev = dev->chip.dev; 223 struct usb_device *usb_dev = cdev->chip.dev;
222 224
223 if (!usb_dev) 225 if (!usb_dev)
224 return -EIO; 226 return -EIO;
@@ -227,18 +229,19 @@ int snd_usb_caiaq_send_command(struct snd_usb_caiaqdev *dev,
227 len = EP1_BUFSIZE - 1; 229 len = EP1_BUFSIZE - 1;
228 230
229 if (buffer && len > 0) 231 if (buffer && len > 0)
230 memcpy(dev->ep1_out_buf+1, buffer, len); 232 memcpy(cdev->ep1_out_buf+1, buffer, len);
231 233
232 dev->ep1_out_buf[0] = command; 234 cdev->ep1_out_buf[0] = command;
233 return usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, 1), 235 return usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, 1),
234 dev->ep1_out_buf, len+1, &actual_len, 200); 236 cdev->ep1_out_buf, len+1, &actual_len, 200);
235} 237}
236 238
237int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *dev, 239int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *cdev,
238 int rate, int depth, int bpp) 240 int rate, int depth, int bpp)
239{ 241{
240 int ret; 242 int ret;
241 char tmp[5]; 243 char tmp[5];
244 struct device *dev = caiaqdev_to_dev(cdev);
242 245
243 switch (rate) { 246 switch (rate) {
244 case 44100: tmp[0] = SAMPLERATE_44100; break; 247 case 44100: tmp[0] = SAMPLERATE_44100; break;
@@ -259,49 +262,50 @@ int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *dev,
259 tmp[3] = bpp >> 8; 262 tmp[3] = bpp >> 8;
260 tmp[4] = 1; /* packets per microframe */ 263 tmp[4] = 1; /* packets per microframe */
261 264
262 debug("setting audio params: %d Hz, %d bits, %d bpp\n", 265 dev_dbg(dev, "setting audio params: %d Hz, %d bits, %d bpp\n",
263 rate, depth, bpp); 266 rate, depth, bpp);
264 267
265 dev->audio_parm_answer = -1; 268 cdev->audio_parm_answer = -1;
266 ret = snd_usb_caiaq_send_command(dev, EP1_CMD_AUDIO_PARAMS, 269 ret = snd_usb_caiaq_send_command(cdev, EP1_CMD_AUDIO_PARAMS,
267 tmp, sizeof(tmp)); 270 tmp, sizeof(tmp));
268 271
269 if (ret) 272 if (ret)
270 return ret; 273 return ret;
271 274
272 if (!wait_event_timeout(dev->ep1_wait_queue, 275 if (!wait_event_timeout(cdev->ep1_wait_queue,
273 dev->audio_parm_answer >= 0, HZ)) 276 cdev->audio_parm_answer >= 0, HZ))
274 return -EPIPE; 277 return -EPIPE;
275 278
276 if (dev->audio_parm_answer != 1) 279 if (cdev->audio_parm_answer != 1)
277 debug("unable to set the device's audio params\n"); 280 dev_dbg(dev, "unable to set the device's audio params\n");
278 else 281 else
279 dev->bpp = bpp; 282 cdev->bpp = bpp;
280 283
281 return dev->audio_parm_answer == 1 ? 0 : -EINVAL; 284 return cdev->audio_parm_answer == 1 ? 0 : -EINVAL;
282} 285}
283 286
284int snd_usb_caiaq_set_auto_msg(struct snd_usb_caiaqdev *dev, 287int snd_usb_caiaq_set_auto_msg(struct snd_usb_caiaqdev *cdev,
285 int digital, int analog, int erp) 288 int digital, int analog, int erp)
286{ 289{
287 char tmp[3] = { digital, analog, erp }; 290 char tmp[3] = { digital, analog, erp };
288 return snd_usb_caiaq_send_command(dev, EP1_CMD_AUTO_MSG, 291 return snd_usb_caiaq_send_command(cdev, EP1_CMD_AUTO_MSG,
289 tmp, sizeof(tmp)); 292 tmp, sizeof(tmp));
290} 293}
291 294
292static void setup_card(struct snd_usb_caiaqdev *dev) 295static void setup_card(struct snd_usb_caiaqdev *cdev)
293{ 296{
294 int ret; 297 int ret;
295 char val[4]; 298 char val[4];
299 struct device *dev = caiaqdev_to_dev(cdev);
296 300
297 /* device-specific startup specials */ 301 /* device-specific startup specials */
298 switch (dev->chip.usb_id) { 302 switch (cdev->chip.usb_id) {
299 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): 303 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
300 /* RigKontrol2 - display centered dash ('-') */ 304 /* RigKontrol2 - display centered dash ('-') */
301 val[0] = 0x00; 305 val[0] = 0x00;
302 val[1] = 0x00; 306 val[1] = 0x00;
303 val[2] = 0x01; 307 val[2] = 0x01;
304 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO, val, 3); 308 snd_usb_caiaq_send_command(cdev, EP1_CMD_WRITE_IO, val, 3);
305 break; 309 break;
306 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): 310 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
307 /* RigKontrol2 - display two centered dashes ('--') */ 311 /* RigKontrol2 - display two centered dashes ('--') */
@@ -309,69 +313,69 @@ static void setup_card(struct snd_usb_caiaqdev *dev)
309 val[1] = 0x40; 313 val[1] = 0x40;
310 val[2] = 0x40; 314 val[2] = 0x40;
311 val[3] = 0x00; 315 val[3] = 0x00;
312 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO, val, 4); 316 snd_usb_caiaq_send_command(cdev, EP1_CMD_WRITE_IO, val, 4);
313 break; 317 break;
314 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): 318 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
315 /* Audio Kontrol 1 - make USB-LED stop blinking */ 319 /* Audio Kontrol 1 - make USB-LED stop blinking */
316 val[0] = 0x00; 320 val[0] = 0x00;
317 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO, val, 1); 321 snd_usb_caiaq_send_command(cdev, EP1_CMD_WRITE_IO, val, 1);
318 break; 322 break;
319 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ): 323 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
320 /* Audio 8 DJ - trigger read of current settings */ 324 /* Audio 8 DJ - trigger read of current settings */
321 dev->control_state[0] = 0xff; 325 cdev->control_state[0] = 0xff;
322 snd_usb_caiaq_set_auto_msg(dev, 1, 0, 0); 326 snd_usb_caiaq_set_auto_msg(cdev, 1, 0, 0);
323 snd_usb_caiaq_send_command(dev, EP1_CMD_READ_IO, NULL, 0); 327 snd_usb_caiaq_send_command(cdev, EP1_CMD_READ_IO, NULL, 0);
324 328
325 if (!wait_event_timeout(dev->ep1_wait_queue, 329 if (!wait_event_timeout(cdev->ep1_wait_queue,
326 dev->control_state[0] != 0xff, HZ)) 330 cdev->control_state[0] != 0xff, HZ))
327 return; 331 return;
328 332
329 /* fix up some defaults */ 333 /* fix up some defaults */
330 if ((dev->control_state[1] != 2) || 334 if ((cdev->control_state[1] != 2) ||
331 (dev->control_state[2] != 3) || 335 (cdev->control_state[2] != 3) ||
332 (dev->control_state[4] != 2)) { 336 (cdev->control_state[4] != 2)) {
333 dev->control_state[1] = 2; 337 cdev->control_state[1] = 2;
334 dev->control_state[2] = 3; 338 cdev->control_state[2] = 3;
335 dev->control_state[4] = 2; 339 cdev->control_state[4] = 2;
336 snd_usb_caiaq_send_command(dev, 340 snd_usb_caiaq_send_command(cdev,
337 EP1_CMD_WRITE_IO, dev->control_state, 6); 341 EP1_CMD_WRITE_IO, cdev->control_state, 6);
338 } 342 }
339 343
340 break; 344 break;
341 } 345 }
342 346
343 if (dev->spec.num_analog_audio_out + 347 if (cdev->spec.num_analog_audio_out +
344 dev->spec.num_analog_audio_in + 348 cdev->spec.num_analog_audio_in +
345 dev->spec.num_digital_audio_out + 349 cdev->spec.num_digital_audio_out +
346 dev->spec.num_digital_audio_in > 0) { 350 cdev->spec.num_digital_audio_in > 0) {
347 ret = snd_usb_caiaq_audio_init(dev); 351 ret = snd_usb_caiaq_audio_init(cdev);
348 if (ret < 0) 352 if (ret < 0)
349 log("Unable to set up audio system (ret=%d)\n", ret); 353 dev_err(dev, "Unable to set up audio system (ret=%d)\n", ret);
350 } 354 }
351 355
352 if (dev->spec.num_midi_in + 356 if (cdev->spec.num_midi_in +
353 dev->spec.num_midi_out > 0) { 357 cdev->spec.num_midi_out > 0) {
354 ret = snd_usb_caiaq_midi_init(dev); 358 ret = snd_usb_caiaq_midi_init(cdev);
355 if (ret < 0) 359 if (ret < 0)
356 log("Unable to set up MIDI system (ret=%d)\n", ret); 360 dev_err(dev, "Unable to set up MIDI system (ret=%d)\n", ret);
357 } 361 }
358 362
359#ifdef CONFIG_SND_USB_CAIAQ_INPUT 363#ifdef CONFIG_SND_USB_CAIAQ_INPUT
360 ret = snd_usb_caiaq_input_init(dev); 364 ret = snd_usb_caiaq_input_init(cdev);
361 if (ret < 0) 365 if (ret < 0)
362 log("Unable to set up input system (ret=%d)\n", ret); 366 dev_err(dev, "Unable to set up input system (ret=%d)\n", ret);
363#endif 367#endif
364 368
365 /* finally, register the card and all its sub-instances */ 369 /* finally, register the card and all its sub-instances */
366 ret = snd_card_register(dev->chip.card); 370 ret = snd_card_register(cdev->chip.card);
367 if (ret < 0) { 371 if (ret < 0) {
368 log("snd_card_register() returned %d\n", ret); 372 dev_err(dev, "snd_card_register() returned %d\n", ret);
369 snd_card_free(dev->chip.card); 373 snd_card_free(cdev->chip.card);
370 } 374 }
371 375
372 ret = snd_usb_caiaq_control_init(dev); 376 ret = snd_usb_caiaq_control_init(cdev);
373 if (ret < 0) 377 if (ret < 0)
374 log("Unable to set up control system (ret=%d)\n", ret); 378 dev_err(dev, "Unable to set up control system (ret=%d)\n", ret);
375} 379}
376 380
377static int create_card(struct usb_device *usb_dev, 381static int create_card(struct usb_device *usb_dev,
@@ -381,7 +385,7 @@ static int create_card(struct usb_device *usb_dev,
381 int devnum; 385 int devnum;
382 int err; 386 int err;
383 struct snd_card *card; 387 struct snd_card *card;
384 struct snd_usb_caiaqdev *dev; 388 struct snd_usb_caiaqdev *cdev;
385 389
386 for (devnum = 0; devnum < SNDRV_CARDS; devnum++) 390 for (devnum = 0; devnum < SNDRV_CARDS; devnum++)
387 if (enable[devnum] && !snd_card_used[devnum]) 391 if (enable[devnum] && !snd_card_used[devnum])
@@ -395,65 +399,66 @@ static int create_card(struct usb_device *usb_dev,
395 if (err < 0) 399 if (err < 0)
396 return err; 400 return err;
397 401
398 dev = caiaqdev(card); 402 cdev = caiaqdev(card);
399 dev->chip.dev = usb_dev; 403 cdev->chip.dev = usb_dev;
400 dev->chip.card = card; 404 cdev->chip.card = card;
401 dev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor), 405 cdev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor),
402 le16_to_cpu(usb_dev->descriptor.idProduct)); 406 le16_to_cpu(usb_dev->descriptor.idProduct));
403 spin_lock_init(&dev->spinlock); 407 spin_lock_init(&cdev->spinlock);
404 snd_card_set_dev(card, &intf->dev); 408 snd_card_set_dev(card, &intf->dev);
405 409
406 *cardp = card; 410 *cardp = card;
407 return 0; 411 return 0;
408} 412}
409 413
410static int init_card(struct snd_usb_caiaqdev *dev) 414static int init_card(struct snd_usb_caiaqdev *cdev)
411{ 415{
412 char *c, usbpath[32]; 416 char *c, usbpath[32];
413 struct usb_device *usb_dev = dev->chip.dev; 417 struct usb_device *usb_dev = cdev->chip.dev;
414 struct snd_card *card = dev->chip.card; 418 struct snd_card *card = cdev->chip.card;
419 struct device *dev = caiaqdev_to_dev(cdev);
415 int err, len; 420 int err, len;
416 421
417 if (usb_set_interface(usb_dev, 0, 1) != 0) { 422 if (usb_set_interface(usb_dev, 0, 1) != 0) {
418 log("can't set alt interface.\n"); 423 dev_err(dev, "can't set alt interface.\n");
419 return -EIO; 424 return -EIO;
420 } 425 }
421 426
422 usb_init_urb(&dev->ep1_in_urb); 427 usb_init_urb(&cdev->ep1_in_urb);
423 usb_init_urb(&dev->midi_out_urb); 428 usb_init_urb(&cdev->midi_out_urb);
424 429
425 usb_fill_bulk_urb(&dev->ep1_in_urb, usb_dev, 430 usb_fill_bulk_urb(&cdev->ep1_in_urb, usb_dev,
426 usb_rcvbulkpipe(usb_dev, 0x1), 431 usb_rcvbulkpipe(usb_dev, 0x1),
427 dev->ep1_in_buf, EP1_BUFSIZE, 432 cdev->ep1_in_buf, EP1_BUFSIZE,
428 usb_ep1_command_reply_dispatch, dev); 433 usb_ep1_command_reply_dispatch, cdev);
429 434
430 usb_fill_bulk_urb(&dev->midi_out_urb, usb_dev, 435 usb_fill_bulk_urb(&cdev->midi_out_urb, usb_dev,
431 usb_sndbulkpipe(usb_dev, 0x1), 436 usb_sndbulkpipe(usb_dev, 0x1),
432 dev->midi_out_buf, EP1_BUFSIZE, 437 cdev->midi_out_buf, EP1_BUFSIZE,
433 snd_usb_caiaq_midi_output_done, dev); 438 snd_usb_caiaq_midi_output_done, cdev);
434 439
435 init_waitqueue_head(&dev->ep1_wait_queue); 440 init_waitqueue_head(&cdev->ep1_wait_queue);
436 init_waitqueue_head(&dev->prepare_wait_queue); 441 init_waitqueue_head(&cdev->prepare_wait_queue);
437 442
438 if (usb_submit_urb(&dev->ep1_in_urb, GFP_KERNEL) != 0) 443 if (usb_submit_urb(&cdev->ep1_in_urb, GFP_KERNEL) != 0)
439 return -EIO; 444 return -EIO;
440 445
441 err = snd_usb_caiaq_send_command(dev, EP1_CMD_GET_DEVICE_INFO, NULL, 0); 446 err = snd_usb_caiaq_send_command(cdev, EP1_CMD_GET_DEVICE_INFO, NULL, 0);
442 if (err) 447 if (err)
443 return err; 448 return err;
444 449
445 if (!wait_event_timeout(dev->ep1_wait_queue, dev->spec_received, HZ)) 450 if (!wait_event_timeout(cdev->ep1_wait_queue, cdev->spec_received, HZ))
446 return -ENODEV; 451 return -ENODEV;
447 452
448 usb_string(usb_dev, usb_dev->descriptor.iManufacturer, 453 usb_string(usb_dev, usb_dev->descriptor.iManufacturer,
449 dev->vendor_name, CAIAQ_USB_STR_LEN); 454 cdev->vendor_name, CAIAQ_USB_STR_LEN);
450 455
451 usb_string(usb_dev, usb_dev->descriptor.iProduct, 456 usb_string(usb_dev, usb_dev->descriptor.iProduct,
452 dev->product_name, CAIAQ_USB_STR_LEN); 457 cdev->product_name, CAIAQ_USB_STR_LEN);
453 458
454 strlcpy(card->driver, MODNAME, sizeof(card->driver)); 459 strlcpy(card->driver, MODNAME, sizeof(card->driver));
455 strlcpy(card->shortname, dev->product_name, sizeof(card->shortname)); 460 strlcpy(card->shortname, cdev->product_name, sizeof(card->shortname));
456 strlcpy(card->mixername, dev->product_name, sizeof(card->mixername)); 461 strlcpy(card->mixername, cdev->product_name, sizeof(card->mixername));
457 462
458 /* if the id was not passed as module option, fill it with a shortened 463 /* if the id was not passed as module option, fill it with a shortened
459 * version of the product string which does not contain any 464 * version of the product string which does not contain any
@@ -473,11 +478,10 @@ static int init_card(struct snd_usb_caiaqdev *dev)
473 } 478 }
474 479
475 usb_make_path(usb_dev, usbpath, sizeof(usbpath)); 480 usb_make_path(usb_dev, usbpath, sizeof(usbpath));
476 snprintf(card->longname, sizeof(card->longname), 481 snprintf(card->longname, sizeof(card->longname), "%s %s (%s)",
477 "%s %s (%s)", 482 cdev->vendor_name, cdev->product_name, usbpath);
478 dev->vendor_name, dev->product_name, usbpath);
479 483
480 setup_card(dev); 484 setup_card(cdev);
481 return 0; 485 return 0;
482} 486}
483 487
@@ -486,9 +490,9 @@ static int snd_probe(struct usb_interface *intf,
486{ 490{
487 int ret; 491 int ret;
488 struct snd_card *card = NULL; 492 struct snd_card *card = NULL;
489 struct usb_device *device = interface_to_usbdev(intf); 493 struct usb_device *usb_dev = interface_to_usbdev(intf);
490 494
491 ret = create_card(device, intf, &card); 495 ret = create_card(usb_dev, intf, &card);
492 496
493 if (ret < 0) 497 if (ret < 0)
494 return ret; 498 return ret;
@@ -496,7 +500,7 @@ static int snd_probe(struct usb_interface *intf,
496 usb_set_intfdata(intf, card); 500 usb_set_intfdata(intf, card);
497 ret = init_card(caiaqdev(card)); 501 ret = init_card(caiaqdev(card));
498 if (ret < 0) { 502 if (ret < 0) {
499 log("unable to init card! (ret=%d)\n", ret); 503 dev_err(&usb_dev->dev, "unable to init card! (ret=%d)\n", ret);
500 snd_card_free(card); 504 snd_card_free(card);
501 return ret; 505 return ret;
502 } 506 }
@@ -506,24 +510,25 @@ static int snd_probe(struct usb_interface *intf,
506 510
507static void snd_disconnect(struct usb_interface *intf) 511static void snd_disconnect(struct usb_interface *intf)
508{ 512{
509 struct snd_usb_caiaqdev *dev;
510 struct snd_card *card = usb_get_intfdata(intf); 513 struct snd_card *card = usb_get_intfdata(intf);
511 514 struct device *dev = intf->usb_dev;
512 debug("%s(%p)\n", __func__, intf); 515 struct snd_usb_caiaqdev *cdev;
513 516
514 if (!card) 517 if (!card)
515 return; 518 return;
516 519
517 dev = caiaqdev(card); 520 cdev = caiaqdev(card);
521 dev_dbg(dev, "%s(%p)\n", __func__, intf);
522
518 snd_card_disconnect(card); 523 snd_card_disconnect(card);
519 524
520#ifdef CONFIG_SND_USB_CAIAQ_INPUT 525#ifdef CONFIG_SND_USB_CAIAQ_INPUT
521 snd_usb_caiaq_input_free(dev); 526 snd_usb_caiaq_input_free(cdev);
522#endif 527#endif
523 snd_usb_caiaq_audio_free(dev); 528 snd_usb_caiaq_audio_free(cdev);
524 529
525 usb_kill_urb(&dev->ep1_in_urb); 530 usb_kill_urb(&cdev->ep1_in_urb);
526 usb_kill_urb(&dev->midi_out_urb); 531 usb_kill_urb(&cdev->midi_out_urb);
527 532
528 snd_card_free(card); 533 snd_card_free(card);
529 usb_reset_device(interface_to_usbdev(intf)); 534 usb_reset_device(interface_to_usbdev(intf));
@@ -539,4 +544,3 @@ static struct usb_driver snd_usb_driver = {
539}; 544};
540 545
541module_usb_driver(snd_usb_driver); 546module_usb_driver(snd_usb_driver);
542
diff --git a/sound/usb/caiaq/device.h b/sound/usb/caiaq/device.h
index 562b0bff9c41..ad102fac6942 100644
--- a/sound/usb/caiaq/device.h
+++ b/sound/usb/caiaq/device.h
@@ -25,16 +25,7 @@
25#define CAIAQ_USB_STR_LEN 0xff 25#define CAIAQ_USB_STR_LEN 0xff
26#define MAX_STREAMS 32 26#define MAX_STREAMS 32
27 27
28//#define SND_USB_CAIAQ_DEBUG
29
30#define MODNAME "snd-usb-caiaq" 28#define MODNAME "snd-usb-caiaq"
31#define log(x...) snd_printk(KERN_WARNING MODNAME" log: " x)
32
33#ifdef SND_USB_CAIAQ_DEBUG
34#define debug(x...) snd_printk(KERN_WARNING MODNAME " debug: " x)
35#else
36#define debug(x...) do { } while(0)
37#endif
38 29
39#define EP1_CMD_GET_DEVICE_INFO 0x1 30#define EP1_CMD_GET_DEVICE_INFO 0x1
40#define EP1_CMD_READ_ERP 0x2 31#define EP1_CMD_READ_ERP 0x2
@@ -124,15 +115,16 @@ struct snd_usb_caiaqdev {
124}; 115};
125 116
126struct snd_usb_caiaq_cb_info { 117struct snd_usb_caiaq_cb_info {
127 struct snd_usb_caiaqdev *dev; 118 struct snd_usb_caiaqdev *cdev;
128 int index; 119 int index;
129}; 120};
130 121
131#define caiaqdev(c) ((struct snd_usb_caiaqdev*)(c)->private_data) 122#define caiaqdev(c) ((struct snd_usb_caiaqdev*)(c)->private_data)
123#define caiaqdev_to_dev(d) (d->chip.card->dev)
132 124
133int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *dev, int rate, int depth, int bbp); 125int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *cdev, int rate, int depth, int bbp);
134int snd_usb_caiaq_set_auto_msg (struct snd_usb_caiaqdev *dev, int digital, int analog, int erp); 126int snd_usb_caiaq_set_auto_msg (struct snd_usb_caiaqdev *cdev, int digital, int analog, int erp);
135int snd_usb_caiaq_send_command(struct snd_usb_caiaqdev *dev, 127int snd_usb_caiaq_send_command(struct snd_usb_caiaqdev *cdev,
136 unsigned char command, 128 unsigned char command,
137 const unsigned char *buffer, 129 const unsigned char *buffer,
138 int len); 130 int len);
diff --git a/sound/usb/caiaq/input.c b/sound/usb/caiaq/input.c
index 26a121b42c3c..efc70ae915c5 100644
--- a/sound/usb/caiaq/input.c
+++ b/sound/usb/caiaq/input.c
@@ -16,6 +16,7 @@
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/ 17*/
18 18
19#include <linux/device.h>
19#include <linux/gfp.h> 20#include <linux/gfp.h>
20#include <linux/init.h> 21#include <linux/init.h>
21#include <linux/usb.h> 22#include <linux/usb.h>
@@ -199,55 +200,55 @@ static unsigned int decode_erp(unsigned char a, unsigned char b)
199#undef HIGH_PEAK 200#undef HIGH_PEAK
200#undef LOW_PEAK 201#undef LOW_PEAK
201 202
202static inline void snd_caiaq_input_report_abs(struct snd_usb_caiaqdev *dev, 203static inline void snd_caiaq_input_report_abs(struct snd_usb_caiaqdev *cdev,
203 int axis, const unsigned char *buf, 204 int axis, const unsigned char *buf,
204 int offset) 205 int offset)
205{ 206{
206 input_report_abs(dev->input_dev, axis, 207 input_report_abs(cdev->input_dev, axis,
207 (buf[offset * 2] << 8) | buf[offset * 2 + 1]); 208 (buf[offset * 2] << 8) | buf[offset * 2 + 1]);
208} 209}
209 210
210static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev, 211static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *cdev,
211 const unsigned char *buf, 212 const unsigned char *buf,
212 unsigned int len) 213 unsigned int len)
213{ 214{
214 struct input_dev *input_dev = dev->input_dev; 215 struct input_dev *input_dev = cdev->input_dev;
215 216
216 switch (dev->chip.usb_id) { 217 switch (cdev->chip.usb_id) {
217 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): 218 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
218 snd_caiaq_input_report_abs(dev, ABS_X, buf, 2); 219 snd_caiaq_input_report_abs(cdev, ABS_X, buf, 2);
219 snd_caiaq_input_report_abs(dev, ABS_Y, buf, 0); 220 snd_caiaq_input_report_abs(cdev, ABS_Y, buf, 0);
220 snd_caiaq_input_report_abs(dev, ABS_Z, buf, 1); 221 snd_caiaq_input_report_abs(cdev, ABS_Z, buf, 1);
221 break; 222 break;
222 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): 223 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
223 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): 224 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
224 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): 225 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
225 snd_caiaq_input_report_abs(dev, ABS_X, buf, 0); 226 snd_caiaq_input_report_abs(cdev, ABS_X, buf, 0);
226 snd_caiaq_input_report_abs(dev, ABS_Y, buf, 1); 227 snd_caiaq_input_report_abs(cdev, ABS_Y, buf, 1);
227 snd_caiaq_input_report_abs(dev, ABS_Z, buf, 2); 228 snd_caiaq_input_report_abs(cdev, ABS_Z, buf, 2);
228 break; 229 break;
229 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 230 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
230 snd_caiaq_input_report_abs(dev, ABS_HAT0X, buf, 4); 231 snd_caiaq_input_report_abs(cdev, ABS_HAT0X, buf, 4);
231 snd_caiaq_input_report_abs(dev, ABS_HAT0Y, buf, 2); 232 snd_caiaq_input_report_abs(cdev, ABS_HAT0Y, buf, 2);
232 snd_caiaq_input_report_abs(dev, ABS_HAT1X, buf, 6); 233 snd_caiaq_input_report_abs(cdev, ABS_HAT1X, buf, 6);
233 snd_caiaq_input_report_abs(dev, ABS_HAT1Y, buf, 1); 234 snd_caiaq_input_report_abs(cdev, ABS_HAT1Y, buf, 1);
234 snd_caiaq_input_report_abs(dev, ABS_HAT2X, buf, 7); 235 snd_caiaq_input_report_abs(cdev, ABS_HAT2X, buf, 7);
235 snd_caiaq_input_report_abs(dev, ABS_HAT2Y, buf, 0); 236 snd_caiaq_input_report_abs(cdev, ABS_HAT2Y, buf, 0);
236 snd_caiaq_input_report_abs(dev, ABS_HAT3X, buf, 5); 237 snd_caiaq_input_report_abs(cdev, ABS_HAT3X, buf, 5);
237 snd_caiaq_input_report_abs(dev, ABS_HAT3Y, buf, 3); 238 snd_caiaq_input_report_abs(cdev, ABS_HAT3Y, buf, 3);
238 break; 239 break;
239 } 240 }
240 241
241 input_sync(input_dev); 242 input_sync(input_dev);
242} 243}
243 244
244static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev, 245static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *cdev,
245 const char *buf, unsigned int len) 246 const char *buf, unsigned int len)
246{ 247{
247 struct input_dev *input_dev = dev->input_dev; 248 struct input_dev *input_dev = cdev->input_dev;
248 int i; 249 int i;
249 250
250 switch (dev->chip.usb_id) { 251 switch (cdev->chip.usb_id) {
251 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): 252 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
252 i = decode_erp(buf[0], buf[1]); 253 i = decode_erp(buf[0], buf[1]);
253 input_report_abs(input_dev, ABS_X, i); 254 input_report_abs(input_dev, ABS_X, i);
@@ -299,10 +300,10 @@ static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev,
299 } 300 }
300} 301}
301 302
302static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev, 303static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *cdev,
303 unsigned char *buf, unsigned int len) 304 unsigned char *buf, unsigned int len)
304{ 305{
305 struct input_dev *input_dev = dev->input_dev; 306 struct input_dev *input_dev = cdev->input_dev;
306 unsigned short *keycode = input_dev->keycode; 307 unsigned short *keycode = input_dev->keycode;
307 int i; 308 int i;
308 309
@@ -317,17 +318,17 @@ static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev,
317 input_report_key(input_dev, keycode[i], 318 input_report_key(input_dev, keycode[i],
318 buf[i / 8] & (1 << (i % 8))); 319 buf[i / 8] & (1 << (i % 8)));
319 320
320 switch (dev->chip.usb_id) { 321 switch (cdev->chip.usb_id) {
321 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): 322 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
322 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): 323 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
323 input_report_abs(dev->input_dev, ABS_MISC, 255 - buf[4]); 324 input_report_abs(cdev->input_dev, ABS_MISC, 255 - buf[4]);
324 break; 325 break;
325 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 326 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
326 /* rotary encoders */ 327 /* rotary encoders */
327 input_report_abs(dev->input_dev, ABS_X, buf[5] & 0xf); 328 input_report_abs(cdev->input_dev, ABS_X, buf[5] & 0xf);
328 input_report_abs(dev->input_dev, ABS_Y, buf[5] >> 4); 329 input_report_abs(cdev->input_dev, ABS_Y, buf[5] >> 4);
329 input_report_abs(dev->input_dev, ABS_Z, buf[6] & 0xf); 330 input_report_abs(cdev->input_dev, ABS_Z, buf[6] & 0xf);
330 input_report_abs(dev->input_dev, ABS_MISC, buf[6] >> 4); 331 input_report_abs(cdev->input_dev, ABS_MISC, buf[6] >> 4);
331 break; 332 break;
332 } 333 }
333 334
@@ -336,10 +337,12 @@ static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev,
336 337
337#define TKS4_MSGBLOCK_SIZE 16 338#define TKS4_MSGBLOCK_SIZE 16
338 339
339static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev *dev, 340static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev *cdev,
340 const unsigned char *buf, 341 const unsigned char *buf,
341 unsigned int len) 342 unsigned int len)
342{ 343{
344 struct device *dev = caiaqdev_to_dev(cdev);
345
343 while (len) { 346 while (len) {
344 unsigned int i, block_id = (buf[0] << 8) | buf[1]; 347 unsigned int i, block_id = (buf[0] << 8) | buf[1];
345 348
@@ -347,126 +350,126 @@ static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev *dev,
347 case 0: 350 case 0:
348 /* buttons */ 351 /* buttons */
349 for (i = 0; i < KONTROLS4_BUTTONS; i++) 352 for (i = 0; i < KONTROLS4_BUTTONS; i++)
350 input_report_key(dev->input_dev, KONTROLS4_BUTTON(i), 353 input_report_key(cdev->input_dev, KONTROLS4_BUTTON(i),
351 (buf[4 + (i / 8)] >> (i % 8)) & 1); 354 (buf[4 + (i / 8)] >> (i % 8)) & 1);
352 break; 355 break;
353 356
354 case 1: 357 case 1:
355 /* left wheel */ 358 /* left wheel */
356 input_report_abs(dev->input_dev, KONTROLS4_ABS(36), buf[9] | ((buf[8] & 0x3) << 8)); 359 input_report_abs(cdev->input_dev, KONTROLS4_ABS(36), buf[9] | ((buf[8] & 0x3) << 8));
357 /* right wheel */ 360 /* right wheel */
358 input_report_abs(dev->input_dev, KONTROLS4_ABS(37), buf[13] | ((buf[12] & 0x3) << 8)); 361 input_report_abs(cdev->input_dev, KONTROLS4_ABS(37), buf[13] | ((buf[12] & 0x3) << 8));
359 362
360 /* rotary encoders */ 363 /* rotary encoders */
361 input_report_abs(dev->input_dev, KONTROLS4_ABS(38), buf[3] & 0xf); 364 input_report_abs(cdev->input_dev, KONTROLS4_ABS(38), buf[3] & 0xf);
362 input_report_abs(dev->input_dev, KONTROLS4_ABS(39), buf[4] >> 4); 365 input_report_abs(cdev->input_dev, KONTROLS4_ABS(39), buf[4] >> 4);
363 input_report_abs(dev->input_dev, KONTROLS4_ABS(40), buf[4] & 0xf); 366 input_report_abs(cdev->input_dev, KONTROLS4_ABS(40), buf[4] & 0xf);
364 input_report_abs(dev->input_dev, KONTROLS4_ABS(41), buf[5] >> 4); 367 input_report_abs(cdev->input_dev, KONTROLS4_ABS(41), buf[5] >> 4);
365 input_report_abs(dev->input_dev, KONTROLS4_ABS(42), buf[5] & 0xf); 368 input_report_abs(cdev->input_dev, KONTROLS4_ABS(42), buf[5] & 0xf);
366 input_report_abs(dev->input_dev, KONTROLS4_ABS(43), buf[6] >> 4); 369 input_report_abs(cdev->input_dev, KONTROLS4_ABS(43), buf[6] >> 4);
367 input_report_abs(dev->input_dev, KONTROLS4_ABS(44), buf[6] & 0xf); 370 input_report_abs(cdev->input_dev, KONTROLS4_ABS(44), buf[6] & 0xf);
368 input_report_abs(dev->input_dev, KONTROLS4_ABS(45), buf[7] >> 4); 371 input_report_abs(cdev->input_dev, KONTROLS4_ABS(45), buf[7] >> 4);
369 input_report_abs(dev->input_dev, KONTROLS4_ABS(46), buf[7] & 0xf); 372 input_report_abs(cdev->input_dev, KONTROLS4_ABS(46), buf[7] & 0xf);
370 373
371 break; 374 break;
372 case 2: 375 case 2:
373 /* Volume Fader Channel D */ 376 /* Volume Fader Channel D */
374 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(0), buf, 1); 377 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(0), buf, 1);
375 /* Volume Fader Channel B */ 378 /* Volume Fader Channel B */
376 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(1), buf, 2); 379 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(1), buf, 2);
377 /* Volume Fader Channel A */ 380 /* Volume Fader Channel A */
378 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(2), buf, 3); 381 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(2), buf, 3);
379 /* Volume Fader Channel C */ 382 /* Volume Fader Channel C */
380 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(3), buf, 4); 383 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(3), buf, 4);
381 /* Loop Volume */ 384 /* Loop Volume */
382 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(4), buf, 6); 385 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(4), buf, 6);
383 /* Crossfader */ 386 /* Crossfader */
384 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(7), buf, 7); 387 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(7), buf, 7);
385 388
386 break; 389 break;
387 390
388 case 3: 391 case 3:
389 /* Tempo Fader R */ 392 /* Tempo Fader R */
390 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(6), buf, 3); 393 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(6), buf, 3);
391 /* Tempo Fader L */ 394 /* Tempo Fader L */
392 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(5), buf, 4); 395 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(5), buf, 4);
393 /* Mic Volume */ 396 /* Mic Volume */
394 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(8), buf, 6); 397 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(8), buf, 6);
395 /* Cue Mix */ 398 /* Cue Mix */
396 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(9), buf, 7); 399 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(9), buf, 7);
397 400
398 break; 401 break;
399 402
400 case 4: 403 case 4:
401 /* Wheel distance sensor L */ 404 /* Wheel distance sensor L */
402 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(10), buf, 1); 405 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(10), buf, 1);
403 /* Wheel distance sensor R */ 406 /* Wheel distance sensor R */
404 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(11), buf, 2); 407 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(11), buf, 2);
405 /* Channel D EQ - Filter */ 408 /* Channel D EQ - Filter */
406 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(12), buf, 3); 409 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(12), buf, 3);
407 /* Channel D EQ - Low */ 410 /* Channel D EQ - Low */
408 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(13), buf, 4); 411 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(13), buf, 4);
409 /* Channel D EQ - Mid */ 412 /* Channel D EQ - Mid */
410 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(14), buf, 5); 413 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(14), buf, 5);
411 /* Channel D EQ - Hi */ 414 /* Channel D EQ - Hi */
412 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(15), buf, 6); 415 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(15), buf, 6);
413 /* FX2 - dry/wet */ 416 /* FX2 - dry/wet */
414 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(16), buf, 7); 417 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(16), buf, 7);
415 418
416 break; 419 break;
417 420
418 case 5: 421 case 5:
419 /* FX2 - 1 */ 422 /* FX2 - 1 */
420 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(17), buf, 1); 423 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(17), buf, 1);
421 /* FX2 - 2 */ 424 /* FX2 - 2 */
422 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(18), buf, 2); 425 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(18), buf, 2);
423 /* FX2 - 3 */ 426 /* FX2 - 3 */
424 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(19), buf, 3); 427 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(19), buf, 3);
425 /* Channel B EQ - Filter */ 428 /* Channel B EQ - Filter */
426 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(20), buf, 4); 429 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(20), buf, 4);
427 /* Channel B EQ - Low */ 430 /* Channel B EQ - Low */
428 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(21), buf, 5); 431 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(21), buf, 5);
429 /* Channel B EQ - Mid */ 432 /* Channel B EQ - Mid */
430 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(22), buf, 6); 433 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(22), buf, 6);
431 /* Channel B EQ - Hi */ 434 /* Channel B EQ - Hi */
432 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(23), buf, 7); 435 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(23), buf, 7);
433 436
434 break; 437 break;
435 438
436 case 6: 439 case 6:
437 /* Channel A EQ - Filter */ 440 /* Channel A EQ - Filter */
438 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(24), buf, 1); 441 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(24), buf, 1);
439 /* Channel A EQ - Low */ 442 /* Channel A EQ - Low */
440 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(25), buf, 2); 443 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(25), buf, 2);
441 /* Channel A EQ - Mid */ 444 /* Channel A EQ - Mid */
442 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(26), buf, 3); 445 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(26), buf, 3);
443 /* Channel A EQ - Hi */ 446 /* Channel A EQ - Hi */
444 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(27), buf, 4); 447 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(27), buf, 4);
445 /* Channel C EQ - Filter */ 448 /* Channel C EQ - Filter */
446 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(28), buf, 5); 449 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(28), buf, 5);
447 /* Channel C EQ - Low */ 450 /* Channel C EQ - Low */
448 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(29), buf, 6); 451 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(29), buf, 6);
449 /* Channel C EQ - Mid */ 452 /* Channel C EQ - Mid */
450 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(30), buf, 7); 453 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(30), buf, 7);
451 454
452 break; 455 break;
453 456
454 case 7: 457 case 7:
455 /* Channel C EQ - Hi */ 458 /* Channel C EQ - Hi */
456 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(31), buf, 1); 459 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(31), buf, 1);
457 /* FX1 - wet/dry */ 460 /* FX1 - wet/dry */
458 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(32), buf, 2); 461 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(32), buf, 2);
459 /* FX1 - 1 */ 462 /* FX1 - 1 */
460 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(33), buf, 3); 463 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(33), buf, 3);
461 /* FX1 - 2 */ 464 /* FX1 - 2 */
462 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(34), buf, 4); 465 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(34), buf, 4);
463 /* FX1 - 3 */ 466 /* FX1 - 3 */
464 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(35), buf, 5); 467 snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(35), buf, 5);
465 468
466 break; 469 break;
467 470
468 default: 471 default:
469 debug("%s(): bogus block (id %d)\n", 472 dev_dbg(dev, "%s(): bogus block (id %d)\n",
470 __func__, block_id); 473 __func__, block_id);
471 return; 474 return;
472 } 475 }
@@ -475,12 +478,12 @@ static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev *dev,
475 buf += TKS4_MSGBLOCK_SIZE; 478 buf += TKS4_MSGBLOCK_SIZE;
476 } 479 }
477 480
478 input_sync(dev->input_dev); 481 input_sync(cdev->input_dev);
479} 482}
480 483
481#define MASCHINE_MSGBLOCK_SIZE 2 484#define MASCHINE_MSGBLOCK_SIZE 2
482 485
483static void snd_usb_caiaq_maschine_dispatch(struct snd_usb_caiaqdev *dev, 486static void snd_usb_caiaq_maschine_dispatch(struct snd_usb_caiaqdev *cdev,
484 const unsigned char *buf, 487 const unsigned char *buf,
485 unsigned int len) 488 unsigned int len)
486{ 489{
@@ -491,65 +494,66 @@ static void snd_usb_caiaq_maschine_dispatch(struct snd_usb_caiaqdev *dev,
491 pressure = be16_to_cpu(buf[i * 2] << 8 | buf[(i * 2) + 1]); 494 pressure = be16_to_cpu(buf[i * 2] << 8 | buf[(i * 2) + 1]);
492 pad_id = pressure >> 12; 495 pad_id = pressure >> 12;
493 496
494 input_report_abs(dev->input_dev, MASCHINE_PAD(pad_id), pressure & 0xfff); 497 input_report_abs(cdev->input_dev, MASCHINE_PAD(pad_id), pressure & 0xfff);
495 } 498 }
496 499
497 input_sync(dev->input_dev); 500 input_sync(cdev->input_dev);
498} 501}
499 502
500static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb) 503static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb)
501{ 504{
502 struct snd_usb_caiaqdev *dev = urb->context; 505 struct snd_usb_caiaqdev *cdev = urb->context;
503 unsigned char *buf = urb->transfer_buffer; 506 unsigned char *buf = urb->transfer_buffer;
507 struct device *dev = &urb->dev->dev;
504 int ret; 508 int ret;
505 509
506 if (urb->status || !dev || urb != dev->ep4_in_urb) 510 if (urb->status || !cdev || urb != cdev->ep4_in_urb)
507 return; 511 return;
508 512
509 switch (dev->chip.usb_id) { 513 switch (cdev->chip.usb_id) {
510 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 514 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
511 if (urb->actual_length < 24) 515 if (urb->actual_length < 24)
512 goto requeue; 516 goto requeue;
513 517
514 if (buf[0] & 0x3) 518 if (buf[0] & 0x3)
515 snd_caiaq_input_read_io(dev, buf + 1, 7); 519 snd_caiaq_input_read_io(cdev, buf + 1, 7);
516 520
517 if (buf[0] & 0x4) 521 if (buf[0] & 0x4)
518 snd_caiaq_input_read_analog(dev, buf + 8, 16); 522 snd_caiaq_input_read_analog(cdev, buf + 8, 16);
519 523
520 break; 524 break;
521 525
522 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): 526 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
523 snd_usb_caiaq_tks4_dispatch(dev, buf, urb->actual_length); 527 snd_usb_caiaq_tks4_dispatch(cdev, buf, urb->actual_length);
524 break; 528 break;
525 529
526 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER): 530 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
527 if (urb->actual_length < (MASCHINE_PADS * MASCHINE_MSGBLOCK_SIZE)) 531 if (urb->actual_length < (MASCHINE_PADS * MASCHINE_MSGBLOCK_SIZE))
528 goto requeue; 532 goto requeue;
529 533
530 snd_usb_caiaq_maschine_dispatch(dev, buf, urb->actual_length); 534 snd_usb_caiaq_maschine_dispatch(cdev, buf, urb->actual_length);
531 break; 535 break;
532 } 536 }
533 537
534requeue: 538requeue:
535 dev->ep4_in_urb->actual_length = 0; 539 cdev->ep4_in_urb->actual_length = 0;
536 ret = usb_submit_urb(dev->ep4_in_urb, GFP_ATOMIC); 540 ret = usb_submit_urb(cdev->ep4_in_urb, GFP_ATOMIC);
537 if (ret < 0) 541 if (ret < 0)
538 log("unable to submit urb. OOM!?\n"); 542 dev_err(dev, "unable to submit urb. OOM!?\n");
539} 543}
540 544
541static int snd_usb_caiaq_input_open(struct input_dev *idev) 545static int snd_usb_caiaq_input_open(struct input_dev *idev)
542{ 546{
543 struct snd_usb_caiaqdev *dev = input_get_drvdata(idev); 547 struct snd_usb_caiaqdev *cdev = input_get_drvdata(idev);
544 548
545 if (!dev) 549 if (!cdev)
546 return -EINVAL; 550 return -EINVAL;
547 551
548 switch (dev->chip.usb_id) { 552 switch (cdev->chip.usb_id) {
549 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 553 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
550 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): 554 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
551 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER): 555 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
552 if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0) 556 if (usb_submit_urb(cdev->ep4_in_urb, GFP_KERNEL) != 0)
553 return -EIO; 557 return -EIO;
554 break; 558 break;
555 } 559 }
@@ -559,43 +563,43 @@ static int snd_usb_caiaq_input_open(struct input_dev *idev)
559 563
560static void snd_usb_caiaq_input_close(struct input_dev *idev) 564static void snd_usb_caiaq_input_close(struct input_dev *idev)
561{ 565{
562 struct snd_usb_caiaqdev *dev = input_get_drvdata(idev); 566 struct snd_usb_caiaqdev *cdev = input_get_drvdata(idev);
563 567
564 if (!dev) 568 if (!cdev)
565 return; 569 return;
566 570
567 switch (dev->chip.usb_id) { 571 switch (cdev->chip.usb_id) {
568 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 572 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
569 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): 573 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
570 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER): 574 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
571 usb_kill_urb(dev->ep4_in_urb); 575 usb_kill_urb(cdev->ep4_in_urb);
572 break; 576 break;
573 } 577 }
574} 578}
575 579
576void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *dev, 580void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *cdev,
577 char *buf, 581 char *buf,
578 unsigned int len) 582 unsigned int len)
579{ 583{
580 if (!dev->input_dev || len < 1) 584 if (!cdev->input_dev || len < 1)
581 return; 585 return;
582 586
583 switch (buf[0]) { 587 switch (buf[0]) {
584 case EP1_CMD_READ_ANALOG: 588 case EP1_CMD_READ_ANALOG:
585 snd_caiaq_input_read_analog(dev, buf + 1, len - 1); 589 snd_caiaq_input_read_analog(cdev, buf + 1, len - 1);
586 break; 590 break;
587 case EP1_CMD_READ_ERP: 591 case EP1_CMD_READ_ERP:
588 snd_caiaq_input_read_erp(dev, buf + 1, len - 1); 592 snd_caiaq_input_read_erp(cdev, buf + 1, len - 1);
589 break; 593 break;
590 case EP1_CMD_READ_IO: 594 case EP1_CMD_READ_IO:
591 snd_caiaq_input_read_io(dev, buf + 1, len - 1); 595 snd_caiaq_input_read_io(cdev, buf + 1, len - 1);
592 break; 596 break;
593 } 597 }
594} 598}
595 599
596int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev) 600int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *cdev)
597{ 601{
598 struct usb_device *usb_dev = dev->chip.dev; 602 struct usb_device *usb_dev = cdev->chip.dev;
599 struct input_dev *input; 603 struct input_dev *input;
600 int i, ret = 0; 604 int i, ret = 0;
601 605
@@ -603,49 +607,49 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
603 if (!input) 607 if (!input)
604 return -ENOMEM; 608 return -ENOMEM;
605 609
606 usb_make_path(usb_dev, dev->phys, sizeof(dev->phys)); 610 usb_make_path(usb_dev, cdev->phys, sizeof(cdev->phys));
607 strlcat(dev->phys, "/input0", sizeof(dev->phys)); 611 strlcat(cdev->phys, "/input0", sizeof(cdev->phys));
608 612
609 input->name = dev->product_name; 613 input->name = cdev->product_name;
610 input->phys = dev->phys; 614 input->phys = cdev->phys;
611 usb_to_input_id(usb_dev, &input->id); 615 usb_to_input_id(usb_dev, &input->id);
612 input->dev.parent = &usb_dev->dev; 616 input->dev.parent = &usb_dev->dev;
613 617
614 input_set_drvdata(input, dev); 618 input_set_drvdata(input, cdev);
615 619
616 switch (dev->chip.usb_id) { 620 switch (cdev->chip.usb_id) {
617 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): 621 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
618 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 622 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
619 input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | 623 input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
620 BIT_MASK(ABS_Z); 624 BIT_MASK(ABS_Z);
621 BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_rk2)); 625 BUILD_BUG_ON(sizeof(cdev->keycode) < sizeof(keycode_rk2));
622 memcpy(dev->keycode, keycode_rk2, sizeof(keycode_rk2)); 626 memcpy(cdev->keycode, keycode_rk2, sizeof(keycode_rk2));
623 input->keycodemax = ARRAY_SIZE(keycode_rk2); 627 input->keycodemax = ARRAY_SIZE(keycode_rk2);
624 input_set_abs_params(input, ABS_X, 0, 4096, 0, 10); 628 input_set_abs_params(input, ABS_X, 0, 4096, 0, 10);
625 input_set_abs_params(input, ABS_Y, 0, 4096, 0, 10); 629 input_set_abs_params(input, ABS_Y, 0, 4096, 0, 10);
626 input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10); 630 input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10);
627 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 0); 631 snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 0);
628 break; 632 break;
629 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): 633 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
630 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 634 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
631 input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | 635 input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
632 BIT_MASK(ABS_Z); 636 BIT_MASK(ABS_Z);
633 BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_rk3)); 637 BUILD_BUG_ON(sizeof(cdev->keycode) < sizeof(keycode_rk3));
634 memcpy(dev->keycode, keycode_rk3, sizeof(keycode_rk3)); 638 memcpy(cdev->keycode, keycode_rk3, sizeof(keycode_rk3));
635 input->keycodemax = ARRAY_SIZE(keycode_rk3); 639 input->keycodemax = ARRAY_SIZE(keycode_rk3);
636 input_set_abs_params(input, ABS_X, 0, 1024, 0, 10); 640 input_set_abs_params(input, ABS_X, 0, 1024, 0, 10);
637 input_set_abs_params(input, ABS_Y, 0, 1024, 0, 10); 641 input_set_abs_params(input, ABS_Y, 0, 1024, 0, 10);
638 input_set_abs_params(input, ABS_Z, 0, 1024, 0, 10); 642 input_set_abs_params(input, ABS_Z, 0, 1024, 0, 10);
639 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 0); 643 snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 0);
640 break; 644 break;
641 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): 645 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
642 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 646 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
643 input->absbit[0] = BIT_MASK(ABS_X); 647 input->absbit[0] = BIT_MASK(ABS_X);
644 BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_ak1)); 648 BUILD_BUG_ON(sizeof(cdev->keycode) < sizeof(keycode_ak1));
645 memcpy(dev->keycode, keycode_ak1, sizeof(keycode_ak1)); 649 memcpy(cdev->keycode, keycode_ak1, sizeof(keycode_ak1));
646 input->keycodemax = ARRAY_SIZE(keycode_ak1); 650 input->keycodemax = ARRAY_SIZE(keycode_ak1);
647 input_set_abs_params(input, ABS_X, 0, 999, 0, 10); 651 input_set_abs_params(input, ABS_X, 0, 999, 0, 10);
648 snd_usb_caiaq_set_auto_msg(dev, 1, 0, 5); 652 snd_usb_caiaq_set_auto_msg(cdev, 1, 0, 5);
649 break; 653 break;
650 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): 654 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
651 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): 655 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
@@ -657,8 +661,8 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
657 BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | 661 BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
658 BIT_MASK(ABS_Z); 662 BIT_MASK(ABS_Z);
659 input->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC); 663 input->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC);
660 BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_kore)); 664 BUILD_BUG_ON(sizeof(cdev->keycode) < sizeof(keycode_kore));
661 memcpy(dev->keycode, keycode_kore, sizeof(keycode_kore)); 665 memcpy(cdev->keycode, keycode_kore, sizeof(keycode_kore));
662 input->keycodemax = ARRAY_SIZE(keycode_kore); 666 input->keycodemax = ARRAY_SIZE(keycode_kore);
663 input_set_abs_params(input, ABS_HAT0X, 0, 999, 0, 10); 667 input_set_abs_params(input, ABS_HAT0X, 0, 999, 0, 10);
664 input_set_abs_params(input, ABS_HAT0Y, 0, 999, 0, 10); 668 input_set_abs_params(input, ABS_HAT0Y, 0, 999, 0, 10);
@@ -672,7 +676,7 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
672 input_set_abs_params(input, ABS_Y, 0, 4096, 0, 10); 676 input_set_abs_params(input, ABS_Y, 0, 4096, 0, 10);
673 input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10); 677 input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10);
674 input_set_abs_params(input, ABS_MISC, 0, 255, 0, 1); 678 input_set_abs_params(input, ABS_MISC, 0, 255, 0, 1);
675 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5); 679 snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5);
676 break; 680 break;
677 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 681 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
678 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 682 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
@@ -683,9 +687,9 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
683 BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | 687 BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
684 BIT_MASK(ABS_Z); 688 BIT_MASK(ABS_Z);
685 input->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC); 689 input->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC);
686 BUILD_BUG_ON(sizeof(dev->keycode) < KONTROLX1_INPUTS); 690 BUILD_BUG_ON(sizeof(cdev->keycode) < KONTROLX1_INPUTS);
687 for (i = 0; i < KONTROLX1_INPUTS; i++) 691 for (i = 0; i < KONTROLX1_INPUTS; i++)
688 dev->keycode[i] = BTN_MISC + i; 692 cdev->keycode[i] = BTN_MISC + i;
689 input->keycodemax = KONTROLX1_INPUTS; 693 input->keycodemax = KONTROLX1_INPUTS;
690 694
691 /* analog potentiometers */ 695 /* analog potentiometers */
@@ -704,26 +708,26 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
704 input_set_abs_params(input, ABS_Z, 0, 0xf, 0, 1); 708 input_set_abs_params(input, ABS_Z, 0, 0xf, 0, 1);
705 input_set_abs_params(input, ABS_MISC, 0, 0xf, 0, 1); 709 input_set_abs_params(input, ABS_MISC, 0, 0xf, 0, 1);
706 710
707 dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL); 711 cdev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL);
708 if (!dev->ep4_in_urb) { 712 if (!cdev->ep4_in_urb) {
709 ret = -ENOMEM; 713 ret = -ENOMEM;
710 goto exit_free_idev; 714 goto exit_free_idev;
711 } 715 }
712 716
713 usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev, 717 usb_fill_bulk_urb(cdev->ep4_in_urb, usb_dev,
714 usb_rcvbulkpipe(usb_dev, 0x4), 718 usb_rcvbulkpipe(usb_dev, 0x4),
715 dev->ep4_in_buf, EP4_BUFSIZE, 719 cdev->ep4_in_buf, EP4_BUFSIZE,
716 snd_usb_caiaq_ep4_reply_dispatch, dev); 720 snd_usb_caiaq_ep4_reply_dispatch, cdev);
717 721
718 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5); 722 snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5);
719 723
720 break; 724 break;
721 725
722 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): 726 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
723 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 727 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
724 BUILD_BUG_ON(sizeof(dev->keycode) < KONTROLS4_BUTTONS); 728 BUILD_BUG_ON(sizeof(cdev->keycode) < KONTROLS4_BUTTONS);
725 for (i = 0; i < KONTROLS4_BUTTONS; i++) 729 for (i = 0; i < KONTROLS4_BUTTONS; i++)
726 dev->keycode[i] = KONTROLS4_BUTTON(i); 730 cdev->keycode[i] = KONTROLS4_BUTTON(i);
727 input->keycodemax = KONTROLS4_BUTTONS; 731 input->keycodemax = KONTROLS4_BUTTONS;
728 732
729 for (i = 0; i < KONTROLS4_AXIS; i++) { 733 for (i = 0; i < KONTROLS4_AXIS; i++) {
@@ -743,18 +747,18 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
743 for (i = 0; i < 9; i++) 747 for (i = 0; i < 9; i++)
744 input_set_abs_params(input, KONTROLS4_ABS(38+i), 0, 0xf, 0, 1); 748 input_set_abs_params(input, KONTROLS4_ABS(38+i), 0, 0xf, 0, 1);
745 749
746 dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL); 750 cdev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL);
747 if (!dev->ep4_in_urb) { 751 if (!cdev->ep4_in_urb) {
748 ret = -ENOMEM; 752 ret = -ENOMEM;
749 goto exit_free_idev; 753 goto exit_free_idev;
750 } 754 }
751 755
752 usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev, 756 usb_fill_bulk_urb(cdev->ep4_in_urb, usb_dev,
753 usb_rcvbulkpipe(usb_dev, 0x4), 757 usb_rcvbulkpipe(usb_dev, 0x4),
754 dev->ep4_in_buf, EP4_BUFSIZE, 758 cdev->ep4_in_buf, EP4_BUFSIZE,
755 snd_usb_caiaq_ep4_reply_dispatch, dev); 759 snd_usb_caiaq_ep4_reply_dispatch, cdev);
756 760
757 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5); 761 snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5);
758 762
759 break; 763 break;
760 764
@@ -767,8 +771,8 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
767 BIT_MASK(ABS_RX) | BIT_MASK(ABS_RY) | 771 BIT_MASK(ABS_RX) | BIT_MASK(ABS_RY) |
768 BIT_MASK(ABS_RZ); 772 BIT_MASK(ABS_RZ);
769 773
770 BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_maschine)); 774 BUILD_BUG_ON(sizeof(cdev->keycode) < sizeof(keycode_maschine));
771 memcpy(dev->keycode, keycode_maschine, sizeof(keycode_maschine)); 775 memcpy(cdev->keycode, keycode_maschine, sizeof(keycode_maschine));
772 input->keycodemax = ARRAY_SIZE(keycode_maschine); 776 input->keycodemax = ARRAY_SIZE(keycode_maschine);
773 777
774 for (i = 0; i < MASCHINE_PADS; i++) { 778 for (i = 0; i < MASCHINE_PADS; i++) {
@@ -788,18 +792,18 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
788 input_set_abs_params(input, ABS_RY, 0, 999, 0, 10); 792 input_set_abs_params(input, ABS_RY, 0, 999, 0, 10);
789 input_set_abs_params(input, ABS_RZ, 0, 999, 0, 10); 793 input_set_abs_params(input, ABS_RZ, 0, 999, 0, 10);
790 794
791 dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL); 795 cdev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL);
792 if (!dev->ep4_in_urb) { 796 if (!cdev->ep4_in_urb) {
793 ret = -ENOMEM; 797 ret = -ENOMEM;
794 goto exit_free_idev; 798 goto exit_free_idev;
795 } 799 }
796 800
797 usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev, 801 usb_fill_bulk_urb(cdev->ep4_in_urb, usb_dev,
798 usb_rcvbulkpipe(usb_dev, 0x4), 802 usb_rcvbulkpipe(usb_dev, 0x4),
799 dev->ep4_in_buf, EP4_BUFSIZE, 803 cdev->ep4_in_buf, EP4_BUFSIZE,
800 snd_usb_caiaq_ep4_reply_dispatch, dev); 804 snd_usb_caiaq_ep4_reply_dispatch, cdev);
801 805
802 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5); 806 snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5);
803 break; 807 break;
804 808
805 default: 809 default:
@@ -809,12 +813,12 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
809 813
810 input->open = snd_usb_caiaq_input_open; 814 input->open = snd_usb_caiaq_input_open;
811 input->close = snd_usb_caiaq_input_close; 815 input->close = snd_usb_caiaq_input_close;
812 input->keycode = dev->keycode; 816 input->keycode = cdev->keycode;
813 input->keycodesize = sizeof(unsigned short); 817 input->keycodesize = sizeof(unsigned short);
814 for (i = 0; i < input->keycodemax; i++) 818 for (i = 0; i < input->keycodemax; i++)
815 __set_bit(dev->keycode[i], input->keybit); 819 __set_bit(cdev->keycode[i], input->keybit);
816 820
817 dev->input_dev = input; 821 cdev->input_dev = input;
818 822
819 ret = input_register_device(input); 823 ret = input_register_device(input);
820 if (ret < 0) 824 if (ret < 0)
@@ -824,19 +828,19 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
824 828
825exit_free_idev: 829exit_free_idev:
826 input_free_device(input); 830 input_free_device(input);
827 dev->input_dev = NULL; 831 cdev->input_dev = NULL;
828 return ret; 832 return ret;
829} 833}
830 834
831void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *dev) 835void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *cdev)
832{ 836{
833 if (!dev || !dev->input_dev) 837 if (!cdev || !cdev->input_dev)
834 return; 838 return;
835 839
836 usb_kill_urb(dev->ep4_in_urb); 840 usb_kill_urb(cdev->ep4_in_urb);
837 usb_free_urb(dev->ep4_in_urb); 841 usb_free_urb(cdev->ep4_in_urb);
838 dev->ep4_in_urb = NULL; 842 cdev->ep4_in_urb = NULL;
839 843
840 input_unregister_device(dev->input_dev); 844 input_unregister_device(cdev->input_dev);
841 dev->input_dev = NULL; 845 cdev->input_dev = NULL;
842} 846}
diff --git a/sound/usb/caiaq/input.h b/sound/usb/caiaq/input.h
index ced535577864..6014e2713a60 100644
--- a/sound/usb/caiaq/input.h
+++ b/sound/usb/caiaq/input.h
@@ -1,8 +1,8 @@
1#ifndef CAIAQ_INPUT_H 1#ifndef CAIAQ_INPUT_H
2#define CAIAQ_INPUT_H 2#define CAIAQ_INPUT_H
3 3
4void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *dev, char *buf, unsigned int len); 4void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *cdev, char *buf, unsigned int len);
5int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev); 5int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *cdev);
6void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *dev); 6void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *cdev);
7 7
8#endif 8#endif
diff --git a/sound/usb/caiaq/midi.c b/sound/usb/caiaq/midi.c
index a1a47088fd0c..2d7588461b33 100644
--- a/sound/usb/caiaq/midi.c
+++ b/sound/usb/caiaq/midi.c
@@ -16,6 +16,7 @@
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/ 17*/
18 18
19#include <linux/device.h>
19#include <linux/usb.h> 20#include <linux/usb.h>
20#include <linux/gfp.h> 21#include <linux/gfp.h>
21#include <sound/rawmidi.h> 22#include <sound/rawmidi.h>
@@ -37,12 +38,12 @@ static int snd_usb_caiaq_midi_input_close(struct snd_rawmidi_substream *substrea
37 38
38static void snd_usb_caiaq_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) 39static void snd_usb_caiaq_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
39{ 40{
40 struct snd_usb_caiaqdev *dev = substream->rmidi->private_data; 41 struct snd_usb_caiaqdev *cdev = substream->rmidi->private_data;
41 42
42 if (!dev) 43 if (!cdev)
43 return; 44 return;
44 45
45 dev->midi_receive_substream = up ? substream : NULL; 46 cdev->midi_receive_substream = up ? substream : NULL;
46} 47}
47 48
48 49
@@ -53,49 +54,50 @@ static int snd_usb_caiaq_midi_output_open(struct snd_rawmidi_substream *substrea
53 54
54static int snd_usb_caiaq_midi_output_close(struct snd_rawmidi_substream *substream) 55static int snd_usb_caiaq_midi_output_close(struct snd_rawmidi_substream *substream)
55{ 56{
56 struct snd_usb_caiaqdev *dev = substream->rmidi->private_data; 57 struct snd_usb_caiaqdev *cdev = substream->rmidi->private_data;
57 if (dev->midi_out_active) { 58 if (cdev->midi_out_active) {
58 usb_kill_urb(&dev->midi_out_urb); 59 usb_kill_urb(&cdev->midi_out_urb);
59 dev->midi_out_active = 0; 60 cdev->midi_out_active = 0;
60 } 61 }
61 return 0; 62 return 0;
62} 63}
63 64
64static void snd_usb_caiaq_midi_send(struct snd_usb_caiaqdev *dev, 65static void snd_usb_caiaq_midi_send(struct snd_usb_caiaqdev *cdev,
65 struct snd_rawmidi_substream *substream) 66 struct snd_rawmidi_substream *substream)
66{ 67{
67 int len, ret; 68 int len, ret;
69 struct device *dev = caiaqdev_to_dev(cdev);
68 70
69 dev->midi_out_buf[0] = EP1_CMD_MIDI_WRITE; 71 cdev->midi_out_buf[0] = EP1_CMD_MIDI_WRITE;
70 dev->midi_out_buf[1] = 0; /* port */ 72 cdev->midi_out_buf[1] = 0; /* port */
71 len = snd_rawmidi_transmit(substream, dev->midi_out_buf + 3, 73 len = snd_rawmidi_transmit(substream, cdev->midi_out_buf + 3,
72 EP1_BUFSIZE - 3); 74 EP1_BUFSIZE - 3);
73 75
74 if (len <= 0) 76 if (len <= 0)
75 return; 77 return;
76 78
77 dev->midi_out_buf[2] = len; 79 cdev->midi_out_buf[2] = len;
78 dev->midi_out_urb.transfer_buffer_length = len+3; 80 cdev->midi_out_urb.transfer_buffer_length = len+3;
79 81
80 ret = usb_submit_urb(&dev->midi_out_urb, GFP_ATOMIC); 82 ret = usb_submit_urb(&cdev->midi_out_urb, GFP_ATOMIC);
81 if (ret < 0) 83 if (ret < 0)
82 log("snd_usb_caiaq_midi_send(%p): usb_submit_urb() failed," 84 dev_err(dev,
83 "ret=%d, len=%d\n", 85 "snd_usb_caiaq_midi_send(%p): usb_submit_urb() failed,"
84 substream, ret, len); 86 "ret=%d, len=%d\n", substream, ret, len);
85 else 87 else
86 dev->midi_out_active = 1; 88 cdev->midi_out_active = 1;
87} 89}
88 90
89static void snd_usb_caiaq_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) 91static void snd_usb_caiaq_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
90{ 92{
91 struct snd_usb_caiaqdev *dev = substream->rmidi->private_data; 93 struct snd_usb_caiaqdev *cdev = substream->rmidi->private_data;
92 94
93 if (up) { 95 if (up) {
94 dev->midi_out_substream = substream; 96 cdev->midi_out_substream = substream;
95 if (!dev->midi_out_active) 97 if (!cdev->midi_out_active)
96 snd_usb_caiaq_midi_send(dev, substream); 98 snd_usb_caiaq_midi_send(cdev, substream);
97 } else { 99 } else {
98 dev->midi_out_substream = NULL; 100 cdev->midi_out_substream = NULL;
99 } 101 }
100} 102}
101 103
@@ -114,13 +116,13 @@ static struct snd_rawmidi_ops snd_usb_caiaq_midi_input =
114 .trigger = snd_usb_caiaq_midi_input_trigger, 116 .trigger = snd_usb_caiaq_midi_input_trigger,
115}; 117};
116 118
117void snd_usb_caiaq_midi_handle_input(struct snd_usb_caiaqdev *dev, 119void snd_usb_caiaq_midi_handle_input(struct snd_usb_caiaqdev *cdev,
118 int port, const char *buf, int len) 120 int port, const char *buf, int len)
119{ 121{
120 if (!dev->midi_receive_substream) 122 if (!cdev->midi_receive_substream)
121 return; 123 return;
122 124
123 snd_rawmidi_receive(dev->midi_receive_substream, buf, len); 125 snd_rawmidi_receive(cdev->midi_receive_substream, buf, len);
124} 126}
125 127
126int snd_usb_caiaq_midi_init(struct snd_usb_caiaqdev *device) 128int snd_usb_caiaq_midi_init(struct snd_usb_caiaqdev *device)
@@ -160,15 +162,14 @@ int snd_usb_caiaq_midi_init(struct snd_usb_caiaqdev *device)
160 162
161void snd_usb_caiaq_midi_output_done(struct urb* urb) 163void snd_usb_caiaq_midi_output_done(struct urb* urb)
162{ 164{
163 struct snd_usb_caiaqdev *dev = urb->context; 165 struct snd_usb_caiaqdev *cdev = urb->context;
164 166
165 dev->midi_out_active = 0; 167 cdev->midi_out_active = 0;
166 if (urb->status != 0) 168 if (urb->status != 0)
167 return; 169 return;
168 170
169 if (!dev->midi_out_substream) 171 if (!cdev->midi_out_substream)
170 return; 172 return;
171 173
172 snd_usb_caiaq_midi_send(dev, dev->midi_out_substream); 174 snd_usb_caiaq_midi_send(cdev, cdev->midi_out_substream);
173} 175}
174
diff --git a/sound/usb/caiaq/midi.h b/sound/usb/caiaq/midi.h
index 380f984babc9..60bf3442b283 100644
--- a/sound/usb/caiaq/midi.h
+++ b/sound/usb/caiaq/midi.h
@@ -1,8 +1,9 @@
1#ifndef CAIAQ_MIDI_H 1#ifndef CAIAQ_MIDI_H
2#define CAIAQ_MIDI_H 2#define CAIAQ_MIDI_H
3 3
4int snd_usb_caiaq_midi_init(struct snd_usb_caiaqdev *dev); 4int snd_usb_caiaq_midi_init(struct snd_usb_caiaqdev *cdev);
5void snd_usb_caiaq_midi_handle_input(struct snd_usb_caiaqdev *dev, int port, const char *buf, int len); 5void snd_usb_caiaq_midi_handle_input(struct snd_usb_caiaqdev *cdev,
6 int port, const char *buf, int len);
6void snd_usb_caiaq_midi_output_done(struct urb *urb); 7void snd_usb_caiaq_midi_output_done(struct urb *urb);
7 8
8#endif /* CAIAQ_MIDI_H */ 9#endif /* CAIAQ_MIDI_H */
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 2da8ad75fd96..5254b18cedcd 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -82,6 +82,7 @@ static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
82static int nrpacks = 8; /* max. number of packets per urb */ 82static int nrpacks = 8; /* max. number of packets per urb */
83static int device_setup[SNDRV_CARDS]; /* device parameter for this card */ 83static int device_setup[SNDRV_CARDS]; /* device parameter for this card */
84static bool ignore_ctl_error; 84static bool ignore_ctl_error;
85static bool autoclock = true;
85 86
86module_param_array(index, int, NULL, 0444); 87module_param_array(index, int, NULL, 0444);
87MODULE_PARM_DESC(index, "Index value for the USB audio adapter."); 88MODULE_PARM_DESC(index, "Index value for the USB audio adapter.");
@@ -100,6 +101,8 @@ MODULE_PARM_DESC(device_setup, "Specific device setup (if needed).");
100module_param(ignore_ctl_error, bool, 0444); 101module_param(ignore_ctl_error, bool, 0444);
101MODULE_PARM_DESC(ignore_ctl_error, 102MODULE_PARM_DESC(ignore_ctl_error,
102 "Ignore errors from USB controller for mixer interfaces."); 103 "Ignore errors from USB controller for mixer interfaces.");
104module_param(autoclock, bool, 0444);
105MODULE_PARM_DESC(autoclock, "Enable auto-clock selection for UAC2 devices (default: yes).");
103 106
104/* 107/*
105 * we keep the snd_usb_audio_t instances by ourselves for merging 108 * we keep the snd_usb_audio_t instances by ourselves for merging
@@ -354,6 +357,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
354 chip->card = card; 357 chip->card = card;
355 chip->setup = device_setup[idx]; 358 chip->setup = device_setup[idx];
356 chip->nrpacks = nrpacks; 359 chip->nrpacks = nrpacks;
360 chip->autoclock = autoclock;
357 chip->probing = 1; 361 chip->probing = 1;
358 362
359 chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), 363 chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
@@ -645,7 +649,6 @@ void snd_usb_autosuspend(struct snd_usb_audio *chip)
645static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) 649static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
646{ 650{
647 struct snd_usb_audio *chip = usb_get_intfdata(intf); 651 struct snd_usb_audio *chip = usb_get_intfdata(intf);
648 struct list_head *p;
649 struct snd_usb_stream *as; 652 struct snd_usb_stream *as;
650 struct usb_mixer_interface *mixer; 653 struct usb_mixer_interface *mixer;
651 654
@@ -655,8 +658,7 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
655 if (!PMSG_IS_AUTO(message)) { 658 if (!PMSG_IS_AUTO(message)) {
656 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); 659 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
657 if (!chip->num_suspended_intf++) { 660 if (!chip->num_suspended_intf++) {
658 list_for_each(p, &chip->pcm_list) { 661 list_for_each_entry(as, &chip->pcm_list, list) {
659 as = list_entry(p, struct snd_usb_stream, list);
660 snd_pcm_suspend_all(as->pcm); 662 snd_pcm_suspend_all(as->pcm);
661 as->substream[0].need_setup_ep = 663 as->substream[0].need_setup_ep =
662 as->substream[1].need_setup_ep = true; 664 as->substream[1].need_setup_ep = true;
@@ -716,8 +718,7 @@ static struct usb_device_id usb_audio_ids [] = {
716 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL }, 718 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL },
717 { } /* Terminating entry */ 719 { } /* Terminating entry */
718}; 720};
719 721MODULE_DEVICE_TABLE(usb, usb_audio_ids);
720MODULE_DEVICE_TABLE (usb, usb_audio_ids);
721 722
722/* 723/*
723 * entry point for linux usb interface 724 * entry point for linux usb interface
diff --git a/sound/usb/card.h b/sound/usb/card.h
index 8a751b4887ea..d32ea411545a 100644
--- a/sound/usb/card.h
+++ b/sound/usb/card.h
@@ -116,6 +116,7 @@ struct snd_usb_substream {
116 unsigned int altset_idx; /* USB data format: index of alternate setting */ 116 unsigned int altset_idx; /* USB data format: index of alternate setting */
117 unsigned int txfr_quirk:1; /* allow sub-frame alignment */ 117 unsigned int txfr_quirk:1; /* allow sub-frame alignment */
118 unsigned int fmt_type; /* USB audio format type (1-3) */ 118 unsigned int fmt_type; /* USB audio format type (1-3) */
119 unsigned int pkt_offset_adj; /* Bytes to drop from beginning of packets (for non-compliant devices) */
119 120
120 unsigned int running: 1; /* running status */ 121 unsigned int running: 1; /* running status */
121 122
diff --git a/sound/usb/clock.c b/sound/usb/clock.c
index 9e2703a25156..b0ec3643eb62 100644
--- a/sound/usb/clock.c
+++ b/sound/usb/clock.c
@@ -32,6 +32,7 @@
32#include "card.h" 32#include "card.h"
33#include "helper.h" 33#include "helper.h"
34#include "clock.h" 34#include "clock.h"
35#include "quirks.h"
35 36
36static struct uac_clock_source_descriptor * 37static struct uac_clock_source_descriptor *
37 snd_usb_find_clock_source(struct usb_host_interface *ctrl_iface, 38 snd_usb_find_clock_source(struct usb_host_interface *ctrl_iface,
@@ -99,6 +100,41 @@ static int uac_clock_selector_get_val(struct snd_usb_audio *chip, int selector_i
99 return buf; 100 return buf;
100} 101}
101 102
103static int uac_clock_selector_set_val(struct snd_usb_audio *chip, int selector_id,
104 unsigned char pin)
105{
106 int ret;
107
108 ret = snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0),
109 UAC2_CS_CUR,
110 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
111 UAC2_CX_CLOCK_SELECTOR << 8,
112 snd_usb_ctrl_intf(chip) | (selector_id << 8),
113 &pin, sizeof(pin));
114 if (ret < 0)
115 return ret;
116
117 if (ret != sizeof(pin)) {
118 snd_printk(KERN_ERR
119 "usb-audio:%d: setting selector (id %d) unexpected length %d\n",
120 chip->dev->devnum, selector_id, ret);
121 return -EINVAL;
122 }
123
124 ret = uac_clock_selector_get_val(chip, selector_id);
125 if (ret < 0)
126 return ret;
127
128 if (ret != pin) {
129 snd_printk(KERN_ERR
130 "usb-audio:%d: setting selector (id %d) to %x failed (current: %d)\n",
131 chip->dev->devnum, selector_id, pin, ret);
132 return -EINVAL;
133 }
134
135 return ret;
136}
137
102static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id) 138static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id)
103{ 139{
104 int err; 140 int err;
@@ -131,7 +167,8 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id)
131} 167}
132 168
133static int __uac_clock_find_source(struct snd_usb_audio *chip, 169static int __uac_clock_find_source(struct snd_usb_audio *chip,
134 int entity_id, unsigned long *visited) 170 int entity_id, unsigned long *visited,
171 bool validate)
135{ 172{
136 struct uac_clock_source_descriptor *source; 173 struct uac_clock_source_descriptor *source;
137 struct uac_clock_selector_descriptor *selector; 174 struct uac_clock_selector_descriptor *selector;
@@ -148,12 +185,19 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
148 185
149 /* first, see if the ID we're looking for is a clock source already */ 186 /* first, see if the ID we're looking for is a clock source already */
150 source = snd_usb_find_clock_source(chip->ctrl_intf, entity_id); 187 source = snd_usb_find_clock_source(chip->ctrl_intf, entity_id);
151 if (source) 188 if (source) {
152 return source->bClockID; 189 entity_id = source->bClockID;
190 if (validate && !uac_clock_source_is_valid(chip, entity_id)) {
191 snd_printk(KERN_ERR "usb-audio:%d: clock source %d is not valid, cannot use\n",
192 chip->dev->devnum, entity_id);
193 return -ENXIO;
194 }
195 return entity_id;
196 }
153 197
154 selector = snd_usb_find_clock_selector(chip->ctrl_intf, entity_id); 198 selector = snd_usb_find_clock_selector(chip->ctrl_intf, entity_id);
155 if (selector) { 199 if (selector) {
156 int ret; 200 int ret, i, cur;
157 201
158 /* the entity ID we are looking for is a selector. 202 /* the entity ID we are looking for is a selector.
159 * find out what it currently selects */ 203 * find out what it currently selects */
@@ -164,22 +208,49 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
164 /* Selector values are one-based */ 208 /* Selector values are one-based */
165 209
166 if (ret > selector->bNrInPins || ret < 1) { 210 if (ret > selector->bNrInPins || ret < 1) {
167 printk(KERN_ERR 211 snd_printk(KERN_ERR
168 "%s(): selector reported illegal value, id %d, ret %d\n", 212 "%s(): selector reported illegal value, id %d, ret %d\n",
169 __func__, selector->bClockID, ret); 213 __func__, selector->bClockID, ret);
170 214
171 return -EINVAL; 215 return -EINVAL;
172 } 216 }
173 217
174 return __uac_clock_find_source(chip, selector->baCSourceID[ret-1], 218 cur = ret;
175 visited); 219 ret = __uac_clock_find_source(chip, selector->baCSourceID[ret - 1],
220 visited, validate);
221 if (!validate || ret > 0 || !chip->autoclock)
222 return ret;
223
224 /* The current clock source is invalid, try others. */
225 for (i = 1; i <= selector->bNrInPins; i++) {
226 int err;
227
228 if (i == cur)
229 continue;
230
231 ret = __uac_clock_find_source(chip, selector->baCSourceID[i - 1],
232 visited, true);
233 if (ret < 0)
234 continue;
235
236 err = uac_clock_selector_set_val(chip, entity_id, i);
237 if (err < 0)
238 continue;
239
240 snd_printk(KERN_INFO
241 "usb-audio:%d: found and selected valid clock source %d\n",
242 chip->dev->devnum, ret);
243 return ret;
244 }
245
246 return -ENXIO;
176 } 247 }
177 248
178 /* FIXME: multipliers only act as pass-thru element for now */ 249 /* FIXME: multipliers only act as pass-thru element for now */
179 multiplier = snd_usb_find_clock_multiplier(chip->ctrl_intf, entity_id); 250 multiplier = snd_usb_find_clock_multiplier(chip->ctrl_intf, entity_id);
180 if (multiplier) 251 if (multiplier)
181 return __uac_clock_find_source(chip, multiplier->bCSourceID, 252 return __uac_clock_find_source(chip, multiplier->bCSourceID,
182 visited); 253 visited, validate);
183 254
184 return -EINVAL; 255 return -EINVAL;
185} 256}
@@ -195,11 +266,12 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
195 * 266 *
196 * Returns the clock source UnitID (>=0) on success, or an error. 267 * Returns the clock source UnitID (>=0) on success, or an error.
197 */ 268 */
198int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id) 269int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id,
270 bool validate)
199{ 271{
200 DECLARE_BITMAP(visited, 256); 272 DECLARE_BITMAP(visited, 256);
201 memset(visited, 0, sizeof(visited)); 273 memset(visited, 0, sizeof(visited));
202 return __uac_clock_find_source(chip, entity_id, visited); 274 return __uac_clock_find_source(chip, entity_id, visited, validate);
203} 275}
204 276
205static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface, 277static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
@@ -247,66 +319,71 @@ static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
247 return 0; 319 return 0;
248} 320}
249 321
250static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, 322static int get_sample_rate_v2(struct snd_usb_audio *chip, int iface,
251 struct usb_host_interface *alts, 323 int altsetting, int clock)
252 struct audioformat *fmt, int rate)
253{ 324{
254 struct usb_device *dev = chip->dev; 325 struct usb_device *dev = chip->dev;
255 unsigned char data[4]; 326 __le32 data;
256 int err, cur_rate, prev_rate; 327 int err;
257 int clock = snd_usb_clock_find_source(chip, fmt->clock);
258
259 if (clock < 0)
260 return clock;
261
262 if (!uac_clock_source_is_valid(chip, clock)) {
263 /* TODO: should we try to find valid clock setups by ourself? */
264 snd_printk(KERN_ERR "%d:%d:%d: clock source %d is not valid, cannot use\n",
265 dev->devnum, iface, fmt->altsetting, clock);
266 return -ENXIO;
267 }
268 328
269 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, 329 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
270 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 330 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
271 UAC2_CS_CONTROL_SAM_FREQ << 8, 331 UAC2_CS_CONTROL_SAM_FREQ << 8,
272 snd_usb_ctrl_intf(chip) | (clock << 8), 332 snd_usb_ctrl_intf(chip) | (clock << 8),
273 data, sizeof(data)); 333 &data, sizeof(data));
274 if (err < 0) { 334 if (err < 0) {
275 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n", 335 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2): err %d\n",
276 dev->devnum, iface, fmt->altsetting); 336 dev->devnum, iface, altsetting, err);
277 prev_rate = 0; 337 return 0;
278 } else {
279 prev_rate = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
280 } 338 }
281 339
282 data[0] = rate; 340 return le32_to_cpu(data);
283 data[1] = rate >> 8; 341}
284 data[2] = rate >> 16;
285 data[3] = rate >> 24;
286 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR,
287 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
288 UAC2_CS_CONTROL_SAM_FREQ << 8,
289 snd_usb_ctrl_intf(chip) | (clock << 8),
290 data, sizeof(data))) < 0) {
291 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2)\n",
292 dev->devnum, iface, fmt->altsetting, rate);
293 return err;
294 }
295 342
296 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, 343static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
297 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 344 struct usb_host_interface *alts,
298 UAC2_CS_CONTROL_SAM_FREQ << 8, 345 struct audioformat *fmt, int rate)
299 snd_usb_ctrl_intf(chip) | (clock << 8), 346{
300 data, sizeof(data)); 347 struct usb_device *dev = chip->dev;
301 if (err < 0) { 348 __le32 data;
302 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n", 349 int err, cur_rate, prev_rate;
303 dev->devnum, iface, fmt->altsetting); 350 int clock;
304 cur_rate = 0; 351 bool writeable;
352 struct uac_clock_source_descriptor *cs_desc;
353
354 clock = snd_usb_clock_find_source(chip, fmt->clock, true);
355 if (clock < 0)
356 return clock;
357
358 prev_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock);
359
360 cs_desc = snd_usb_find_clock_source(chip->ctrl_intf, clock);
361 writeable = uac2_control_is_writeable(cs_desc->bmControls, UAC2_CS_CONTROL_SAM_FREQ - 1);
362 if (writeable) {
363 data = cpu_to_le32(rate);
364 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR,
365 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
366 UAC2_CS_CONTROL_SAM_FREQ << 8,
367 snd_usb_ctrl_intf(chip) | (clock << 8),
368 &data, sizeof(data));
369 if (err < 0) {
370 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2): err %d\n",
371 dev->devnum, iface, fmt->altsetting, rate, err);
372 return err;
373 }
374
375 cur_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock);
305 } else { 376 } else {
306 cur_rate = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); 377 cur_rate = prev_rate;
307 } 378 }
308 379
309 if (cur_rate != rate) { 380 if (cur_rate != rate) {
381 if (!writeable) {
382 snd_printk(KERN_WARNING
383 "%d:%d:%d: freq mismatch (RO clock): req %d, clock runs @%d\n",
384 dev->devnum, iface, fmt->altsetting, rate, cur_rate);
385 return -ENXIO;
386 }
310 snd_printd(KERN_WARNING 387 snd_printd(KERN_WARNING
311 "current rate %d is different from the runtime rate %d\n", 388 "current rate %d is different from the runtime rate %d\n",
312 cur_rate, rate); 389 cur_rate, rate);
@@ -316,7 +393,9 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
316 * interface is active. */ 393 * interface is active. */
317 if (rate != prev_rate) { 394 if (rate != prev_rate) {
318 usb_set_interface(dev, iface, 0); 395 usb_set_interface(dev, iface, 0);
396 snd_usb_set_interface_quirk(dev);
319 usb_set_interface(dev, iface, fmt->altsetting); 397 usb_set_interface(dev, iface, fmt->altsetting);
398 snd_usb_set_interface_quirk(dev);
320 } 399 }
321 400
322 return 0; 401 return 0;
diff --git a/sound/usb/clock.h b/sound/usb/clock.h
index 46630936d31f..d592e4a29856 100644
--- a/sound/usb/clock.h
+++ b/sound/usb/clock.h
@@ -5,6 +5,7 @@ int snd_usb_init_sample_rate(struct snd_usb_audio *chip, int iface,
5 struct usb_host_interface *alts, 5 struct usb_host_interface *alts,
6 struct audioformat *fmt, int rate); 6 struct audioformat *fmt, int rate);
7 7
8int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id); 8int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id,
9 bool validate);
9 10
10#endif /* __USBAUDIO_CLOCK_H */ 11#endif /* __USBAUDIO_CLOCK_H */
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index 21049b882ee6..7e9c55a73540 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -128,7 +128,7 @@ static const char *usb_error_string(int err)
128 * Determine whether an endpoint is driven by an implicit feedback 128 * Determine whether an endpoint is driven by an implicit feedback
129 * data endpoint source. 129 * data endpoint source.
130 */ 130 */
131int snd_usb_endpoint_implict_feedback_sink(struct snd_usb_endpoint *ep) 131int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep)
132{ 132{
133 return ep->sync_master && 133 return ep->sync_master &&
134 ep->sync_master->type == SND_USB_ENDPOINT_TYPE_DATA && 134 ep->sync_master->type == SND_USB_ENDPOINT_TYPE_DATA &&
@@ -363,7 +363,7 @@ static void snd_complete_urb(struct urb *urb)
363 if (unlikely(!test_bit(EP_FLAG_RUNNING, &ep->flags))) 363 if (unlikely(!test_bit(EP_FLAG_RUNNING, &ep->flags)))
364 goto exit_clear; 364 goto exit_clear;
365 365
366 if (snd_usb_endpoint_implict_feedback_sink(ep)) { 366 if (snd_usb_endpoint_implicit_feedback_sink(ep)) {
367 unsigned long flags; 367 unsigned long flags;
368 368
369 spin_lock_irqsave(&ep->lock, flags); 369 spin_lock_irqsave(&ep->lock, flags);
@@ -415,14 +415,12 @@ struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
415 struct usb_host_interface *alts, 415 struct usb_host_interface *alts,
416 int ep_num, int direction, int type) 416 int ep_num, int direction, int type)
417{ 417{
418 struct list_head *p;
419 struct snd_usb_endpoint *ep; 418 struct snd_usb_endpoint *ep;
420 int is_playback = direction == SNDRV_PCM_STREAM_PLAYBACK; 419 int is_playback = direction == SNDRV_PCM_STREAM_PLAYBACK;
421 420
422 mutex_lock(&chip->mutex); 421 mutex_lock(&chip->mutex);
423 422
424 list_for_each(p, &chip->ep_list) { 423 list_for_each_entry(ep, &chip->ep_list, list) {
425 ep = list_entry(p, struct snd_usb_endpoint, list);
426 if (ep->ep_num == ep_num && 424 if (ep->ep_num == ep_num &&
427 ep->iface == alts->desc.bInterfaceNumber && 425 ep->iface == alts->desc.bInterfaceNumber &&
428 ep->alt_idx == alts->desc.bAlternateSetting) { 426 ep->alt_idx == alts->desc.bAlternateSetting) {
@@ -607,7 +605,7 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep,
607 else 605 else
608 packs_per_ms = 1; 606 packs_per_ms = 1;
609 607
610 if (is_playback && !snd_usb_endpoint_implict_feedback_sink(ep)) { 608 if (is_playback && !snd_usb_endpoint_implicit_feedback_sink(ep)) {
611 urb_packs = max(ep->chip->nrpacks, 1); 609 urb_packs = max(ep->chip->nrpacks, 1);
612 urb_packs = min(urb_packs, (unsigned int) MAX_PACKS); 610 urb_packs = min(urb_packs, (unsigned int) MAX_PACKS);
613 } else { 611 } else {
@@ -616,11 +614,11 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep,
616 614
617 urb_packs *= packs_per_ms; 615 urb_packs *= packs_per_ms;
618 616
619 if (sync_ep && !snd_usb_endpoint_implict_feedback_sink(ep)) 617 if (sync_ep && !snd_usb_endpoint_implicit_feedback_sink(ep))
620 urb_packs = min(urb_packs, 1U << sync_ep->syncinterval); 618 urb_packs = min(urb_packs, 1U << sync_ep->syncinterval);
621 619
622 /* decide how many packets to be used */ 620 /* decide how many packets to be used */
623 if (is_playback && !snd_usb_endpoint_implict_feedback_sink(ep)) { 621 if (is_playback && !snd_usb_endpoint_implicit_feedback_sink(ep)) {
624 unsigned int minsize, maxpacks; 622 unsigned int minsize, maxpacks;
625 /* determine how small a packet can be */ 623 /* determine how small a packet can be */
626 minsize = (ep->freqn >> (16 - ep->datainterval)) 624 minsize = (ep->freqn >> (16 - ep->datainterval))
@@ -847,7 +845,7 @@ int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, bool can_sleep)
847 845
848 set_bit(EP_FLAG_RUNNING, &ep->flags); 846 set_bit(EP_FLAG_RUNNING, &ep->flags);
849 847
850 if (snd_usb_endpoint_implict_feedback_sink(ep)) { 848 if (snd_usb_endpoint_implicit_feedback_sink(ep)) {
851 for (i = 0; i < ep->nurbs; i++) { 849 for (i = 0; i < ep->nurbs; i++) {
852 struct snd_urb_ctx *ctx = ep->urb + i; 850 struct snd_urb_ctx *ctx = ep->urb + i;
853 list_add_tail(&ctx->ready_list, &ep->ready_playback_urbs); 851 list_add_tail(&ctx->ready_list, &ep->ready_playback_urbs);
@@ -990,7 +988,7 @@ void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep,
990 * and add it to the list of pending urbs. queue_pending_output_urbs() 988 * and add it to the list of pending urbs. queue_pending_output_urbs()
991 * will take care of them later. 989 * will take care of them later.
992 */ 990 */
993 if (snd_usb_endpoint_implict_feedback_sink(ep) && 991 if (snd_usb_endpoint_implicit_feedback_sink(ep) &&
994 ep->use_count != 0) { 992 ep->use_count != 0) {
995 993
996 /* implicit feedback case */ 994 /* implicit feedback case */
diff --git a/sound/usb/endpoint.h b/sound/usb/endpoint.h
index 447902dd8a4a..2287adf5ca59 100644
--- a/sound/usb/endpoint.h
+++ b/sound/usb/endpoint.h
@@ -23,7 +23,7 @@ int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep);
23int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep); 23int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep);
24void snd_usb_endpoint_free(struct list_head *head); 24void snd_usb_endpoint_free(struct list_head *head);
25 25
26int snd_usb_endpoint_implict_feedback_sink(struct snd_usb_endpoint *ep); 26int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep);
27int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep); 27int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep);
28 28
29void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep, 29void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep,
diff --git a/sound/usb/format.c b/sound/usb/format.c
index e831ee4238bb..20c775170959 100644
--- a/sound/usb/format.c
+++ b/sound/usb/format.c
@@ -43,11 +43,11 @@
43 */ 43 */
44static u64 parse_audio_format_i_type(struct snd_usb_audio *chip, 44static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
45 struct audioformat *fp, 45 struct audioformat *fp,
46 int format, void *_fmt, 46 unsigned int format, void *_fmt,
47 int protocol) 47 int protocol)
48{ 48{
49 int sample_width, sample_bytes; 49 int sample_width, sample_bytes;
50 u64 pcm_formats; 50 u64 pcm_formats = 0;
51 51
52 switch (protocol) { 52 switch (protocol) {
53 case UAC_VERSION_1: 53 case UAC_VERSION_1:
@@ -63,14 +63,17 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
63 struct uac_format_type_i_ext_descriptor *fmt = _fmt; 63 struct uac_format_type_i_ext_descriptor *fmt = _fmt;
64 sample_width = fmt->bBitResolution; 64 sample_width = fmt->bBitResolution;
65 sample_bytes = fmt->bSubslotSize; 65 sample_bytes = fmt->bSubslotSize;
66
67 if (format & UAC2_FORMAT_TYPE_I_RAW_DATA)
68 pcm_formats |= SNDRV_PCM_FMTBIT_SPECIAL;
69
66 format <<= 1; 70 format <<= 1;
67 break; 71 break;
68 } 72 }
69 } 73 }
70 74
71 pcm_formats = 0; 75 if ((pcm_formats == 0) &&
72 76 (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED))) {
73 if (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED)) {
74 /* some devices don't define this correctly... */ 77 /* some devices don't define this correctly... */
75 snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n", 78 snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n",
76 chip->dev->devnum, fp->iface, fp->altsetting); 79 chip->dev->devnum, fp->iface, fp->altsetting);
@@ -277,7 +280,7 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
277 struct usb_device *dev = chip->dev; 280 struct usb_device *dev = chip->dev;
278 unsigned char tmp[2], *data; 281 unsigned char tmp[2], *data;
279 int nr_triplets, data_size, ret = 0; 282 int nr_triplets, data_size, ret = 0;
280 int clock = snd_usb_clock_find_source(chip, fp->clock); 283 int clock = snd_usb_clock_find_source(chip, fp->clock, false);
281 284
282 if (clock < 0) { 285 if (clock < 0) {
283 snd_printk(KERN_ERR "%s(): unable to find clock source (clock %d)\n", 286 snd_printk(KERN_ERR "%s(): unable to find clock source (clock %d)\n",
@@ -353,7 +356,7 @@ err:
353 * parse the format type I and III descriptors 356 * parse the format type I and III descriptors
354 */ 357 */
355static int parse_audio_format_i(struct snd_usb_audio *chip, 358static int parse_audio_format_i(struct snd_usb_audio *chip,
356 struct audioformat *fp, int format, 359 struct audioformat *fp, unsigned int format,
357 struct uac_format_type_i_continuous_descriptor *fmt, 360 struct uac_format_type_i_continuous_descriptor *fmt,
358 struct usb_host_interface *iface) 361 struct usb_host_interface *iface)
359{ 362{
@@ -473,8 +476,9 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
473 return ret; 476 return ret;
474} 477}
475 478
476int snd_usb_parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp, 479int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
477 int format, struct uac_format_type_i_continuous_descriptor *fmt, 480 struct audioformat *fp, unsigned int format,
481 struct uac_format_type_i_continuous_descriptor *fmt,
478 int stream, struct usb_host_interface *iface) 482 int stream, struct usb_host_interface *iface)
479{ 483{
480 int err; 484 int err;
diff --git a/sound/usb/format.h b/sound/usb/format.h
index 387924f0af85..6f315226f320 100644
--- a/sound/usb/format.h
+++ b/sound/usb/format.h
@@ -2,7 +2,7 @@
2#define __USBAUDIO_FORMAT_H 2#define __USBAUDIO_FORMAT_H
3 3
4int snd_usb_parse_audio_format(struct snd_usb_audio *chip, 4int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
5 struct audioformat *fp, int format, 5 struct audioformat *fp, unsigned int format,
6 struct uac_format_type_i_continuous_descriptor *fmt, 6 struct uac_format_type_i_continuous_descriptor *fmt,
7 int stream, struct usb_host_interface *iface); 7 int stream, struct usb_host_interface *iface);
8 8
diff --git a/sound/usb/midi.c b/sound/usb/midi.c
index 34b9bb7fe87c..8e01fa4991c5 100644
--- a/sound/usb/midi.c
+++ b/sound/usb/midi.c
@@ -126,7 +126,6 @@ struct snd_usb_midi {
126 struct snd_usb_midi_in_endpoint *in; 126 struct snd_usb_midi_in_endpoint *in;
127 } endpoints[MIDI_MAX_ENDPOINTS]; 127 } endpoints[MIDI_MAX_ENDPOINTS];
128 unsigned long input_triggered; 128 unsigned long input_triggered;
129 bool autopm_reference;
130 unsigned int opened[2]; 129 unsigned int opened[2];
131 unsigned char disconnected; 130 unsigned char disconnected;
132 unsigned char input_running; 131 unsigned char input_running;
@@ -1040,7 +1039,6 @@ static int substream_open(struct snd_rawmidi_substream *substream, int dir,
1040{ 1039{
1041 struct snd_usb_midi* umidi = substream->rmidi->private_data; 1040 struct snd_usb_midi* umidi = substream->rmidi->private_data;
1042 struct snd_kcontrol *ctl; 1041 struct snd_kcontrol *ctl;
1043 int err;
1044 1042
1045 down_read(&umidi->disc_rwsem); 1043 down_read(&umidi->disc_rwsem);
1046 if (umidi->disconnected) { 1044 if (umidi->disconnected) {
@@ -1051,13 +1049,6 @@ static int substream_open(struct snd_rawmidi_substream *substream, int dir,
1051 mutex_lock(&umidi->mutex); 1049 mutex_lock(&umidi->mutex);
1052 if (open) { 1050 if (open) {
1053 if (!umidi->opened[0] && !umidi->opened[1]) { 1051 if (!umidi->opened[0] && !umidi->opened[1]) {
1054 err = usb_autopm_get_interface(umidi->iface);
1055 umidi->autopm_reference = err >= 0;
1056 if (err < 0 && err != -EACCES) {
1057 mutex_unlock(&umidi->mutex);
1058 up_read(&umidi->disc_rwsem);
1059 return -EIO;
1060 }
1061 if (umidi->roland_load_ctl) { 1052 if (umidi->roland_load_ctl) {
1062 ctl = umidi->roland_load_ctl; 1053 ctl = umidi->roland_load_ctl;
1063 ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; 1054 ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
@@ -1080,8 +1071,6 @@ static int substream_open(struct snd_rawmidi_substream *substream, int dir,
1080 snd_ctl_notify(umidi->card, 1071 snd_ctl_notify(umidi->card,
1081 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id); 1072 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
1082 } 1073 }
1083 if (umidi->autopm_reference)
1084 usb_autopm_put_interface(umidi->iface);
1085 } 1074 }
1086 } 1075 }
1087 mutex_unlock(&umidi->mutex); 1076 mutex_unlock(&umidi->mutex);
@@ -1455,6 +1444,7 @@ void snd_usbmidi_disconnect(struct list_head* p)
1455 } 1444 }
1456 del_timer_sync(&umidi->error_timer); 1445 del_timer_sync(&umidi->error_timer);
1457} 1446}
1447EXPORT_SYMBOL(snd_usbmidi_disconnect);
1458 1448
1459static void snd_usbmidi_rawmidi_free(struct snd_rawmidi *rmidi) 1449static void snd_usbmidi_rawmidi_free(struct snd_rawmidi *rmidi)
1460{ 1450{
@@ -1465,10 +1455,9 @@ static void snd_usbmidi_rawmidi_free(struct snd_rawmidi *rmidi)
1465static struct snd_rawmidi_substream *snd_usbmidi_find_substream(struct snd_usb_midi* umidi, 1455static struct snd_rawmidi_substream *snd_usbmidi_find_substream(struct snd_usb_midi* umidi,
1466 int stream, int number) 1456 int stream, int number)
1467{ 1457{
1468 struct list_head* list; 1458 struct snd_rawmidi_substream *substream;
1469 1459
1470 list_for_each(list, &umidi->rmidi->streams[stream].substreams) { 1460 list_for_each_entry(substream, &umidi->rmidi->streams[stream].substreams, list) {
1471 struct snd_rawmidi_substream *substream = list_entry(list, struct snd_rawmidi_substream, list);
1472 if (substream->number == number) 1461 if (substream->number == number)
1473 return substream; 1462 return substream;
1474 } 1463 }
@@ -2091,6 +2080,7 @@ void snd_usbmidi_input_stop(struct list_head* p)
2091 } 2080 }
2092 umidi->input_running = 0; 2081 umidi->input_running = 0;
2093} 2082}
2083EXPORT_SYMBOL(snd_usbmidi_input_stop);
2094 2084
2095static void snd_usbmidi_input_start_ep(struct snd_usb_midi_in_endpoint* ep) 2085static void snd_usbmidi_input_start_ep(struct snd_usb_midi_in_endpoint* ep)
2096{ 2086{
@@ -2120,6 +2110,7 @@ void snd_usbmidi_input_start(struct list_head* p)
2120 snd_usbmidi_input_start_ep(umidi->endpoints[i].in); 2110 snd_usbmidi_input_start_ep(umidi->endpoints[i].in);
2121 umidi->input_running = 1; 2111 umidi->input_running = 1;
2122} 2112}
2113EXPORT_SYMBOL(snd_usbmidi_input_start);
2123 2114
2124/* 2115/*
2125 * Creates and registers everything needed for a MIDI streaming interface. 2116 * Creates and registers everything needed for a MIDI streaming interface.
@@ -2256,11 +2247,9 @@ int snd_usbmidi_create(struct snd_card *card,
2256 return err; 2247 return err;
2257 } 2248 }
2258 2249
2250 usb_autopm_get_interface_no_resume(umidi->iface);
2251
2259 list_add_tail(&umidi->list, midi_list); 2252 list_add_tail(&umidi->list, midi_list);
2260 return 0; 2253 return 0;
2261} 2254}
2262
2263EXPORT_SYMBOL(snd_usbmidi_create); 2255EXPORT_SYMBOL(snd_usbmidi_create);
2264EXPORT_SYMBOL(snd_usbmidi_input_stop);
2265EXPORT_SYMBOL(snd_usbmidi_input_start);
2266EXPORT_SYMBOL(snd_usbmidi_disconnect);
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index f94397b42aa5..9916c85d8cdb 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -94,13 +94,11 @@ static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream
94 */ 94 */
95static struct audioformat *find_format(struct snd_usb_substream *subs) 95static struct audioformat *find_format(struct snd_usb_substream *subs)
96{ 96{
97 struct list_head *p; 97 struct audioformat *fp;
98 struct audioformat *found = NULL; 98 struct audioformat *found = NULL;
99 int cur_attr = 0, attr; 99 int cur_attr = 0, attr;
100 100
101 list_for_each(p, &subs->fmt_list) { 101 list_for_each_entry(fp, &subs->fmt_list, list) {
102 struct audioformat *fp;
103 fp = list_entry(p, struct audioformat, list);
104 if (!(fp->formats & (1uLL << subs->pcm_format))) 102 if (!(fp->formats & (1uLL << subs->pcm_format)))
105 continue; 103 continue;
106 if (fp->channels != subs->channels) 104 if (fp->channels != subs->channels)
@@ -350,6 +348,8 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
350 fmt->iface, fmt->altsetting); 348 fmt->iface, fmt->altsetting);
351 subs->interface = fmt->iface; 349 subs->interface = fmt->iface;
352 subs->altset_idx = fmt->altset_idx; 350 subs->altset_idx = fmt->altset_idx;
351
352 snd_usb_set_interface_quirk(dev);
353 } 353 }
354 354
355 subs->data_endpoint = snd_usb_add_endpoint(subs->stream->chip, 355 subs->data_endpoint = snd_usb_add_endpoint(subs->stream->chip,
@@ -802,7 +802,7 @@ static int hw_rule_rate(struct snd_pcm_hw_params *params,
802 struct snd_pcm_hw_rule *rule) 802 struct snd_pcm_hw_rule *rule)
803{ 803{
804 struct snd_usb_substream *subs = rule->private; 804 struct snd_usb_substream *subs = rule->private;
805 struct list_head *p; 805 struct audioformat *fp;
806 struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); 806 struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
807 unsigned int rmin, rmax; 807 unsigned int rmin, rmax;
808 int changed; 808 int changed;
@@ -810,9 +810,7 @@ static int hw_rule_rate(struct snd_pcm_hw_params *params,
810 hwc_debug("hw_rule_rate: (%d,%d)\n", it->min, it->max); 810 hwc_debug("hw_rule_rate: (%d,%d)\n", it->min, it->max);
811 changed = 0; 811 changed = 0;
812 rmin = rmax = 0; 812 rmin = rmax = 0;
813 list_for_each(p, &subs->fmt_list) { 813 list_for_each_entry(fp, &subs->fmt_list, list) {
814 struct audioformat *fp;
815 fp = list_entry(p, struct audioformat, list);
816 if (!hw_check_valid_format(subs, params, fp)) 814 if (!hw_check_valid_format(subs, params, fp))
817 continue; 815 continue;
818 if (changed++) { 816 if (changed++) {
@@ -856,7 +854,7 @@ static int hw_rule_channels(struct snd_pcm_hw_params *params,
856 struct snd_pcm_hw_rule *rule) 854 struct snd_pcm_hw_rule *rule)
857{ 855{
858 struct snd_usb_substream *subs = rule->private; 856 struct snd_usb_substream *subs = rule->private;
859 struct list_head *p; 857 struct audioformat *fp;
860 struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); 858 struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
861 unsigned int rmin, rmax; 859 unsigned int rmin, rmax;
862 int changed; 860 int changed;
@@ -864,9 +862,7 @@ static int hw_rule_channels(struct snd_pcm_hw_params *params,
864 hwc_debug("hw_rule_channels: (%d,%d)\n", it->min, it->max); 862 hwc_debug("hw_rule_channels: (%d,%d)\n", it->min, it->max);
865 changed = 0; 863 changed = 0;
866 rmin = rmax = 0; 864 rmin = rmax = 0;
867 list_for_each(p, &subs->fmt_list) { 865 list_for_each_entry(fp, &subs->fmt_list, list) {
868 struct audioformat *fp;
869 fp = list_entry(p, struct audioformat, list);
870 if (!hw_check_valid_format(subs, params, fp)) 866 if (!hw_check_valid_format(subs, params, fp))
871 continue; 867 continue;
872 if (changed++) { 868 if (changed++) {
@@ -909,7 +905,7 @@ static int hw_rule_format(struct snd_pcm_hw_params *params,
909 struct snd_pcm_hw_rule *rule) 905 struct snd_pcm_hw_rule *rule)
910{ 906{
911 struct snd_usb_substream *subs = rule->private; 907 struct snd_usb_substream *subs = rule->private;
912 struct list_head *p; 908 struct audioformat *fp;
913 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 909 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
914 u64 fbits; 910 u64 fbits;
915 u32 oldbits[2]; 911 u32 oldbits[2];
@@ -917,9 +913,7 @@ static int hw_rule_format(struct snd_pcm_hw_params *params,
917 913
918 hwc_debug("hw_rule_format: %x:%x\n", fmt->bits[0], fmt->bits[1]); 914 hwc_debug("hw_rule_format: %x:%x\n", fmt->bits[0], fmt->bits[1]);
919 fbits = 0; 915 fbits = 0;
920 list_for_each(p, &subs->fmt_list) { 916 list_for_each_entry(fp, &subs->fmt_list, list) {
921 struct audioformat *fp;
922 fp = list_entry(p, struct audioformat, list);
923 if (!hw_check_valid_format(subs, params, fp)) 917 if (!hw_check_valid_format(subs, params, fp))
924 continue; 918 continue;
925 fbits |= fp->formats; 919 fbits |= fp->formats;
@@ -1027,7 +1021,7 @@ static int snd_usb_pcm_check_knot(struct snd_pcm_runtime *runtime,
1027 1021
1028static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substream *subs) 1022static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substream *subs)
1029{ 1023{
1030 struct list_head *p; 1024 struct audioformat *fp;
1031 unsigned int pt, ptmin; 1025 unsigned int pt, ptmin;
1032 int param_period_time_if_needed; 1026 int param_period_time_if_needed;
1033 int err; 1027 int err;
@@ -1041,9 +1035,7 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre
1041 runtime->hw.rates = 0; 1035 runtime->hw.rates = 0;
1042 ptmin = UINT_MAX; 1036 ptmin = UINT_MAX;
1043 /* check min/max rates and channels */ 1037 /* check min/max rates and channels */
1044 list_for_each(p, &subs->fmt_list) { 1038 list_for_each_entry(fp, &subs->fmt_list, list) {
1045 struct audioformat *fp;
1046 fp = list_entry(p, struct audioformat, list);
1047 runtime->hw.rates |= fp->rates; 1039 runtime->hw.rates |= fp->rates;
1048 if (runtime->hw.rate_min > fp->rate_min) 1040 if (runtime->hw.rate_min > fp->rate_min)
1049 runtime->hw.rate_min = fp->rate_min; 1041 runtime->hw.rate_min = fp->rate_min;
@@ -1170,7 +1162,7 @@ static void retire_capture_urb(struct snd_usb_substream *subs,
1170 stride = runtime->frame_bits >> 3; 1162 stride = runtime->frame_bits >> 3;
1171 1163
1172 for (i = 0; i < urb->number_of_packets; i++) { 1164 for (i = 0; i < urb->number_of_packets; i++) {
1173 cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset; 1165 cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset + subs->pkt_offset_adj;
1174 if (urb->iso_frame_desc[i].status && printk_ratelimit()) { 1166 if (urb->iso_frame_desc[i].status && printk_ratelimit()) {
1175 snd_printdd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status); 1167 snd_printdd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status);
1176 // continue; 1168 // continue;
@@ -1274,7 +1266,7 @@ static void prepare_playback_urb(struct snd_usb_substream *subs,
1274 } 1266 }
1275 } 1267 }
1276 if (period_elapsed && 1268 if (period_elapsed &&
1277 !snd_usb_endpoint_implict_feedback_sink(subs->data_endpoint)) /* finish at the period boundary */ 1269 !snd_usb_endpoint_implicit_feedback_sink(subs->data_endpoint)) /* finish at the period boundary */
1278 break; 1270 break;
1279 } 1271 }
1280 bytes = frames * stride; 1272 bytes = frames * stride;
diff --git a/sound/usb/proc.c b/sound/usb/proc.c
index d218f763501f..0182ef634d8b 100644
--- a/sound/usb/proc.c
+++ b/sound/usb/proc.c
@@ -73,15 +73,14 @@ void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
73 */ 73 */
74static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct snd_info_buffer *buffer) 74static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
75{ 75{
76 struct list_head *p; 76 struct audioformat *fp;
77 static char *sync_types[4] = { 77 static char *sync_types[4] = {
78 "NONE", "ASYNC", "ADAPTIVE", "SYNC" 78 "NONE", "ASYNC", "ADAPTIVE", "SYNC"
79 }; 79 };
80 80
81 list_for_each(p, &subs->fmt_list) { 81 list_for_each_entry(fp, &subs->fmt_list, list) {
82 struct audioformat *fp;
83 snd_pcm_format_t fmt; 82 snd_pcm_format_t fmt;
84 fp = list_entry(p, struct audioformat, list); 83
85 snd_iprintf(buffer, " Interface %d\n", fp->iface); 84 snd_iprintf(buffer, " Interface %d\n", fp->iface);
86 snd_iprintf(buffer, " Altset %d\n", fp->altsetting); 85 snd_iprintf(buffer, " Altset %d\n", fp->altsetting);
87 snd_iprintf(buffer, " Format:"); 86 snd_iprintf(buffer, " Format:");
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
index c39f898b15d2..86e4b8c17dad 100644
--- a/sound/usb/quirks-table.h
+++ b/sound/usb/quirks-table.h
@@ -2748,6 +2748,46 @@ YAMAHA_DEVICE(0x7010, "UB99"),
2748 } 2748 }
2749}, 2749},
2750{ 2750{
2751 USB_DEVICE(0x1235, 0x0018),
2752 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
2753 .vendor_name = "Novation",
2754 .product_name = "Twitch",
2755 .ifnum = QUIRK_ANY_INTERFACE,
2756 .type = QUIRK_COMPOSITE,
2757 .data = (const struct snd_usb_audio_quirk[]) {
2758 {
2759 .ifnum = 0,
2760 .type = QUIRK_AUDIO_FIXED_ENDPOINT,
2761 .data = & (const struct audioformat) {
2762 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
2763 .channels = 4,
2764 .iface = 0,
2765 .altsetting = 1,
2766 .altset_idx = 1,
2767 .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE,
2768 .endpoint = 0x01,
2769 .ep_attr = USB_ENDPOINT_XFER_ISOC,
2770 .rates = SNDRV_PCM_RATE_44100 |
2771 SNDRV_PCM_RATE_48000,
2772 .rate_min = 44100,
2773 .rate_max = 48000,
2774 .nr_rates = 2,
2775 .rate_table = (unsigned int[]) {
2776 44100, 48000
2777 }
2778 }
2779 },
2780 {
2781 .ifnum = 1,
2782 .type = QUIRK_MIDI_RAW_BYTES
2783 },
2784 {
2785 .ifnum = -1
2786 }
2787 }
2788 }
2789},
2790{
2751 USB_DEVICE_VENDOR_SPEC(0x1235, 0x4661), 2791 USB_DEVICE_VENDOR_SPEC(0x1235, 0x4661),
2752 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { 2792 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
2753 .vendor_name = "Novation", 2793 .vendor_name = "Novation",
@@ -2996,7 +3036,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
2996 .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE, 3036 .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE,
2997 .endpoint = 0x02, 3037 .endpoint = 0x02,
2998 .ep_attr = 0x01, 3038 .ep_attr = 0x01,
2999 .maxpacksize = 0x130,
3000 .rates = SNDRV_PCM_RATE_44100 | 3039 .rates = SNDRV_PCM_RATE_44100 |
3001 SNDRV_PCM_RATE_48000, 3040 SNDRV_PCM_RATE_48000,
3002 .rate_min = 44100, 3041 .rate_min = 44100,
@@ -3044,7 +3083,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
3044 .attributes = 0x00, 3083 .attributes = 0x00,
3045 .endpoint = 0x03, 3084 .endpoint = 0x03,
3046 .ep_attr = USB_ENDPOINT_SYNC_ASYNC, 3085 .ep_attr = USB_ENDPOINT_SYNC_ASYNC,
3047 .maxpacksize = 0x128,
3048 .rates = SNDRV_PCM_RATE_48000, 3086 .rates = SNDRV_PCM_RATE_48000,
3049 .rate_min = 48000, 3087 .rate_min = 48000,
3050 .rate_max = 48000, 3088 .rate_max = 48000,
@@ -3070,7 +3108,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
3070 .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE, 3108 .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE,
3071 .endpoint = 0x85, 3109 .endpoint = 0x85,
3072 .ep_attr = USB_ENDPOINT_SYNC_SYNC, 3110 .ep_attr = USB_ENDPOINT_SYNC_SYNC,
3073 .maxpacksize = 0x128,
3074 .rates = SNDRV_PCM_RATE_48000, 3111 .rates = SNDRV_PCM_RATE_48000,
3075 .rate_min = 48000, 3112 .rate_min = 48000,
3076 .rate_max = 48000, 3113 .rate_max = 48000,
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 5325a3869bb7..175fbb7d334a 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -165,8 +165,10 @@ static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
165 return -EINVAL; 165 return -EINVAL;
166 } 166 }
167 alts = &iface->altsetting[fp->altset_idx]; 167 alts = &iface->altsetting[fp->altset_idx];
168 fp->datainterval = snd_usb_parse_datainterval(chip, alts); 168 if (fp->datainterval == 0)
169 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); 169 fp->datainterval = snd_usb_parse_datainterval(chip, alts);
170 if (fp->maxpacksize == 0)
171 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
170 usb_set_interface(chip->dev, fp->iface, 0); 172 usb_set_interface(chip->dev, fp->iface, 0);
171 snd_usb_init_pitch(chip, fp->iface, alts, fp); 173 snd_usb_init_pitch(chip, fp->iface, alts, fp);
172 snd_usb_init_sample_rate(chip, fp->iface, alts, fp, fp->rate_max); 174 snd_usb_init_sample_rate(chip, fp->iface, alts, fp, fp->rate_max);
@@ -446,6 +448,17 @@ static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
446} 448}
447 449
448/* 450/*
451 * Novation Twitch DJ controller
452 */
453static int snd_usb_twitch_boot_quirk(struct usb_device *dev)
454{
455 /* preemptively set up the device because otherwise the
456 * raw MIDI endpoints are not active */
457 usb_set_interface(dev, 0, 1);
458 return 0;
459}
460
461/*
449 * This call will put the synth in "USB send" mode, i.e it will send MIDI 462 * This call will put the synth in "USB send" mode, i.e it will send MIDI
450 * messages through USB (this is disabled at startup). The synth will 463 * messages through USB (this is disabled at startup). The synth will
451 * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB 464 * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
@@ -746,6 +759,10 @@ int snd_usb_apply_boot_quirk(struct usb_device *dev,
746 /* Digidesign Mbox 2 */ 759 /* Digidesign Mbox 2 */
747 return snd_usb_mbox2_boot_quirk(dev); 760 return snd_usb_mbox2_boot_quirk(dev);
748 761
762 case USB_ID(0x1235, 0x0018):
763 /* Focusrite Novation Twitch */
764 return snd_usb_twitch_boot_quirk(dev);
765
749 case USB_ID(0x133e, 0x0815): 766 case USB_ID(0x133e, 0x0815):
750 /* Access Music VirusTI Desktop */ 767 /* Access Music VirusTI Desktop */
751 return snd_usb_accessmusic_boot_quirk(dev); 768 return snd_usb_accessmusic_boot_quirk(dev);
@@ -837,6 +854,7 @@ static void set_format_emu_quirk(struct snd_usb_substream *subs,
837 break; 854 break;
838 } 855 }
839 snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id); 856 snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
857 subs->pkt_offset_adj = (emu_samplerate_id >= EMU_QUIRK_SR_176400HZ) ? 4 : 0;
840} 858}
841 859
842void snd_usb_set_format_quirk(struct snd_usb_substream *subs, 860void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
@@ -875,6 +893,16 @@ void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
875 ep->skip_packets = 16; 893 ep->skip_packets = 16;
876} 894}
877 895
896void snd_usb_set_interface_quirk(struct usb_device *dev)
897{
898 /*
899 * "Playback Design" products need a 50ms delay after setting the
900 * USB interface.
901 */
902 if (le16_to_cpu(dev->descriptor.idVendor) == 0x23ba)
903 mdelay(50);
904}
905
878void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe, 906void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
879 __u8 request, __u8 requesttype, __u16 value, 907 __u8 request, __u8 requesttype, __u16 value,
880 __u16 index, void *data, __u16 size) 908 __u16 index, void *data, __u16 size)
diff --git a/sound/usb/quirks.h b/sound/usb/quirks.h
index 0ca9e91067a6..7c3681fd1c3c 100644
--- a/sound/usb/quirks.h
+++ b/sound/usb/quirks.h
@@ -26,6 +26,7 @@ int snd_usb_is_big_endian_format(struct snd_usb_audio *chip,
26 26
27void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep); 27void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep);
28 28
29void snd_usb_set_interface_quirk(struct usb_device *dev);
29void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe, 30void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
30 __u8 request, __u8 requesttype, __u16 value, 31 __u8 request, __u8 requesttype, __u16 value,
31 __u16 index, void *data, __u16 size); 32 __u16 index, void *data, __u16 size);
diff --git a/sound/usb/stream.c b/sound/usb/stream.c
index ad181d538bd9..8951f77a7201 100644
--- a/sound/usb/stream.c
+++ b/sound/usb/stream.c
@@ -42,12 +42,11 @@
42 */ 42 */
43static void free_substream(struct snd_usb_substream *subs) 43static void free_substream(struct snd_usb_substream *subs)
44{ 44{
45 struct list_head *p, *n; 45 struct audioformat *fp, *n;
46 46
47 if (!subs->num_formats) 47 if (!subs->num_formats)
48 return; /* not initialized */ 48 return; /* not initialized */
49 list_for_each_safe(p, n, &subs->fmt_list) { 49 list_for_each_entry_safe(fp, n, &subs->fmt_list, list) {
50 struct audioformat *fp = list_entry(p, struct audioformat, list);
51 kfree(fp->rate_table); 50 kfree(fp->rate_table);
52 kfree(fp->chmap); 51 kfree(fp->chmap);
53 kfree(fp); 52 kfree(fp);
@@ -94,6 +93,7 @@ static void snd_usb_init_substream(struct snd_usb_stream *as,
94 subs->dev = as->chip->dev; 93 subs->dev = as->chip->dev;
95 subs->txfr_quirk = as->chip->txfr_quirk; 94 subs->txfr_quirk = as->chip->txfr_quirk;
96 subs->speed = snd_usb_get_speed(subs->dev); 95 subs->speed = snd_usb_get_speed(subs->dev);
96 subs->pkt_offset_adj = 0;
97 97
98 snd_usb_set_pcm_ops(as->pcm, stream); 98 snd_usb_set_pcm_ops(as->pcm, stream);
99 99
@@ -313,14 +313,12 @@ int snd_usb_add_audio_stream(struct snd_usb_audio *chip,
313 int stream, 313 int stream,
314 struct audioformat *fp) 314 struct audioformat *fp)
315{ 315{
316 struct list_head *p;
317 struct snd_usb_stream *as; 316 struct snd_usb_stream *as;
318 struct snd_usb_substream *subs; 317 struct snd_usb_substream *subs;
319 struct snd_pcm *pcm; 318 struct snd_pcm *pcm;
320 int err; 319 int err;
321 320
322 list_for_each(p, &chip->pcm_list) { 321 list_for_each_entry(as, &chip->pcm_list, list) {
323 as = list_entry(p, struct snd_usb_stream, list);
324 if (as->fmt_type != fp->fmt_type) 322 if (as->fmt_type != fp->fmt_type)
325 continue; 323 continue;
326 subs = &as->substream[stream]; 324 subs = &as->substream[stream];
@@ -332,8 +330,7 @@ int snd_usb_add_audio_stream(struct snd_usb_audio *chip,
332 } 330 }
333 } 331 }
334 /* look for an empty stream */ 332 /* look for an empty stream */
335 list_for_each(p, &chip->pcm_list) { 333 list_for_each_entry(as, &chip->pcm_list, list) {
336 as = list_entry(p, struct snd_usb_stream, list);
337 if (as->fmt_type != fp->fmt_type) 334 if (as->fmt_type != fp->fmt_type)
338 continue; 335 continue;
339 subs = &as->substream[stream]; 336 subs = &as->substream[stream];
@@ -463,7 +460,7 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
463 struct usb_host_interface *alts; 460 struct usb_host_interface *alts;
464 struct usb_interface_descriptor *altsd; 461 struct usb_interface_descriptor *altsd;
465 int i, altno, err, stream; 462 int i, altno, err, stream;
466 int format = 0, num_channels = 0; 463 unsigned int format = 0, num_channels = 0;
467 struct audioformat *fp = NULL; 464 struct audioformat *fp = NULL;
468 int num, protocol, clock = 0; 465 int num, protocol, clock = 0;
469 struct uac_format_type_i_continuous_descriptor *fmt; 466 struct uac_format_type_i_continuous_descriptor *fmt;
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index 1ac3fd9cc5a6..bc43bcaddf4d 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -56,6 +56,7 @@ struct snd_usb_audio {
56 56
57 int setup; /* from the 'device_setup' module param */ 57 int setup; /* from the 'device_setup' module param */
58 int nrpacks; /* from the 'nrpacks' module param */ 58 int nrpacks; /* from the 'nrpacks' module param */
59 bool autoclock; /* from the 'autoclock' module param */
59 60
60 struct usb_host_interface *ctrl_intf; /* the audio control interface */ 61 struct usb_host_interface *ctrl_intf; /* the audio control interface */
61}; 62};