Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'topic/misc' into for-linus

+2336 -1779
+1 -1
Documentation/sound/alsa/ALSA-Configuration.txt
··· 1545 1545 1546 1546 Module for sound cards based on the C-Media CMI8786/8787/8788 chip: 1547 1547 * Asound A-8788 1548 - * Asus Xonar DG 1548 + * Asus Xonar DG/DGX 1549 1549 * AuzenTech X-Meridian 1550 1550 * AuzenTech X-Meridian 2G 1551 1551 * Bgears b-Enspirer
+14
include/sound/asound.h
··· 70 70 71 71 /**************************************************************************** 72 72 * * 73 + * CEA-861 Audio InfoFrame. Used in HDMI and DisplayPort * 74 + * * 75 + ****************************************************************************/ 76 + 77 + struct snd_cea_861_aud_if { 78 + unsigned char db1_ct_cc; /* coding type and channel count */ 79 + unsigned char db2_sf_ss; /* sample frequency and size */ 80 + unsigned char db3; /* not used, all zeros */ 81 + unsigned char db4_ca; /* channel allocation code */ 82 + unsigned char db5_dminh_lsv; /* downmix inhibit & level-shit values */ 83 + }; 84 + 85 + /**************************************************************************** 86 + * * 73 87 * Section for driver hardware dependent interface - /dev/snd/hw? * 74 88 * * 75 89 ****************************************************************************/
+41
include/sound/asoundef.h
··· 170 170 #define IEC958_AES5_CON_CGMSA_COPYNOMORE (2<<0) /* condition not be used */ 171 171 #define IEC958_AES5_CON_CGMSA_COPYNEVER (3<<0) /* no copying is permitted */ 172 172 173 + /**************************************************************************** 174 + * * 175 + * CEA-861 Audio InfoFrame. Used in HDMI and DisplayPort * 176 + * * 177 + ****************************************************************************/ 178 + #define CEA861_AUDIO_INFOFRAME_DB1CC (7<<0) /* mask - channel count */ 179 + #define CEA861_AUDIO_INFOFRAME_DB1CT (0xf<<4) /* mask - coding type */ 180 + #define CEA861_AUDIO_INFOFRAME_DB1CT_FROM_STREAM (0<<4) /* refer to stream */ 181 + #define CEA861_AUDIO_INFOFRAME_DB1CT_IEC60958 (1<<4) /* IEC-60958 L-PCM */ 182 + #define CEA861_AUDIO_INFOFRAME_DB1CT_AC3 (2<<4) /* AC-3 */ 183 + #define CEA861_AUDIO_INFOFRAME_DB1CT_MPEG1 (3<<4) /* MPEG1 Layers 1 & 2 */ 184 + #define CEA861_AUDIO_INFOFRAME_DB1CT_MP3 (4<<4) /* MPEG1 Layer 3 */ 185 + #define CEA861_AUDIO_INFOFRAME_DB1CT_MPEG2_MULTICH (5<<4) /* MPEG2 Multichannel */ 186 + #define CEA861_AUDIO_INFOFRAME_DB1CT_AAC (6<<4) /* AAC */ 187 + #define CEA861_AUDIO_INFOFRAME_DB1CT_DTS (7<<4) /* DTS */ 188 + #define CEA861_AUDIO_INFOFRAME_DB1CT_ATRAC (8<<4) /* ATRAC */ 189 + #define CEA861_AUDIO_INFOFRAME_DB1CT_ONEBIT (9<<4) /* One Bit Audio */ 190 + #define CEA861_AUDIO_INFOFRAME_DB1CT_DOLBY_DIG_PLUS (10<<4) /* Dolby Digital + */ 191 + #define CEA861_AUDIO_INFOFRAME_DB1CT_DTS_HD (11<<4) /* DTS-HD */ 192 + #define CEA861_AUDIO_INFOFRAME_DB1CT_MAT (12<<4) /* MAT (MLP) */ 193 + #define CEA861_AUDIO_INFOFRAME_DB1CT_DST (13<<4) /* DST */ 194 + #define CEA861_AUDIO_INFOFRAME_DB1CT_WMA_PRO (14<<4) /* WMA Pro */ 195 + #define CEA861_AUDIO_INFOFRAME_DB2SF (7<<2) /* mask - sample frequency */ 196 + #define CEA861_AUDIO_INFOFRAME_DB2SF_FROM_STREAM (0<<2) /* refer to stream */ 197 + #define CEA861_AUDIO_INFOFRAME_DB2SF_32000 (1<<2) /* 32kHz */ 198 + #define CEA861_AUDIO_INFOFRAME_DB2SF_44100 (2<<2) /* 44.1kHz */ 199 + #define CEA861_AUDIO_INFOFRAME_DB2SF_48000 (3<<2) /* 48kHz */ 200 + #define CEA861_AUDIO_INFOFRAME_DB2SF_88200 (4<<2) /* 88.2kHz */ 201 + #define CEA861_AUDIO_INFOFRAME_DB2SF_96000 (5<<2) /* 96kHz */ 202 + #define CEA861_AUDIO_INFOFRAME_DB2SF_176400 (6<<2) /* 176.4kHz */ 203 + #define CEA861_AUDIO_INFOFRAME_DB2SF_192000 (7<<2) /* 192kHz */ 204 + #define CEA861_AUDIO_INFOFRAME_DB2SS (3<<0) /* mask - sample size */ 205 + #define CEA861_AUDIO_INFOFRAME_DB2SS_FROM_STREAM (0<<0) /* refer to stream */ 206 + #define CEA861_AUDIO_INFOFRAME_DB2SS_16BIT (1<<0) /* 16 bits */ 207 + #define CEA861_AUDIO_INFOFRAME_DB2SS_20BIT (2<<0) /* 20 bits */ 208 + #define CEA861_AUDIO_INFOFRAME_DB2SS_24BIT (3<<0) /* 24 bits */ 209 + #define CEA861_AUDIO_INFOFRAME_DB5_DM_INH (1<<7) /* mask - inhibit downmixing */ 210 + #define CEA861_AUDIO_INFOFRAME_DB5_DM_INH_PERMITTED (0<<7) /* stereo downmix permitted */ 211 + #define CEA861_AUDIO_INFOFRAME_DB5_DM_INH_PROHIBITED (1<<7) /* stereo downmis prohibited */ 212 + #define CEA861_AUDIO_INFOFRAME_DB5_LSV (0xf<<3) /* mask - level-shift values */ 213 + 173 214 /***************************************************************************** 174 215 * * 175 216 * MIDI v1.0 interface *
+2
sound/atmel/ac97c.c
··· 991 991 gpio_direction_output(pdata->reset_pin, 1); 992 992 chip->reset_pin = pdata->reset_pin; 993 993 } 994 + } else { 995 + chip->reset_pin = -EINVAL; 994 996 } 995 997 996 998 snd_card_set_dev(card, &pdev->dev);
+4 -1
sound/core/jack.c
··· 155 155 * @jack: The jack to configure 156 156 * @parent: The device to set as parent for the jack. 157 157 * 158 - * Set the parent for the jack input device in the device tree. This 158 + * Set the parent for the jack devices in the device tree. This 159 159 * function is only valid prior to registration of the jack. If no 160 160 * parent is configured then the parent device will be the sound card. 161 161 */ ··· 178 178 * reporting of keys on accessories via the jack abstraction. If no 179 179 * mapping is provided but keys are enabled in the jack type then 180 180 * BTN_n numeric buttons will be reported. 181 + * 182 + * If jacks are not reporting via the input API this call will have no 183 + * effect. 181 184 * 182 185 * Note that this is intended to be use by simple devices with small 183 186 * numbers of keys that can be reported. It is also possible to
+10 -8
sound/core/pcm_lib.c
··· 1894 1894 struct snd_pcm_runtime *runtime = substream->runtime; 1895 1895 snd_pcm_uframes_t xfer = 0; 1896 1896 snd_pcm_uframes_t offset = 0; 1897 + snd_pcm_uframes_t avail; 1897 1898 int err = 0; 1898 1899 1899 1900 if (size == 0) ··· 1918 1917 } 1919 1918 1920 1919 runtime->twake = runtime->control->avail_min ? : 1; 1920 + if (runtime->status->state == SNDRV_PCM_STATE_RUNNING) 1921 + snd_pcm_update_hw_ptr(substream); 1922 + avail = snd_pcm_playback_avail(runtime); 1921 1923 while (size > 0) { 1922 1924 snd_pcm_uframes_t frames, appl_ptr, appl_ofs; 1923 - snd_pcm_uframes_t avail; 1924 1925 snd_pcm_uframes_t cont; 1925 - if (runtime->status->state == SNDRV_PCM_STATE_RUNNING) 1926 - snd_pcm_update_hw_ptr(substream); 1927 - avail = snd_pcm_playback_avail(runtime); 1928 1926 if (!avail) { 1929 1927 if (nonblock) { 1930 1928 err = -EAGAIN; ··· 1971 1971 offset += frames; 1972 1972 size -= frames; 1973 1973 xfer += frames; 1974 + avail -= frames; 1974 1975 if (runtime->status->state == SNDRV_PCM_STATE_PREPARED && 1975 1976 snd_pcm_playback_hw_avail(runtime) >= (snd_pcm_sframes_t)runtime->start_threshold) { 1976 1977 err = snd_pcm_start(substream); ··· 2112 2111 struct snd_pcm_runtime *runtime = substream->runtime; 2113 2112 snd_pcm_uframes_t xfer = 0; 2114 2113 snd_pcm_uframes_t offset = 0; 2114 + snd_pcm_uframes_t avail; 2115 2115 int err = 0; 2116 2116 2117 2117 if (size == 0) ··· 2143 2141 } 2144 2142 2145 2143 runtime->twake = runtime->control->avail_min ? : 1; 2144 + if (runtime->status->state == SNDRV_PCM_STATE_RUNNING) 2145 + snd_pcm_update_hw_ptr(substream); 2146 + avail = snd_pcm_capture_avail(runtime); 2146 2147 while (size > 0) { 2147 2148 snd_pcm_uframes_t frames, appl_ptr, appl_ofs; 2148 - snd_pcm_uframes_t avail; 2149 2149 snd_pcm_uframes_t cont; 2150 - if (runtime->status->state == SNDRV_PCM_STATE_RUNNING) 2151 - snd_pcm_update_hw_ptr(substream); 2152 - avail = snd_pcm_capture_avail(runtime); 2153 2150 if (!avail) { 2154 2151 if (runtime->status->state == 2155 2152 SNDRV_PCM_STATE_DRAINING) { ··· 2203 2202 offset += frames; 2204 2203 size -= frames; 2205 2204 xfer += frames; 2205 + avail -= frames; 2206 2206 } 2207 2207 _end_unlock: 2208 2208 runtime->twake = 0;
+11 -1
sound/core/pcm_native.c
··· 1360 1360 1361 1361 static int snd_pcm_pre_drain_init(struct snd_pcm_substream *substream, int state) 1362 1362 { 1363 - substream->runtime->trigger_master = substream; 1363 + struct snd_pcm_runtime *runtime = substream->runtime; 1364 + switch (runtime->status->state) { 1365 + case SNDRV_PCM_STATE_OPEN: 1366 + case SNDRV_PCM_STATE_DISCONNECTED: 1367 + case SNDRV_PCM_STATE_SUSPENDED: 1368 + return -EBADFD; 1369 + } 1370 + runtime->trigger_master = substream; 1364 1371 return 0; 1365 1372 } 1366 1373 ··· 1385 1378 break; 1386 1379 case SNDRV_PCM_STATE_RUNNING: 1387 1380 runtime->status->state = SNDRV_PCM_STATE_DRAINING; 1381 + break; 1382 + case SNDRV_PCM_STATE_XRUN: 1383 + runtime->status->state = SNDRV_PCM_STATE_SETUP; 1388 1384 break; 1389 1385 default: 1390 1386 break;
+3 -3
sound/core/sound_oss.c
··· 35 35 #include <linux/sound.h> 36 36 #include <linux/mutex.h> 37 37 38 - #define SNDRV_OSS_MINORS 128 38 + #define SNDRV_OSS_MINORS 256 39 39 40 40 static struct snd_minor *snd_oss_minors[SNDRV_OSS_MINORS]; 41 41 static DEFINE_MUTEX(sound_oss_mutex); ··· 111 111 int register1 = -1, register2 = -1; 112 112 struct device *carddev = snd_card_get_device_link(card); 113 113 114 - if (card && card->number >= 8) 114 + if (card && card->number >= SNDRV_MINOR_OSS_DEVICES) 115 115 return 0; /* ignore silently */ 116 116 if (minor < 0) 117 117 return minor; ··· 170 170 int track2 = -1; 171 171 struct snd_minor *mptr; 172 172 173 - if (card && card->number >= 8) 173 + if (card && card->number >= SNDRV_MINOR_OSS_DEVICES) 174 174 return 0; 175 175 if (minor < 0) 176 176 return minor;
+35 -27
sound/drivers/aloop.c
··· 117 117 /* timer stuff */ 118 118 unsigned int irq_pos; /* fractional IRQ position */ 119 119 unsigned int period_size_frac; 120 + unsigned int last_drift; 120 121 unsigned long last_jiffies; 121 122 struct timer_list timer; 122 123 }; ··· 265 264 return err; 266 265 dpcm->last_jiffies = jiffies; 267 266 dpcm->pcm_rate_shift = 0; 267 + dpcm->last_drift = 0; 268 268 spin_lock(&cable->lock); 269 269 cable->running |= stream; 270 270 cable->pause &= ~stream; ··· 446 444 } 447 445 } 448 446 449 - #define BYTEPOS_UPDATE_POSONLY 0 450 - #define BYTEPOS_UPDATE_CLEAR 1 451 - #define BYTEPOS_UPDATE_COPY 2 452 - 453 - static void loopback_bytepos_update(struct loopback_pcm *dpcm, 454 - unsigned int delta, 455 - unsigned int cmd) 447 + static inline unsigned int bytepos_delta(struct loopback_pcm *dpcm, 448 + unsigned int jiffies_delta) 456 449 { 457 - unsigned int count; 458 450 unsigned long last_pos; 451 + unsigned int delta; 459 452 460 453 last_pos = byte_pos(dpcm, dpcm->irq_pos); 461 - dpcm->irq_pos += delta * dpcm->pcm_bps; 462 - count = byte_pos(dpcm, dpcm->irq_pos) - last_pos; 463 - if (!count) 464 - return; 465 - if (cmd == BYTEPOS_UPDATE_CLEAR) 466 - clear_capture_buf(dpcm, count); 467 - else if (cmd == BYTEPOS_UPDATE_COPY) 468 - copy_play_buf(dpcm->cable->streams[SNDRV_PCM_STREAM_PLAYBACK], 469 - dpcm->cable->streams[SNDRV_PCM_STREAM_CAPTURE], 470 - count); 471 - dpcm->buf_pos += count; 472 - dpcm->buf_pos %= dpcm->pcm_buffer_size; 454 + dpcm->irq_pos += jiffies_delta * dpcm->pcm_bps; 455 + delta = byte_pos(dpcm, dpcm->irq_pos) - last_pos; 456 + if (delta >= dpcm->last_drift) 457 + delta -= dpcm->last_drift; 458 + dpcm->last_drift = 0; 473 459 if (dpcm->irq_pos >= dpcm->period_size_frac) { 474 460 dpcm->irq_pos %= dpcm->period_size_frac; 475 461 dpcm->period_update_pending = 1; 476 462 } 463 + return delta; 464 + } 465 + 466 + static inline void bytepos_finish(struct loopback_pcm *dpcm, 467 + unsigned int delta) 468 + { 469 + dpcm->buf_pos += delta; 470 + dpcm->buf_pos %= dpcm->pcm_buffer_size; 477 471 } 478 472 479 473 static unsigned int loopback_pos_update(struct loopback_cable *cable) ··· 479 481 struct loopback_pcm *dpcm_capt = 480 482 cable->streams[SNDRV_PCM_STREAM_CAPTURE]; 481 483 unsigned long delta_play = 0, delta_capt = 0; 482 - unsigned int running; 484 + unsigned int running, count1, count2; 483 485 unsigned long flags; 484 486 485 487 spin_lock_irqsave(&cable->lock, flags); ··· 498 500 goto unlock; 499 501 500 502 if (delta_play > delta_capt) { 501 - loopback_bytepos_update(dpcm_play, delta_play - delta_capt, 502 - BYTEPOS_UPDATE_POSONLY); 503 + count1 = bytepos_delta(dpcm_play, delta_play - delta_capt); 504 + bytepos_finish(dpcm_play, count1); 503 505 delta_play = delta_capt; 504 506 } else if (delta_play < delta_capt) { 505 - loopback_bytepos_update(dpcm_capt, delta_capt - delta_play, 506 - BYTEPOS_UPDATE_CLEAR); 507 + count1 = bytepos_delta(dpcm_capt, delta_capt - delta_play); 508 + clear_capture_buf(dpcm_capt, count1); 509 + bytepos_finish(dpcm_capt, count1); 507 510 delta_capt = delta_play; 508 511 } 509 512 ··· 512 513 goto unlock; 513 514 514 515 /* note delta_capt == delta_play at this moment */ 515 - loopback_bytepos_update(dpcm_capt, delta_capt, BYTEPOS_UPDATE_COPY); 516 - loopback_bytepos_update(dpcm_play, delta_play, BYTEPOS_UPDATE_POSONLY); 516 + count1 = bytepos_delta(dpcm_play, delta_play); 517 + count2 = bytepos_delta(dpcm_capt, delta_capt); 518 + if (count1 < count2) { 519 + dpcm_capt->last_drift = count2 - count1; 520 + count1 = count2; 521 + } else if (count1 > count2) { 522 + dpcm_play->last_drift = count1 - count2; 523 + } 524 + copy_play_buf(dpcm_play, dpcm_capt, count1); 525 + bytepos_finish(dpcm_play, count1); 526 + bytepos_finish(dpcm_capt, count1); 517 527 unlock: 518 528 spin_unlock_irqrestore(&cable->lock, flags); 519 529 return running;
+48 -1
sound/firewire/amdtp.c
··· 31 31 #define INTERRUPT_INTERVAL 16 32 32 #define QUEUE_LENGTH 48 33 33 34 + static void pcm_period_tasklet(unsigned long data); 35 + 34 36 /** 35 37 * amdtp_out_stream_init - initialize an AMDTP output stream structure 36 38 * @s: the AMDTP output stream to initialize ··· 49 47 s->flags = flags; 50 48 s->context = ERR_PTR(-1); 51 49 mutex_init(&s->mutex); 50 + tasklet_init(&s->period_tasklet, pcm_period_tasklet, (unsigned long)s); 52 51 s->packet_index = 0; 53 52 54 53 return 0; ··· 166 163 } 167 164 } 168 165 EXPORT_SYMBOL(amdtp_out_stream_set_pcm_format); 166 + 167 + /** 168 + * amdtp_out_stream_pcm_prepare - prepare PCM device for running 169 + * @s: the AMDTP output stream 170 + * 171 + * This function should be called from the PCM device's .prepare callback. 172 + */ 173 + void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s) 174 + { 175 + tasklet_kill(&s->period_tasklet); 176 + s->pcm_buffer_pointer = 0; 177 + s->pcm_period_pointer = 0; 178 + s->pointer_flush = true; 179 + } 180 + EXPORT_SYMBOL(amdtp_out_stream_pcm_prepare); 169 181 170 182 static unsigned int calculate_data_blocks(struct amdtp_out_stream *s) 171 183 { ··· 394 376 s->pcm_period_pointer += data_blocks; 395 377 if (s->pcm_period_pointer >= pcm->runtime->period_size) { 396 378 s->pcm_period_pointer -= pcm->runtime->period_size; 397 - snd_pcm_period_elapsed(pcm); 379 + s->pointer_flush = false; 380 + tasklet_hi_schedule(&s->period_tasklet); 398 381 } 399 382 } 383 + } 384 + 385 + static void pcm_period_tasklet(unsigned long data) 386 + { 387 + struct amdtp_out_stream *s = (void *)data; 388 + struct snd_pcm_substream *pcm = ACCESS_ONCE(s->pcm); 389 + 390 + if (pcm) 391 + snd_pcm_period_elapsed(pcm); 400 392 } 401 393 402 394 static void out_packet_callback(struct fw_iso_context *context, u32 cycle, ··· 534 506 EXPORT_SYMBOL(amdtp_out_stream_start); 535 507 536 508 /** 509 + * amdtp_out_stream_pcm_pointer - get the PCM buffer position 510 + * @s: the AMDTP output stream that transports the PCM data 511 + * 512 + * Returns the current buffer position, in frames. 513 + */ 514 + unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s) 515 + { 516 + /* this optimization is allowed to be racy */ 517 + if (s->pointer_flush) 518 + fw_iso_context_flush_completions(s->context); 519 + else 520 + s->pointer_flush = true; 521 + 522 + return ACCESS_ONCE(s->pcm_buffer_pointer); 523 + } 524 + EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer); 525 + 526 + /** 537 527 * amdtp_out_stream_update - update the stream after a bus reset 538 528 * @s: the AMDTP output stream 539 529 */ ··· 578 532 return; 579 533 } 580 534 535 + tasklet_kill(&s->period_tasklet); 581 536 fw_iso_context_stop(s->context); 582 537 fw_iso_context_destroy(s->context); 583 538 s->context = ERR_PTR(-1);
+5 -24
sound/firewire/amdtp.h
··· 1 1 #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED 2 2 #define SOUND_FIREWIRE_AMDTP_H_INCLUDED 3 3 4 + #include <linux/interrupt.h> 4 5 #include <linux/mutex.h> 5 6 #include <linux/spinlock.h> 6 7 #include "packets-buffer.h" ··· 56 55 struct iso_packets_buffer buffer; 57 56 58 57 struct snd_pcm_substream *pcm; 58 + struct tasklet_struct period_tasklet; 59 59 60 60 int packet_index; 61 61 unsigned int data_block_counter; ··· 68 66 69 67 unsigned int pcm_buffer_pointer; 70 68 unsigned int pcm_period_pointer; 69 + bool pointer_flush; 71 70 }; 72 71 73 72 int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit, ··· 84 81 85 82 void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s, 86 83 snd_pcm_format_t format); 84 + void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s); 85 + unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s); 87 86 void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s); 88 87 89 88 /** ··· 128 123 } 129 124 130 125 /** 131 - * amdtp_out_stream_pcm_prepare - prepare PCM device for running 132 - * @s: the AMDTP output stream 133 - * 134 - * This function should be called from the PCM device's .prepare callback. 135 - */ 136 - static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s) 137 - { 138 - s->pcm_buffer_pointer = 0; 139 - s->pcm_period_pointer = 0; 140 - } 141 - 142 - /** 143 126 * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device 144 127 * @s: the AMDTP output stream 145 128 * @pcm: the PCM device to be started, or %NULL to stop the current device ··· 140 147 struct snd_pcm_substream *pcm) 141 148 { 142 149 ACCESS_ONCE(s->pcm) = pcm; 143 - } 144 - 145 - /** 146 - * amdtp_out_stream_pcm_pointer - get the PCM buffer position 147 - * @s: the AMDTP output stream that transports the PCM data 148 - * 149 - * Returns the current buffer position, in frames. 150 - */ 151 - static inline unsigned long 152 - amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s) 153 - { 154 - return ACCESS_ONCE(s->pcm_buffer_pointer); 155 150 } 156 151 157 152 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
+1 -1
sound/pci/Kconfig
··· 228 228 Say Y here to include support for sound cards based on the 229 229 C-Media CMI8788 (Oxygen HD Audio) chip: 230 230 * Asound A-8788 231 - * Asus Xonar DG 231 + * Asus Xonar DG/DGX 232 232 * AuzenTech X-Meridian 233 233 * AuzenTech X-Meridian 2G 234 234 * Bgears b-Enspirer
+1 -14
sound/pci/ad1889.c
··· 1062 1062 .remove = __devexit_p(snd_ad1889_remove), 1063 1063 }; 1064 1064 1065 - static int __init 1066 - alsa_ad1889_init(void) 1067 - { 1068 - return pci_register_driver(&ad1889_pci_driver); 1069 - } 1070 - 1071 - static void __exit 1072 - alsa_ad1889_fini(void) 1073 - { 1074 - pci_unregister_driver(&ad1889_pci_driver); 1075 - } 1076 - 1077 - module_init(alsa_ad1889_init); 1078 - module_exit(alsa_ad1889_fini); 1065 + module_pci_driver(ad1889_pci_driver);
+2 -13
sound/pci/ali5451/ali5451.c
··· 2294 2294 pci_set_drvdata(pci, NULL); 2295 2295 } 2296 2296 2297 - static struct pci_driver driver = { 2297 + static struct pci_driver ali5451_driver = { 2298 2298 .name = KBUILD_MODNAME, 2299 2299 .id_table = snd_ali_ids, 2300 2300 .probe = snd_ali_probe, ··· 2305 2305 #endif 2306 2306 }; 2307 2307 2308 - static int __init alsa_card_ali_init(void) 2309 - { 2310 - return pci_register_driver(&driver); 2311 - } 2312 - 2313 - static void __exit alsa_card_ali_exit(void) 2314 - { 2315 - pci_unregister_driver(&driver); 2316 - } 2317 - 2318 - module_init(alsa_card_ali_init) 2319 - module_exit(alsa_card_ali_exit) 2308 + module_pci_driver(ali5451_driver);
+2 -13
sound/pci/als300.c
··· 852 852 return 0; 853 853 } 854 854 855 - static struct pci_driver driver = { 855 + static struct pci_driver als300_driver = { 856 856 .name = KBUILD_MODNAME, 857 857 .id_table = snd_als300_ids, 858 858 .probe = snd_als300_probe, ··· 863 863 #endif 864 864 }; 865 865 866 - static int __init alsa_card_als300_init(void) 867 - { 868 - return pci_register_driver(&driver); 869 - } 870 - 871 - static void __exit alsa_card_als300_exit(void) 872 - { 873 - pci_unregister_driver(&driver); 874 - } 875 - 876 - module_init(alsa_card_als300_init) 877 - module_exit(alsa_card_als300_exit) 866 + module_pci_driver(als300_driver);
+2 -13
sound/pci/als4000.c
··· 1036 1036 #endif /* CONFIG_PM */ 1037 1037 1038 1038 1039 - static struct pci_driver driver = { 1039 + static struct pci_driver als4000_driver = { 1040 1040 .name = KBUILD_MODNAME, 1041 1041 .id_table = snd_als4000_ids, 1042 1042 .probe = snd_card_als4000_probe, ··· 1047 1047 #endif 1048 1048 }; 1049 1049 1050 - static int __init alsa_card_als4000_init(void) 1051 - { 1052 - return pci_register_driver(&driver); 1053 - } 1054 - 1055 - static void __exit alsa_card_als4000_exit(void) 1056 - { 1057 - pci_unregister_driver(&driver); 1058 - } 1059 - 1060 - module_init(alsa_card_als4000_init) 1061 - module_exit(alsa_card_als4000_exit) 1050 + module_pci_driver(als4000_driver);
+2 -14
sound/pci/atiixp.c
··· 1700 1700 pci_set_drvdata(pci, NULL); 1701 1701 } 1702 1702 1703 - static struct pci_driver driver = { 1703 + static struct pci_driver atiixp_driver = { 1704 1704 .name = KBUILD_MODNAME, 1705 1705 .id_table = snd_atiixp_ids, 1706 1706 .probe = snd_atiixp_probe, ··· 1711 1711 #endif 1712 1712 }; 1713 1713 1714 - 1715 - static int __init alsa_card_atiixp_init(void) 1716 - { 1717 - return pci_register_driver(&driver); 1718 - } 1719 - 1720 - static void __exit alsa_card_atiixp_exit(void) 1721 - { 1722 - pci_unregister_driver(&driver); 1723 - } 1724 - 1725 - module_init(alsa_card_atiixp_init) 1726 - module_exit(alsa_card_atiixp_exit) 1714 + module_pci_driver(atiixp_driver);
+2 -14
sound/pci/atiixp_modem.c
··· 1331 1331 pci_set_drvdata(pci, NULL); 1332 1332 } 1333 1333 1334 - static struct pci_driver driver = { 1334 + static struct pci_driver atiixp_modem_driver = { 1335 1335 .name = KBUILD_MODNAME, 1336 1336 .id_table = snd_atiixp_ids, 1337 1337 .probe = snd_atiixp_probe, ··· 1342 1342 #endif 1343 1343 }; 1344 1344 1345 - 1346 - static int __init alsa_card_atiixp_init(void) 1347 - { 1348 - return pci_register_driver(&driver); 1349 - } 1350 - 1351 - static void __exit alsa_card_atiixp_exit(void) 1352 - { 1353 - pci_unregister_driver(&driver); 1354 - } 1355 - 1356 - module_init(alsa_card_atiixp_init) 1357 - module_exit(alsa_card_atiixp_exit) 1345 + module_pci_driver(atiixp_modem_driver);
+2 -15
sound/pci/au88x0/au88x0.c
··· 375 375 } 376 376 377 377 // pci_driver definition 378 - static struct pci_driver driver = { 378 + static struct pci_driver vortex_driver = { 379 379 .name = KBUILD_MODNAME, 380 380 .id_table = snd_vortex_ids, 381 381 .probe = snd_vortex_probe, 382 382 .remove = __devexit_p(snd_vortex_remove), 383 383 }; 384 384 385 - // initialization of the module 386 - static int __init alsa_card_vortex_init(void) 387 - { 388 - return pci_register_driver(&driver); 389 - } 390 - 391 - // clean up the module 392 - static void __exit alsa_card_vortex_exit(void) 393 - { 394 - pci_unregister_driver(&driver); 395 - } 396 - 397 - module_init(alsa_card_vortex_init) 398 - module_exit(alsa_card_vortex_exit) 385 + module_pci_driver(vortex_driver);
+3 -20
sound/pci/aw2/aw2-alsa.c
··· 112 112 /********************************* 113 113 * FUNCTION DECLARATIONS 114 114 ********************************/ 115 - static int __init alsa_card_aw2_init(void); 116 - static void __exit alsa_card_aw2_exit(void); 117 115 static int snd_aw2_dev_free(struct snd_device *device); 118 116 static int __devinit snd_aw2_create(struct snd_card *card, 119 117 struct pci_dev *pci, struct aw2 **rchip); ··· 169 171 MODULE_DEVICE_TABLE(pci, snd_aw2_ids); 170 172 171 173 /* pci_driver definition */ 172 - static struct pci_driver driver = { 174 + static struct pci_driver aw2_driver = { 173 175 .name = KBUILD_MODNAME, 174 176 .id_table = snd_aw2_ids, 175 177 .probe = snd_aw2_probe, 176 178 .remove = __devexit_p(snd_aw2_remove), 177 179 }; 180 + 181 + module_pci_driver(aw2_driver); 178 182 179 183 /* operators for playback PCM alsa interface */ 180 184 static struct snd_pcm_ops snd_aw2_playback_ops = { ··· 216 216 /********************************* 217 217 * FUNCTION IMPLEMENTATIONS 218 218 ********************************/ 219 - 220 - /* initialization of the module */ 221 - static int __init alsa_card_aw2_init(void) 222 - { 223 - snd_printdd(KERN_DEBUG "aw2: Load aw2 module\n"); 224 - return pci_register_driver(&driver); 225 - } 226 - 227 - /* clean up the module */ 228 - static void __exit alsa_card_aw2_exit(void) 229 - { 230 - snd_printdd(KERN_DEBUG "aw2: Unload aw2 module\n"); 231 - pci_unregister_driver(&driver); 232 - } 233 - 234 - module_init(alsa_card_aw2_init); 235 - module_exit(alsa_card_aw2_exit); 236 219 237 220 /* component-destructor */ 238 221 static int snd_aw2_dev_free(struct snd_device *device)
+2 -21
sound/pci/azt3328.c
··· 2862 2862 #endif /* CONFIG_PM */ 2863 2863 2864 2864 2865 - static struct pci_driver driver = { 2865 + static struct pci_driver azf3328_driver = { 2866 2866 .name = KBUILD_MODNAME, 2867 2867 .id_table = snd_azf3328_ids, 2868 2868 .probe = snd_azf3328_probe, ··· 2873 2873 #endif 2874 2874 }; 2875 2875 2876 - static int __init 2877 - alsa_card_azf3328_init(void) 2878 - { 2879 - int err; 2880 - snd_azf3328_dbgcallenter(); 2881 - err = pci_register_driver(&driver); 2882 - snd_azf3328_dbgcallleave(); 2883 - return err; 2884 - } 2885 - 2886 - static void __exit 2887 - alsa_card_azf3328_exit(void) 2888 - { 2889 - snd_azf3328_dbgcallenter(); 2890 - pci_unregister_driver(&driver); 2891 - snd_azf3328_dbgcallleave(); 2892 - } 2893 - 2894 - module_init(alsa_card_azf3328_init) 2895 - module_exit(alsa_card_azf3328_exit) 2876 + module_pci_driver(azf3328_driver);
+2 -17
sound/pci/bt87x.c
··· 836 836 {0x7063, 0x2000}, /* pcHDTV HD-2000 TV */ 837 837 }; 838 838 839 - static struct pci_driver driver; 840 - 841 839 /* return the id of the card, or a negative value if it's blacklisted */ 842 840 static int __devinit snd_bt87x_detect_card(struct pci_dev *pci) 843 841 { ··· 962 964 { } 963 965 }; 964 966 965 - static struct pci_driver driver = { 967 + static struct pci_driver bt87x_driver = { 966 968 .name = KBUILD_MODNAME, 967 969 .id_table = snd_bt87x_ids, 968 970 .probe = snd_bt87x_probe, 969 971 .remove = __devexit_p(snd_bt87x_remove), 970 972 }; 971 973 972 - static int __init alsa_card_bt87x_init(void) 973 - { 974 - if (load_all) 975 - driver.id_table = snd_bt87x_default_ids; 976 - return pci_register_driver(&driver); 977 - } 978 - 979 - static void __exit alsa_card_bt87x_exit(void) 980 - { 981 - pci_unregister_driver(&driver); 982 - } 983 - 984 - module_init(alsa_card_bt87x_init) 985 - module_exit(alsa_card_bt87x_exit) 974 + module_pci_driver(bt87x_driver);
+2 -15
sound/pci/ca0106/ca0106_main.c
··· 1932 1932 MODULE_DEVICE_TABLE(pci, snd_ca0106_ids); 1933 1933 1934 1934 // pci_driver definition 1935 - static struct pci_driver driver = { 1935 + static struct pci_driver ca0106_driver = { 1936 1936 .name = KBUILD_MODNAME, 1937 1937 .id_table = snd_ca0106_ids, 1938 1938 .probe = snd_ca0106_probe, ··· 1943 1943 #endif 1944 1944 }; 1945 1945 1946 - // initialization of the module 1947 - static int __init alsa_card_ca0106_init(void) 1948 - { 1949 - return pci_register_driver(&driver); 1950 - } 1951 - 1952 - // clean up the module 1953 - static void __exit alsa_card_ca0106_exit(void) 1954 - { 1955 - pci_unregister_driver(&driver); 1956 - } 1957 - 1958 - module_init(alsa_card_ca0106_init) 1959 - module_exit(alsa_card_ca0106_exit) 1946 + module_pci_driver(ca0106_driver);
+2 -13
sound/pci/cmipci.c
··· 3398 3398 } 3399 3399 #endif /* CONFIG_PM */ 3400 3400 3401 - static struct pci_driver driver = { 3401 + static struct pci_driver cmipci_driver = { 3402 3402 .name = KBUILD_MODNAME, 3403 3403 .id_table = snd_cmipci_ids, 3404 3404 .probe = snd_cmipci_probe, ··· 3409 3409 #endif 3410 3410 }; 3411 3411 3412 - static int __init alsa_card_cmipci_init(void) 3413 - { 3414 - return pci_register_driver(&driver); 3415 - } 3416 - 3417 - static void __exit alsa_card_cmipci_exit(void) 3418 - { 3419 - pci_unregister_driver(&driver); 3420 - } 3421 - 3422 - module_init(alsa_card_cmipci_init) 3423 - module_exit(alsa_card_cmipci_exit) 3412 + module_pci_driver(cmipci_driver);
+2 -13
sound/pci/cs4281.c
··· 2084 2084 } 2085 2085 #endif /* CONFIG_PM */ 2086 2086 2087 - static struct pci_driver driver = { 2087 + static struct pci_driver cs4281_driver = { 2088 2088 .name = KBUILD_MODNAME, 2089 2089 .id_table = snd_cs4281_ids, 2090 2090 .probe = snd_cs4281_probe, ··· 2095 2095 #endif 2096 2096 }; 2097 2097 2098 - static int __init alsa_card_cs4281_init(void) 2099 - { 2100 - return pci_register_driver(&driver); 2101 - } 2102 - 2103 - static void __exit alsa_card_cs4281_exit(void) 2104 - { 2105 - pci_unregister_driver(&driver); 2106 - } 2107 - 2108 - module_init(alsa_card_cs4281_init) 2109 - module_exit(alsa_card_cs4281_exit) 2098 + module_pci_driver(cs4281_driver);
+2 -13
sound/pci/cs46xx/cs46xx.c
··· 161 161 pci_set_drvdata(pci, NULL); 162 162 } 163 163 164 - static struct pci_driver driver = { 164 + static struct pci_driver cs46xx_driver = { 165 165 .name = KBUILD_MODNAME, 166 166 .id_table = snd_cs46xx_ids, 167 167 .probe = snd_card_cs46xx_probe, ··· 172 172 #endif 173 173 }; 174 174 175 - static int __init alsa_card_cs46xx_init(void) 176 - { 177 - return pci_register_driver(&driver); 178 - } 179 - 180 - static void __exit alsa_card_cs46xx_exit(void) 181 - { 182 - pci_unregister_driver(&driver); 183 - } 184 - 185 - module_init(alsa_card_cs46xx_init) 186 - module_exit(alsa_card_cs46xx_exit) 175 + module_pci_driver(cs46xx_driver);
+2 -14
sound/pci/cs5530.c
··· 291 291 return 0; 292 292 } 293 293 294 - static struct pci_driver driver = { 294 + static struct pci_driver cs5530_driver = { 295 295 .name = KBUILD_MODNAME, 296 296 .id_table = snd_cs5530_ids, 297 297 .probe = snd_cs5530_probe, 298 298 .remove = __devexit_p(snd_cs5530_remove), 299 299 }; 300 300 301 - static int __init alsa_card_cs5530_init(void) 302 - { 303 - return pci_register_driver(&driver); 304 - } 305 - 306 - static void __exit alsa_card_cs5530_exit(void) 307 - { 308 - pci_unregister_driver(&driver); 309 - } 310 - 311 - module_init(alsa_card_cs5530_init) 312 - module_exit(alsa_card_cs5530_exit) 313 - 301 + module_pci_driver(cs5530_driver);
+2 -13
sound/pci/cs5535audio/cs5535audio.c
··· 394 394 pci_set_drvdata(pci, NULL); 395 395 } 396 396 397 - static struct pci_driver driver = { 397 + static struct pci_driver cs5535audio_driver = { 398 398 .name = KBUILD_MODNAME, 399 399 .id_table = snd_cs5535audio_ids, 400 400 .probe = snd_cs5535audio_probe, ··· 405 405 #endif 406 406 }; 407 407 408 - static int __init alsa_card_cs5535audio_init(void) 409 - { 410 - return pci_register_driver(&driver); 411 - } 412 - 413 - static void __exit alsa_card_cs5535audio_exit(void) 414 - { 415 - pci_unregister_driver(&driver); 416 - } 417 - 418 - module_init(alsa_card_cs5535audio_init) 419 - module_exit(alsa_card_cs5535audio_exit) 408 + module_pci_driver(cs5535audio_driver); 420 409 421 410 MODULE_AUTHOR("Jaya Kumar"); 422 411 MODULE_LICENSE("GPL");
+1 -12
sound/pci/ctxfi/xfi.c
··· 154 154 #endif 155 155 }; 156 156 157 - static int __init ct_card_init(void) 158 - { 159 - return pci_register_driver(&ct_driver); 160 - } 161 - 162 - static void __exit ct_card_exit(void) 163 - { 164 - pci_unregister_driver(&ct_driver); 165 - } 166 - 167 - module_init(ct_card_init) 168 - module_exit(ct_card_exit) 157 + module_pci_driver(ct_driver);
+2 -20
sound/pci/echoaudio/echoaudio.c
··· 2328 2328 ******************************************************************************/ 2329 2329 2330 2330 /* pci_driver definition */ 2331 - static struct pci_driver driver = { 2331 + static struct pci_driver echo_driver = { 2332 2332 .name = KBUILD_MODNAME, 2333 2333 .id_table = snd_echo_ids, 2334 2334 .probe = snd_echo_probe, ··· 2339 2339 #endif /* CONFIG_PM */ 2340 2340 }; 2341 2341 2342 - 2343 - 2344 - /* initialization of the module */ 2345 - static int __init alsa_card_echo_init(void) 2346 - { 2347 - return pci_register_driver(&driver); 2348 - } 2349 - 2350 - 2351 - 2352 - /* clean up the module */ 2353 - static void __exit alsa_card_echo_exit(void) 2354 - { 2355 - pci_unregister_driver(&driver); 2356 - } 2357 - 2358 - 2359 - module_init(alsa_card_echo_init) 2360 - module_exit(alsa_card_echo_exit) 2342 + module_pci_driver(echo_driver);
+2 -13
sound/pci/emu10k1/emu10k1.c
··· 263 263 } 264 264 #endif 265 265 266 - static struct pci_driver driver = { 266 + static struct pci_driver emu10k1_driver = { 267 267 .name = KBUILD_MODNAME, 268 268 .id_table = snd_emu10k1_ids, 269 269 .probe = snd_card_emu10k1_probe, ··· 274 274 #endif 275 275 }; 276 276 277 - static int __init alsa_card_emu10k1_init(void) 278 - { 279 - return pci_register_driver(&driver); 280 - } 281 - 282 - static void __exit alsa_card_emu10k1_exit(void) 283 - { 284 - pci_unregister_driver(&driver); 285 - } 286 - 287 - module_init(alsa_card_emu10k1_init) 288 - module_exit(alsa_card_emu10k1_exit) 277 + module_pci_driver(emu10k1_driver);
+2 -15
sound/pci/emu10k1/emu10k1x.c
··· 1612 1612 MODULE_DEVICE_TABLE(pci, snd_emu10k1x_ids); 1613 1613 1614 1614 // pci_driver definition 1615 - static struct pci_driver driver = { 1615 + static struct pci_driver emu10k1x_driver = { 1616 1616 .name = KBUILD_MODNAME, 1617 1617 .id_table = snd_emu10k1x_ids, 1618 1618 .probe = snd_emu10k1x_probe, 1619 1619 .remove = __devexit_p(snd_emu10k1x_remove), 1620 1620 }; 1621 1621 1622 - // initialization of the module 1623 - static int __init alsa_card_emu10k1x_init(void) 1624 - { 1625 - return pci_register_driver(&driver); 1626 - } 1627 - 1628 - // clean up the module 1629 - static void __exit alsa_card_emu10k1x_exit(void) 1630 - { 1631 - pci_unregister_driver(&driver); 1632 - } 1633 - 1634 - module_init(alsa_card_emu10k1x_init) 1635 - module_exit(alsa_card_emu10k1x_exit) 1622 + module_pci_driver(emu10k1x_driver);
+2 -13
sound/pci/ens1370.c
··· 2488 2488 pci_set_drvdata(pci, NULL); 2489 2489 } 2490 2490 2491 - static struct pci_driver driver = { 2491 + static struct pci_driver ens137x_driver = { 2492 2492 .name = KBUILD_MODNAME, 2493 2493 .id_table = snd_audiopci_ids, 2494 2494 .probe = snd_audiopci_probe, ··· 2499 2499 #endif 2500 2500 }; 2501 2501 2502 - static int __init alsa_card_ens137x_init(void) 2503 - { 2504 - return pci_register_driver(&driver); 2505 - } 2506 - 2507 - static void __exit alsa_card_ens137x_exit(void) 2508 - { 2509 - pci_unregister_driver(&driver); 2510 - } 2511 - 2512 - module_init(alsa_card_ens137x_init) 2513 - module_exit(alsa_card_ens137x_exit) 2502 + module_pci_driver(ens137x_driver);
+2 -13
sound/pci/es1938.c
··· 1882 1882 pci_set_drvdata(pci, NULL); 1883 1883 } 1884 1884 1885 - static struct pci_driver driver = { 1885 + static struct pci_driver es1938_driver = { 1886 1886 .name = KBUILD_MODNAME, 1887 1887 .id_table = snd_es1938_ids, 1888 1888 .probe = snd_es1938_probe, ··· 1893 1893 #endif 1894 1894 }; 1895 1895 1896 - static int __init alsa_card_es1938_init(void) 1897 - { 1898 - return pci_register_driver(&driver); 1899 - } 1900 - 1901 - static void __exit alsa_card_es1938_exit(void) 1902 - { 1903 - pci_unregister_driver(&driver); 1904 - } 1905 - 1906 - module_init(alsa_card_es1938_init) 1907 - module_exit(alsa_card_es1938_exit) 1896 + module_pci_driver(es1938_driver);
+2 -13
sound/pci/es1968.c
··· 2898 2898 pci_set_drvdata(pci, NULL); 2899 2899 } 2900 2900 2901 - static struct pci_driver driver = { 2901 + static struct pci_driver es1968_driver = { 2902 2902 .name = KBUILD_MODNAME, 2903 2903 .id_table = snd_es1968_ids, 2904 2904 .probe = snd_es1968_probe, ··· 2909 2909 #endif 2910 2910 }; 2911 2911 2912 - static int __init alsa_card_es1968_init(void) 2913 - { 2914 - return pci_register_driver(&driver); 2915 - } 2916 - 2917 - static void __exit alsa_card_es1968_exit(void) 2918 - { 2919 - pci_unregister_driver(&driver); 2920 - } 2921 - 2922 - module_init(alsa_card_es1968_init) 2923 - module_exit(alsa_card_es1968_exit) 2912 + module_pci_driver(es1968_driver);
+2 -13
sound/pci/fm801.c
··· 1416 1416 } 1417 1417 #endif 1418 1418 1419 - static struct pci_driver driver = { 1419 + static struct pci_driver fm801_driver = { 1420 1420 .name = KBUILD_MODNAME, 1421 1421 .id_table = snd_fm801_ids, 1422 1422 .probe = snd_card_fm801_probe, ··· 1427 1427 #endif 1428 1428 }; 1429 1429 1430 - static int __init alsa_card_fm801_init(void) 1431 - { 1432 - return pci_register_driver(&driver); 1433 - } 1434 - 1435 - static void __exit alsa_card_fm801_exit(void) 1436 - { 1437 - pci_unregister_driver(&driver); 1438 - } 1439 - 1440 - module_init(alsa_card_fm801_init) 1441 - module_exit(alsa_card_fm801_exit) 1430 + module_pci_driver(fm801_driver);
+4 -13
sound/pci/hda/hda_intel.c
··· 2566 2566 /* forced codec slots */ 2567 2567 SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103), 2568 2568 SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103), 2569 + /* WinFast VP200 H (Teradici) user reported broken communication */ 2570 + SND_PCI_QUIRK(0x3a21, 0x040d, "WinFast VP200 H", 0x101), 2569 2571 {} 2570 2572 }; 2571 2573 ··· 3156 3154 MODULE_DEVICE_TABLE(pci, azx_ids); 3157 3155 3158 3156 /* pci_driver definition */ 3159 - static struct pci_driver driver = { 3157 + static struct pci_driver azx_driver = { 3160 3158 .name = KBUILD_MODNAME, 3161 3159 .id_table = azx_ids, 3162 3160 .probe = azx_probe, ··· 3167 3165 #endif 3168 3166 }; 3169 3167 3170 - static int __init alsa_card_azx_init(void) 3171 - { 3172 - return pci_register_driver(&driver); 3173 - } 3174 - 3175 - static void __exit alsa_card_azx_exit(void) 3176 - { 3177 - pci_unregister_driver(&driver); 3178 - } 3179 - 3180 - module_init(alsa_card_azx_init) 3181 - module_exit(alsa_card_azx_exit) 3168 + module_pci_driver(azx_driver);
+2 -13
sound/pci/ice1712/ice1712.c
··· 2803 2803 pci_set_drvdata(pci, NULL); 2804 2804 } 2805 2805 2806 - static struct pci_driver driver = { 2806 + static struct pci_driver ice1712_driver = { 2807 2807 .name = KBUILD_MODNAME, 2808 2808 .id_table = snd_ice1712_ids, 2809 2809 .probe = snd_ice1712_probe, 2810 2810 .remove = __devexit_p(snd_ice1712_remove), 2811 2811 }; 2812 2812 2813 - static int __init alsa_card_ice1712_init(void) 2814 - { 2815 - return pci_register_driver(&driver); 2816 - } 2817 - 2818 - static void __exit alsa_card_ice1712_exit(void) 2819 - { 2820 - pci_unregister_driver(&driver); 2821 - } 2822 - 2823 - module_init(alsa_card_ice1712_init) 2824 - module_exit(alsa_card_ice1712_exit) 2813 + module_pci_driver(ice1712_driver);
+2 -13
sound/pci/ice1712/ice1724.c
··· 2873 2873 } 2874 2874 #endif 2875 2875 2876 - static struct pci_driver driver = { 2876 + static struct pci_driver vt1724_driver = { 2877 2877 .name = KBUILD_MODNAME, 2878 2878 .id_table = snd_vt1724_ids, 2879 2879 .probe = snd_vt1724_probe, ··· 2884 2884 #endif 2885 2885 }; 2886 2886 2887 - static int __init alsa_card_ice1724_init(void) 2888 - { 2889 - return pci_register_driver(&driver); 2890 - } 2891 - 2892 - static void __exit alsa_card_ice1724_exit(void) 2893 - { 2894 - pci_unregister_driver(&driver); 2895 - } 2896 - 2897 - module_init(alsa_card_ice1724_init) 2898 - module_exit(alsa_card_ice1724_exit) 2887 + module_pci_driver(vt1724_driver);
+2 -14
sound/pci/intel8x0.c
··· 3338 3338 pci_set_drvdata(pci, NULL); 3339 3339 } 3340 3340 3341 - static struct pci_driver driver = { 3341 + static struct pci_driver intel8x0_driver = { 3342 3342 .name = KBUILD_MODNAME, 3343 3343 .id_table = snd_intel8x0_ids, 3344 3344 .probe = snd_intel8x0_probe, ··· 3349 3349 #endif 3350 3350 }; 3351 3351 3352 - 3353 - static int __init alsa_card_intel8x0_init(void) 3354 - { 3355 - return pci_register_driver(&driver); 3356 - } 3357 - 3358 - static void __exit alsa_card_intel8x0_exit(void) 3359 - { 3360 - pci_unregister_driver(&driver); 3361 - } 3362 - 3363 - module_init(alsa_card_intel8x0_init) 3364 - module_exit(alsa_card_intel8x0_exit) 3352 + module_pci_driver(intel8x0_driver);
+2 -14
sound/pci/intel8x0m.c
··· 1324 1324 pci_set_drvdata(pci, NULL); 1325 1325 } 1326 1326 1327 - static struct pci_driver driver = { 1327 + static struct pci_driver intel8x0m_driver = { 1328 1328 .name = KBUILD_MODNAME, 1329 1329 .id_table = snd_intel8x0m_ids, 1330 1330 .probe = snd_intel8x0m_probe, ··· 1335 1335 #endif 1336 1336 }; 1337 1337 1338 - 1339 - static int __init alsa_card_intel8x0m_init(void) 1340 - { 1341 - return pci_register_driver(&driver); 1342 - } 1343 - 1344 - static void __exit alsa_card_intel8x0m_exit(void) 1345 - { 1346 - pci_unregister_driver(&driver); 1347 - } 1348 - 1349 - module_init(alsa_card_intel8x0m_init) 1350 - module_exit(alsa_card_intel8x0m_exit) 1338 + module_pci_driver(intel8x0m_driver);
+2 -13
sound/pci/korg1212/korg1212.c
··· 2476 2476 pci_set_drvdata(pci, NULL); 2477 2477 } 2478 2478 2479 - static struct pci_driver driver = { 2479 + static struct pci_driver korg1212_driver = { 2480 2480 .name = KBUILD_MODNAME, 2481 2481 .id_table = snd_korg1212_ids, 2482 2482 .probe = snd_korg1212_probe, 2483 2483 .remove = __devexit_p(snd_korg1212_remove), 2484 2484 }; 2485 2485 2486 - static int __init alsa_card_korg1212_init(void) 2487 - { 2488 - return pci_register_driver(&driver); 2489 - } 2490 - 2491 - static void __exit alsa_card_korg1212_exit(void) 2492 - { 2493 - pci_unregister_driver(&driver); 2494 - } 2495 - 2496 - module_init(alsa_card_korg1212_init) 2497 - module_exit(alsa_card_korg1212_exit) 2486 + module_pci_driver(korg1212_driver);
+2 -13
sound/pci/lola/lola.c
··· 770 770 MODULE_DEVICE_TABLE(pci, lola_ids); 771 771 772 772 /* pci_driver definition */ 773 - static struct pci_driver driver = { 773 + static struct pci_driver lola_driver = { 774 774 .name = KBUILD_MODNAME, 775 775 .id_table = lola_ids, 776 776 .probe = lola_probe, 777 777 .remove = __devexit_p(lola_remove), 778 778 }; 779 779 780 - static int __init alsa_card_lola_init(void) 781 - { 782 - return pci_register_driver(&driver); 783 - } 784 - 785 - static void __exit alsa_card_lola_exit(void) 786 - { 787 - pci_unregister_driver(&driver); 788 - } 789 - 790 - module_init(alsa_card_lola_init) 791 - module_exit(alsa_card_lola_exit) 780 + module_pci_driver(lola_driver);
+2 -15
sound/pci/lx6464es/lx6464es.c
··· 1141 1141 } 1142 1142 1143 1143 1144 - static struct pci_driver driver = { 1144 + static struct pci_driver lx6464es_driver = { 1145 1145 .name = KBUILD_MODNAME, 1146 1146 .id_table = snd_lx6464es_ids, 1147 1147 .probe = snd_lx6464es_probe, 1148 1148 .remove = __devexit_p(snd_lx6464es_remove), 1149 1149 }; 1150 1150 1151 - 1152 - /* module initialization */ 1153 - static int __init mod_init(void) 1154 - { 1155 - return pci_register_driver(&driver); 1156 - } 1157 - 1158 - static void __exit mod_exit(void) 1159 - { 1160 - pci_unregister_driver(&driver); 1161 - } 1162 - 1163 - module_init(mod_init); 1164 - module_exit(mod_exit); 1151 + module_pci_driver(lx6464es_driver);
+2 -13
sound/pci/maestro3.c
··· 2837 2837 pci_set_drvdata(pci, NULL); 2838 2838 } 2839 2839 2840 - static struct pci_driver driver = { 2840 + static struct pci_driver m3_driver = { 2841 2841 .name = KBUILD_MODNAME, 2842 2842 .id_table = snd_m3_ids, 2843 2843 .probe = snd_m3_probe, ··· 2848 2848 #endif 2849 2849 }; 2850 2850 2851 - static int __init alsa_card_m3_init(void) 2852 - { 2853 - return pci_register_driver(&driver); 2854 - } 2855 - 2856 - static void __exit alsa_card_m3_exit(void) 2857 - { 2858 - pci_unregister_driver(&driver); 2859 - } 2860 - 2861 - module_init(alsa_card_m3_init) 2862 - module_exit(alsa_card_m3_exit) 2851 + module_pci_driver(m3_driver);
+2 -13
sound/pci/mixart/mixart.c
··· 1380 1380 pci_set_drvdata(pci, NULL); 1381 1381 } 1382 1382 1383 - static struct pci_driver driver = { 1383 + static struct pci_driver mixart_driver = { 1384 1384 .name = KBUILD_MODNAME, 1385 1385 .id_table = snd_mixart_ids, 1386 1386 .probe = snd_mixart_probe, 1387 1387 .remove = __devexit_p(snd_mixart_remove), 1388 1388 }; 1389 1389 1390 - static int __init alsa_card_mixart_init(void) 1391 - { 1392 - return pci_register_driver(&driver); 1393 - } 1394 - 1395 - static void __exit alsa_card_mixart_exit(void) 1396 - { 1397 - pci_unregister_driver(&driver); 1398 - } 1399 - 1400 - module_init(alsa_card_mixart_init) 1401 - module_exit(alsa_card_mixart_exit) 1390 + module_pci_driver(mixart_driver);
+2 -14
sound/pci/nm256/nm256.c
··· 1742 1742 } 1743 1743 1744 1744 1745 - static struct pci_driver driver = { 1745 + static struct pci_driver nm256_driver = { 1746 1746 .name = KBUILD_MODNAME, 1747 1747 .id_table = snd_nm256_ids, 1748 1748 .probe = snd_nm256_probe, ··· 1753 1753 #endif 1754 1754 }; 1755 1755 1756 - 1757 - static int __init alsa_card_nm256_init(void) 1758 - { 1759 - return pci_register_driver(&driver); 1760 - } 1761 - 1762 - static void __exit alsa_card_nm256_exit(void) 1763 - { 1764 - pci_unregister_driver(&driver); 1765 - } 1766 - 1767 - module_init(alsa_card_nm256_init) 1768 - module_exit(alsa_card_nm256_exit) 1756 + module_pci_driver(nm256_driver);
+9 -12
sound/pci/oxygen/oxygen.c
··· 94 94 MODEL_2CH_OUTPUT, 95 95 MODEL_HG2PCI, 96 96 MODEL_XONAR_DG, 97 + MODEL_XONAR_DGX, 97 98 }; 98 99 99 100 static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = { ··· 110 109 { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF }, 111 110 /* Asus Xonar DG */ 112 111 { OXYGEN_PCI_SUBID(0x1043, 0x8467), .driver_data = MODEL_XONAR_DG }, 112 + /* Asus Xonar DGX */ 113 + { OXYGEN_PCI_SUBID(0x1043, 0x8521), .driver_data = MODEL_XONAR_DGX }, 113 114 /* PCI 2.0 HD Audio */ 114 115 { OXYGEN_PCI_SUBID(0x13f6, 0x8782), .driver_data = MODEL_2CH_OUTPUT }, 115 116 /* Kuroutoshikou CMI8787-HG2PCI */ ··· 830 827 break; 831 828 case MODEL_XONAR_DG: 832 829 chip->model = model_xonar_dg; 830 + chip->model.shortname = "Xonar DG"; 831 + break; 832 + case MODEL_XONAR_DGX: 833 + chip->model = model_xonar_dg; 834 + chip->model.shortname = "Xonar DGX"; 833 835 break; 834 836 } 835 837 if (id->driver_data == MODEL_MERIDIAN || ··· 878 870 #endif 879 871 }; 880 872 881 - static int __init alsa_card_oxygen_init(void) 882 - { 883 - return pci_register_driver(&oxygen_driver); 884 - } 885 - 886 - static void __exit alsa_card_oxygen_exit(void) 887 - { 888 - pci_unregister_driver(&oxygen_driver); 889 - } 890 - 891 - module_init(alsa_card_oxygen_init) 892 - module_exit(alsa_card_oxygen_exit) 873 + module_pci_driver(oxygen_driver);
+1 -12
sound/pci/oxygen/virtuoso.c
··· 100 100 .shutdown = oxygen_pci_shutdown, 101 101 }; 102 102 103 - static int __init alsa_card_xonar_init(void) 104 - { 105 - return pci_register_driver(&xonar_driver); 106 - } 107 - 108 - static void __exit alsa_card_xonar_exit(void) 109 - { 110 - pci_unregister_driver(&xonar_driver); 111 - } 112 - 113 - module_init(alsa_card_xonar_init) 114 - module_exit(alsa_card_xonar_exit) 103 + module_pci_driver(xonar_driver);
+3 -4
sound/pci/oxygen/xonar_dg.c
··· 1 1 /* 2 - * card driver for the Xonar DG 2 + * card driver for the Xonar DG/DGX 3 3 * 4 4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de> 5 5 * ··· 17 17 */ 18 18 19 19 /* 20 - * Xonar DG 21 - * -------- 20 + * Xonar DG/DGX 21 + * ------------ 22 22 * 23 23 * CMI8788: 24 24 * ··· 581 581 } 582 582 583 583 struct oxygen_model model_xonar_dg = { 584 - .shortname = "Xonar DG", 585 584 .longname = "C-Media Oxygen HD Audio", 586 585 .chip = "CMI8786", 587 586 .init = dg_init,
+2 -13
sound/pci/pcxhr/pcxhr.c
··· 1607 1607 pci_set_drvdata(pci, NULL); 1608 1608 } 1609 1609 1610 - static struct pci_driver driver = { 1610 + static struct pci_driver pcxhr_driver = { 1611 1611 .name = KBUILD_MODNAME, 1612 1612 .id_table = pcxhr_ids, 1613 1613 .probe = pcxhr_probe, 1614 1614 .remove = __devexit_p(pcxhr_remove), 1615 1615 }; 1616 1616 1617 - static int __init pcxhr_module_init(void) 1618 - { 1619 - return pci_register_driver(&driver); 1620 - } 1621 - 1622 - static void __exit pcxhr_module_exit(void) 1623 - { 1624 - pci_unregister_driver(&driver); 1625 - } 1626 - 1627 - module_init(pcxhr_module_init) 1628 - module_exit(pcxhr_module_exit) 1617 + module_pci_driver(pcxhr_driver);
+1 -2
sound/pci/riptide/riptide.c
··· 1837 1837 } 1838 1838 if (chip->irq >= 0) 1839 1839 free_irq(chip->irq, chip); 1840 - if (chip->fw_entry) 1841 - release_firmware(chip->fw_entry); 1840 + release_firmware(chip->fw_entry); 1842 1841 release_and_free_resource(chip->res_port); 1843 1842 kfree(chip); 1844 1843 return 0;
+2 -13
sound/pci/rme32.c
··· 1984 1984 pci_set_drvdata(pci, NULL); 1985 1985 } 1986 1986 1987 - static struct pci_driver driver = { 1987 + static struct pci_driver rme32_driver = { 1988 1988 .name = KBUILD_MODNAME, 1989 1989 .id_table = snd_rme32_ids, 1990 1990 .probe = snd_rme32_probe, 1991 1991 .remove = __devexit_p(snd_rme32_remove), 1992 1992 }; 1993 1993 1994 - static int __init alsa_card_rme32_init(void) 1995 - { 1996 - return pci_register_driver(&driver); 1997 - } 1998 - 1999 - static void __exit alsa_card_rme32_exit(void) 2000 - { 2001 - pci_unregister_driver(&driver); 2002 - } 2003 - 2004 - module_init(alsa_card_rme32_init) 2005 - module_exit(alsa_card_rme32_exit) 1994 + module_pci_driver(rme32_driver);
+2 -13
sound/pci/rme96.c
··· 2395 2395 pci_set_drvdata(pci, NULL); 2396 2396 } 2397 2397 2398 - static struct pci_driver driver = { 2398 + static struct pci_driver rme96_driver = { 2399 2399 .name = KBUILD_MODNAME, 2400 2400 .id_table = snd_rme96_ids, 2401 2401 .probe = snd_rme96_probe, 2402 2402 .remove = __devexit_p(snd_rme96_remove), 2403 2403 }; 2404 2404 2405 - static int __init alsa_card_rme96_init(void) 2406 - { 2407 - return pci_register_driver(&driver); 2408 - } 2409 - 2410 - static void __exit alsa_card_rme96_exit(void) 2411 - { 2412 - pci_unregister_driver(&driver); 2413 - } 2414 - 2415 - module_init(alsa_card_rme96_init) 2416 - module_exit(alsa_card_rme96_exit) 2405 + module_pci_driver(rme96_driver);
+2 -13
sound/pci/rme9652/hdsp.c
··· 5636 5636 pci_set_drvdata(pci, NULL); 5637 5637 } 5638 5638 5639 - static struct pci_driver driver = { 5639 + static struct pci_driver hdsp_driver = { 5640 5640 .name = KBUILD_MODNAME, 5641 5641 .id_table = snd_hdsp_ids, 5642 5642 .probe = snd_hdsp_probe, 5643 5643 .remove = __devexit_p(snd_hdsp_remove), 5644 5644 }; 5645 5645 5646 - static int __init alsa_card_hdsp_init(void) 5647 - { 5648 - return pci_register_driver(&driver); 5649 - } 5650 - 5651 - static void __exit alsa_card_hdsp_exit(void) 5652 - { 5653 - pci_unregister_driver(&driver); 5654 - } 5655 - 5656 - module_init(alsa_card_hdsp_init) 5657 - module_exit(alsa_card_hdsp_exit) 5646 + module_pci_driver(hdsp_driver);
+2 -14
sound/pci/rme9652/hdspm.c
··· 6918 6918 pci_set_drvdata(pci, NULL); 6919 6919 } 6920 6920 6921 - static struct pci_driver driver = { 6921 + static struct pci_driver hdspm_driver = { 6922 6922 .name = KBUILD_MODNAME, 6923 6923 .id_table = snd_hdspm_ids, 6924 6924 .probe = snd_hdspm_probe, 6925 6925 .remove = __devexit_p(snd_hdspm_remove), 6926 6926 }; 6927 6927 6928 - 6929 - static int __init alsa_card_hdspm_init(void) 6930 - { 6931 - return pci_register_driver(&driver); 6932 - } 6933 - 6934 - static void __exit alsa_card_hdspm_exit(void) 6935 - { 6936 - pci_unregister_driver(&driver); 6937 - } 6938 - 6939 - module_init(alsa_card_hdspm_init) 6940 - module_exit(alsa_card_hdspm_exit) 6928 + module_pci_driver(hdspm_driver);
+2 -13
sound/pci/rme9652/rme9652.c
··· 2631 2631 pci_set_drvdata(pci, NULL); 2632 2632 } 2633 2633 2634 - static struct pci_driver driver = { 2634 + static struct pci_driver rme9652_driver = { 2635 2635 .name = KBUILD_MODNAME, 2636 2636 .id_table = snd_rme9652_ids, 2637 2637 .probe = snd_rme9652_probe, 2638 2638 .remove = __devexit_p(snd_rme9652_remove), 2639 2639 }; 2640 2640 2641 - static int __init alsa_card_hammerfall_init(void) 2642 - { 2643 - return pci_register_driver(&driver); 2644 - } 2645 - 2646 - static void __exit alsa_card_hammerfall_exit(void) 2647 - { 2648 - pci_unregister_driver(&driver); 2649 - } 2650 - 2651 - module_init(alsa_card_hammerfall_init) 2652 - module_exit(alsa_card_hammerfall_exit) 2641 + module_pci_driver(rme9652_driver);
+1 -12
sound/pci/sis7019.c
··· 1488 1488 #endif 1489 1489 }; 1490 1490 1491 - static int __init sis7019_init(void) 1492 - { 1493 - return pci_register_driver(&sis7019_driver); 1494 - } 1495 - 1496 - static void __exit sis7019_exit(void) 1497 - { 1498 - pci_unregister_driver(&sis7019_driver); 1499 - } 1500 - 1501 - module_init(sis7019_init); 1502 - module_exit(sis7019_exit); 1491 + module_pci_driver(sis7019_driver);
+2 -13
sound/pci/sonicvibes.c
··· 1530 1530 pci_set_drvdata(pci, NULL); 1531 1531 } 1532 1532 1533 - static struct pci_driver driver = { 1533 + static struct pci_driver sonicvibes_driver = { 1534 1534 .name = KBUILD_MODNAME, 1535 1535 .id_table = snd_sonic_ids, 1536 1536 .probe = snd_sonic_probe, 1537 1537 .remove = __devexit_p(snd_sonic_remove), 1538 1538 }; 1539 1539 1540 - static int __init alsa_card_sonicvibes_init(void) 1541 - { 1542 - return pci_register_driver(&driver); 1543 - } 1544 - 1545 - static void __exit alsa_card_sonicvibes_exit(void) 1546 - { 1547 - pci_unregister_driver(&driver); 1548 - } 1549 - 1550 - module_init(alsa_card_sonicvibes_init) 1551 - module_exit(alsa_card_sonicvibes_exit) 1540 + module_pci_driver(sonicvibes_driver);
+2 -13
sound/pci/trident/trident.c
··· 172 172 pci_set_drvdata(pci, NULL); 173 173 } 174 174 175 - static struct pci_driver driver = { 175 + static struct pci_driver trident_driver = { 176 176 .name = KBUILD_MODNAME, 177 177 .id_table = snd_trident_ids, 178 178 .probe = snd_trident_probe, ··· 183 183 #endif 184 184 }; 185 185 186 - static int __init alsa_card_trident_init(void) 187 - { 188 - return pci_register_driver(&driver); 189 - } 190 - 191 - static void __exit alsa_card_trident_exit(void) 192 - { 193 - pci_unregister_driver(&driver); 194 - } 195 - 196 - module_init(alsa_card_trident_init) 197 - module_exit(alsa_card_trident_exit) 186 + module_pci_driver(trident_driver);
+2 -13
sound/pci/via82xx.c
··· 2619 2619 pci_set_drvdata(pci, NULL); 2620 2620 } 2621 2621 2622 - static struct pci_driver driver = { 2622 + static struct pci_driver via82xx_driver = { 2623 2623 .name = KBUILD_MODNAME, 2624 2624 .id_table = snd_via82xx_ids, 2625 2625 .probe = snd_via82xx_probe, ··· 2630 2630 #endif 2631 2631 }; 2632 2632 2633 - static int __init alsa_card_via82xx_init(void) 2634 - { 2635 - return pci_register_driver(&driver); 2636 - } 2637 - 2638 - static void __exit alsa_card_via82xx_exit(void) 2639 - { 2640 - pci_unregister_driver(&driver); 2641 - } 2642 - 2643 - module_init(alsa_card_via82xx_init) 2644 - module_exit(alsa_card_via82xx_exit) 2633 + module_pci_driver(via82xx_driver);
+2 -13
sound/pci/via82xx_modem.c
··· 1223 1223 pci_set_drvdata(pci, NULL); 1224 1224 } 1225 1225 1226 - static struct pci_driver driver = { 1226 + static struct pci_driver via82xx_modem_driver = { 1227 1227 .name = KBUILD_MODNAME, 1228 1228 .id_table = snd_via82xx_modem_ids, 1229 1229 .probe = snd_via82xx_probe, ··· 1234 1234 #endif 1235 1235 }; 1236 1236 1237 - static int __init alsa_card_via82xx_init(void) 1238 - { 1239 - return pci_register_driver(&driver); 1240 - } 1241 - 1242 - static void __exit alsa_card_via82xx_exit(void) 1243 - { 1244 - pci_unregister_driver(&driver); 1245 - } 1246 - 1247 - module_init(alsa_card_via82xx_init) 1248 - module_exit(alsa_card_via82xx_exit) 1237 + module_pci_driver(via82xx_modem_driver);
+2 -13
sound/pci/vx222/vx222.c
··· 289 289 } 290 290 #endif 291 291 292 - static struct pci_driver driver = { 292 + static struct pci_driver vx222_driver = { 293 293 .name = KBUILD_MODNAME, 294 294 .id_table = snd_vx222_ids, 295 295 .probe = snd_vx222_probe, ··· 300 300 #endif 301 301 }; 302 302 303 - static int __init alsa_card_vx222_init(void) 304 - { 305 - return pci_register_driver(&driver); 306 - } 307 - 308 - static void __exit alsa_card_vx222_exit(void) 309 - { 310 - pci_unregister_driver(&driver); 311 - } 312 - 313 - module_init(alsa_card_vx222_init) 314 - module_exit(alsa_card_vx222_exit) 303 + module_pci_driver(vx222_driver);
+2 -13
sound/pci/ymfpci/ymfpci.c
··· 350 350 pci_set_drvdata(pci, NULL); 351 351 } 352 352 353 - static struct pci_driver driver = { 353 + static struct pci_driver ymfpci_driver = { 354 354 .name = KBUILD_MODNAME, 355 355 .id_table = snd_ymfpci_ids, 356 356 .probe = snd_card_ymfpci_probe, ··· 361 361 #endif 362 362 }; 363 363 364 - static int __init alsa_card_ymfpci_init(void) 365 - { 366 - return pci_register_driver(&driver); 367 - } 368 - 369 - static void __exit alsa_card_ymfpci_exit(void) 370 - { 371 - pci_unregister_driver(&driver); 372 - } 373 - 374 - module_init(alsa_card_ymfpci_init) 375 - module_exit(alsa_card_ymfpci_exit) 364 + module_pci_driver(ymfpci_driver);
+2 -2
sound/sh/sh_dac_audio.c
··· 433 433 /* 434 434 * "driver" definition 435 435 */ 436 - static struct platform_driver driver = { 436 + static struct platform_driver sh_dac_driver = { 437 437 .probe = snd_sh_dac_probe, 438 438 .remove = snd_sh_dac_remove, 439 439 .driver = { ··· 441 441 }, 442 442 }; 443 443 444 - module_platform_driver(driver); 444 + module_platform_driver(sh_dac_driver);
+1 -1
sound/sound_core.c
··· 361 361 struct device *dev) 362 362 { 363 363 const int chain = unit % SOUND_STEP; 364 - int max_unit = 128 + chain; 364 + int max_unit = 256; 365 365 const char *name; 366 366 char _name[16]; 367 367
+9 -1
sound/usb/card.c
··· 131 131 subs = &as->substream[idx]; 132 132 if (!subs->num_formats) 133 133 continue; 134 - snd_usb_release_substream_urbs(subs, 1); 135 134 subs->interface = -1; 135 + subs->data_endpoint = NULL; 136 + subs->sync_endpoint = NULL; 136 137 } 137 138 } 138 139 ··· 277 276 278 277 static int snd_usb_audio_free(struct snd_usb_audio *chip) 279 278 { 279 + mutex_destroy(&chip->mutex); 280 280 kfree(chip); 281 281 return 0; 282 282 } ··· 338 336 return -ENOMEM; 339 337 } 340 338 339 + mutex_init(&chip->mutex); 341 340 mutex_init(&chip->shutdown_mutex); 342 341 chip->index = idx; 343 342 chip->dev = dev; ··· 351 348 chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), 352 349 le16_to_cpu(dev->descriptor.idProduct)); 353 350 INIT_LIST_HEAD(&chip->pcm_list); 351 + INIT_LIST_HEAD(&chip->ep_list); 354 352 INIT_LIST_HEAD(&chip->midi_list); 355 353 INIT_LIST_HEAD(&chip->mixer_list); 356 354 ··· 568 564 /* release the pcm resources */ 569 565 list_for_each(p, &chip->pcm_list) { 570 566 snd_usb_stream_disconnect(p); 567 + } 568 + /* release the endpoint resources */ 569 + list_for_each(p, &chip->ep_list) { 570 + snd_usb_endpoint_free(p); 571 571 } 572 572 /* release the midi resources */ 573 573 list_for_each(p, &chip->midi_list) {
+60 -26
sound/usb/card.h
··· 30 30 }; 31 31 32 32 struct snd_usb_substream; 33 + struct snd_usb_endpoint; 33 34 34 35 struct snd_urb_ctx { 35 36 struct urb *urb; 36 37 unsigned int buffer_size; /* size of data buffer, if data URB */ 37 38 struct snd_usb_substream *subs; 39 + struct snd_usb_endpoint *ep; 38 40 int index; /* index for urb array */ 39 41 int packets; /* number of packets per urb */ 42 + int packet_size[MAX_PACKS_HS]; /* size of packets for next submission */ 43 + struct list_head ready_list; 40 44 }; 41 45 42 - struct snd_urb_ops { 43 - int (*prepare)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u); 44 - int (*retire)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u); 45 - int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u); 46 - int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u); 46 + struct snd_usb_endpoint { 47 + struct snd_usb_audio *chip; 48 + 49 + int use_count; 50 + int ep_num; /* the referenced endpoint number */ 51 + int type; /* SND_USB_ENDPOINT_TYPE_* */ 52 + unsigned long flags; 53 + 54 + void (*prepare_data_urb) (struct snd_usb_substream *subs, 55 + struct urb *urb); 56 + void (*retire_data_urb) (struct snd_usb_substream *subs, 57 + struct urb *urb); 58 + 59 + struct snd_usb_substream *data_subs; 60 + struct snd_usb_endpoint *sync_master; 61 + struct snd_usb_endpoint *sync_slave; 62 + 63 + struct snd_urb_ctx urb[MAX_URBS]; 64 + 65 + struct snd_usb_packet_info { 66 + uint32_t packet_size[MAX_PACKS_HS]; 67 + int packets; 68 + } next_packet[MAX_URBS]; 69 + int next_packet_read_pos, next_packet_write_pos; 70 + struct list_head ready_playback_urbs; 71 + 72 + unsigned int nurbs; /* # urbs */ 73 + unsigned long active_mask; /* bitmask of active urbs */ 74 + unsigned long unlink_mask; /* bitmask of unlinked urbs */ 75 + char *syncbuf; /* sync buffer for all sync URBs */ 76 + dma_addr_t sync_dma; /* DMA address of syncbuf */ 77 + 78 + unsigned int pipe; /* the data i/o pipe */ 79 + unsigned int freqn; /* nominal sampling rate in fs/fps in Q16.16 format */ 80 + unsigned int freqm; /* momentary sampling rate in fs/fps in Q16.16 format */ 81 + int freqshift; /* how much to shift the feedback value to get Q16.16 */ 82 + unsigned int freqmax; /* maximum sampling rate, used for buffer management */ 83 + unsigned int phase; /* phase accumulator */ 84 + unsigned int maxpacksize; /* max packet size in bytes */ 85 + unsigned int maxframesize; /* max packet size in frames */ 86 + unsigned int curpacksize; /* current packet size in bytes (for capture) */ 87 + unsigned int curframesize; /* current packet size in frames (for capture) */ 88 + unsigned int syncmaxsize; /* sync endpoint packet size */ 89 + unsigned int fill_max:1; /* fill max packet size always */ 90 + unsigned int datainterval; /* log_2 of data packet interval */ 91 + unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */ 92 + unsigned char silence_value; 93 + unsigned int stride; 94 + int iface, alt_idx; 95 + 96 + spinlock_t lock; 97 + struct list_head list; 47 98 }; 48 99 49 100 struct snd_usb_substream { ··· 108 57 unsigned int cur_rate; /* current rate (for hw_params callback) */ 109 58 unsigned int period_bytes; /* current period bytes (for hw_params callback) */ 110 59 unsigned int altset_idx; /* USB data format: index of alternate setting */ 111 - unsigned int datapipe; /* the data i/o pipe */ 112 - unsigned int syncpipe; /* 1 - async out or adaptive in */ 113 - unsigned int datainterval; /* log_2 of data packet interval */ 114 - unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */ 115 - unsigned int freqn; /* nominal sampling rate in fs/fps in Q16.16 format */ 116 - unsigned int freqm; /* momentary sampling rate in fs/fps in Q16.16 format */ 117 - int freqshift; /* how much to shift the feedback value to get Q16.16 */ 118 - unsigned int freqmax; /* maximum sampling rate, used for buffer management */ 119 - unsigned int phase; /* phase accumulator */ 120 - unsigned int maxpacksize; /* max packet size in bytes */ 121 - unsigned int maxframesize; /* max packet size in frames */ 122 - unsigned int curpacksize; /* current packet size in bytes (for capture) */ 123 - unsigned int curframesize; /* current packet size in frames (for capture) */ 124 - unsigned int syncmaxsize; /* sync endpoint packet size */ 125 - unsigned int fill_max: 1; /* fill max packet size always */ 126 60 unsigned int txfr_quirk:1; /* allow sub-frame alignment */ 127 61 unsigned int fmt_type; /* USB audio format type (1-3) */ 128 62 ··· 118 82 unsigned long active_mask; /* bitmask of active urbs */ 119 83 unsigned long unlink_mask; /* bitmask of unlinked urbs */ 120 84 121 - unsigned int nurbs; /* # urbs */ 122 - struct snd_urb_ctx dataurb[MAX_URBS]; /* data urb table */ 123 - struct snd_urb_ctx syncurb[SYNC_URBS]; /* sync urb table */ 124 - char *syncbuf; /* sync buffer for all sync URBs */ 125 - dma_addr_t sync_dma; /* DMA address of syncbuf */ 85 + /* data and sync endpoints for this stream */ 86 + struct snd_usb_endpoint *data_endpoint; 87 + struct snd_usb_endpoint *sync_endpoint; 88 + unsigned long flags; 126 89 127 90 u64 formats; /* format bitmasks (all or'ed) */ 128 91 unsigned int num_formats; /* number of supported audio formats (list) */ ··· 129 94 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */ 130 95 spinlock_t lock; 131 96 132 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */ 133 97 int last_frame_number; /* stored frame number */ 134 98 int last_delay; /* stored delay */ 135 99 };
+1034 -839
sound/usb/endpoint.c
··· 20 20 #include <linux/ratelimit.h> 21 21 #include <linux/usb.h> 22 22 #include <linux/usb/audio.h> 23 + #include <linux/slab.h> 23 24 24 25 #include <sound/core.h> 25 26 #include <sound/pcm.h> 27 + #include <sound/pcm_params.h> 26 28 27 29 #include "usbaudio.h" 28 30 #include "helper.h" 29 31 #include "card.h" 30 32 #include "endpoint.h" 31 33 #include "pcm.h" 34 + 35 + #define EP_FLAG_ACTIVATED 0 36 + #define EP_FLAG_RUNNING 1 37 + 38 + /* 39 + * snd_usb_endpoint is a model that abstracts everything related to an 40 + * USB endpoint and its streaming. 41 + * 42 + * There are functions to activate and deactivate the streaming URBs and 43 + * optional callbacks to let the pcm logic handle the actual content of the 44 + * packets for playback and record. Thus, the bus streaming and the audio 45 + * handlers are fully decoupled. 46 + * 47 + * There are two different types of endpoints in audio applications. 48 + * 49 + * SND_USB_ENDPOINT_TYPE_DATA handles full audio data payload for both 50 + * inbound and outbound traffic. 51 + * 52 + * SND_USB_ENDPOINT_TYPE_SYNC endpoints are for inbound traffic only and 53 + * expect the payload to carry Q10.14 / Q16.16 formatted sync information 54 + * (3 or 4 bytes). 55 + * 56 + * Each endpoint has to be configured prior to being used by calling 57 + * snd_usb_endpoint_set_params(). 58 + * 59 + * The model incorporates a reference counting, so that multiple users 60 + * can call snd_usb_endpoint_start() and snd_usb_endpoint_stop(), and 61 + * only the first user will effectively start the URBs, and only the last 62 + * one to stop it will tear the URBs down again. 63 + */ 32 64 33 65 /* 34 66 * convert a sampling rate into our full speed format (fs/1000 in Q16.16) ··· 81 49 } 82 50 83 51 /* 84 - * unlink active urbs. 85 - */ 86 - static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sleep) 87 - { 88 - struct snd_usb_audio *chip = subs->stream->chip; 89 - unsigned int i; 90 - int async; 91 - 92 - subs->running = 0; 93 - 94 - if (!force && subs->stream->chip->shutdown) /* to be sure... */ 95 - return -EBADFD; 96 - 97 - async = !can_sleep && chip->async_unlink; 98 - 99 - if (!async && in_interrupt()) 100 - return 0; 101 - 102 - for (i = 0; i < subs->nurbs; i++) { 103 - if (test_bit(i, &subs->active_mask)) { 104 - if (!test_and_set_bit(i, &subs->unlink_mask)) { 105 - struct urb *u = subs->dataurb[i].urb; 106 - if (async) 107 - usb_unlink_urb(u); 108 - else 109 - usb_kill_urb(u); 110 - } 111 - } 112 - } 113 - if (subs->syncpipe) { 114 - for (i = 0; i < SYNC_URBS; i++) { 115 - if (test_bit(i+16, &subs->active_mask)) { 116 - if (!test_and_set_bit(i+16, &subs->unlink_mask)) { 117 - struct urb *u = subs->syncurb[i].urb; 118 - if (async) 119 - usb_unlink_urb(u); 120 - else 121 - usb_kill_urb(u); 122 - } 123 - } 124 - } 125 - } 126 - return 0; 127 - } 128 - 129 - 130 - /* 131 52 * release a urb data 132 53 */ 133 54 static void release_urb_ctx(struct snd_urb_ctx *u) 134 55 { 135 - if (u->urb) { 136 - if (u->buffer_size) 137 - usb_free_coherent(u->subs->dev, u->buffer_size, 138 - u->urb->transfer_buffer, 139 - u->urb->transfer_dma); 140 - usb_free_urb(u->urb); 141 - u->urb = NULL; 142 - } 143 - } 144 - 145 - /* 146 - * wait until all urbs are processed. 147 - */ 148 - static int wait_clear_urbs(struct snd_usb_substream *subs) 149 - { 150 - unsigned long end_time = jiffies + msecs_to_jiffies(1000); 151 - unsigned int i; 152 - int alive; 153 - 154 - do { 155 - alive = 0; 156 - for (i = 0; i < subs->nurbs; i++) { 157 - if (test_bit(i, &subs->active_mask)) 158 - alive++; 159 - } 160 - if (subs->syncpipe) { 161 - for (i = 0; i < SYNC_URBS; i++) { 162 - if (test_bit(i + 16, &subs->active_mask)) 163 - alive++; 164 - } 165 - } 166 - if (! alive) 167 - break; 168 - schedule_timeout_uninterruptible(1); 169 - } while (time_before(jiffies, end_time)); 170 - if (alive) 171 - snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive); 172 - return 0; 173 - } 174 - 175 - /* 176 - * release a substream 177 - */ 178 - void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force) 179 - { 180 - int i; 181 - 182 - /* stop urbs (to be sure) */ 183 - deactivate_urbs(subs, force, 1); 184 - wait_clear_urbs(subs); 185 - 186 - for (i = 0; i < MAX_URBS; i++) 187 - release_urb_ctx(&subs->dataurb[i]); 188 - for (i = 0; i < SYNC_URBS; i++) 189 - release_urb_ctx(&subs->syncurb[i]); 190 - usb_free_coherent(subs->dev, SYNC_URBS * 4, 191 - subs->syncbuf, subs->sync_dma); 192 - subs->syncbuf = NULL; 193 - subs->nurbs = 0; 194 - } 195 - 196 - /* 197 - * complete callback from data urb 198 - */ 199 - static void snd_complete_urb(struct urb *urb) 200 - { 201 - struct snd_urb_ctx *ctx = urb->context; 202 - struct snd_usb_substream *subs = ctx->subs; 203 - struct snd_pcm_substream *substream = ctx->subs->pcm_substream; 204 - int err = 0; 205 - 206 - if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) || 207 - !subs->running || /* can be stopped during retire callback */ 208 - (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 || 209 - (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 210 - clear_bit(ctx->index, &subs->active_mask); 211 - if (err < 0) { 212 - snd_printd(KERN_ERR "cannot submit urb (err = %d)\n", err); 213 - snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); 214 - } 215 - } 216 - } 217 - 218 - 219 - /* 220 - * complete callback from sync urb 221 - */ 222 - static void snd_complete_sync_urb(struct urb *urb) 223 - { 224 - struct snd_urb_ctx *ctx = urb->context; 225 - struct snd_usb_substream *subs = ctx->subs; 226 - struct snd_pcm_substream *substream = ctx->subs->pcm_substream; 227 - int err = 0; 228 - 229 - if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) || 230 - !subs->running || /* can be stopped during retire callback */ 231 - (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 || 232 - (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 233 - clear_bit(ctx->index + 16, &subs->active_mask); 234 - if (err < 0) { 235 - snd_printd(KERN_ERR "cannot submit sync urb (err = %d)\n", err); 236 - snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); 237 - } 238 - } 239 - } 240 - 241 - 242 - /* 243 - * initialize a substream for plaback/capture 244 - */ 245 - int snd_usb_init_substream_urbs(struct snd_usb_substream *subs, 246 - unsigned int period_bytes, 247 - unsigned int rate, 248 - unsigned int frame_bits) 249 - { 250 - unsigned int maxsize, i; 251 - int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK; 252 - unsigned int urb_packs, total_packs, packs_per_ms; 253 - struct snd_usb_audio *chip = subs->stream->chip; 254 - 255 - /* calculate the frequency in 16.16 format */ 256 - if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) 257 - subs->freqn = get_usb_full_speed_rate(rate); 258 - else 259 - subs->freqn = get_usb_high_speed_rate(rate); 260 - subs->freqm = subs->freqn; 261 - subs->freqshift = INT_MIN; 262 - /* calculate max. frequency */ 263 - if (subs->maxpacksize) { 264 - /* whatever fits into a max. size packet */ 265 - maxsize = subs->maxpacksize; 266 - subs->freqmax = (maxsize / (frame_bits >> 3)) 267 - << (16 - subs->datainterval); 268 - } else { 269 - /* no max. packet size: just take 25% higher than nominal */ 270 - subs->freqmax = subs->freqn + (subs->freqn >> 2); 271 - maxsize = ((subs->freqmax + 0xffff) * (frame_bits >> 3)) 272 - >> (16 - subs->datainterval); 273 - } 274 - subs->phase = 0; 275 - 276 - if (subs->fill_max) 277 - subs->curpacksize = subs->maxpacksize; 278 - else 279 - subs->curpacksize = maxsize; 280 - 281 - if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL) 282 - packs_per_ms = 8 >> subs->datainterval; 283 - else 284 - packs_per_ms = 1; 285 - 286 - if (is_playback) { 287 - urb_packs = max(chip->nrpacks, 1); 288 - urb_packs = min(urb_packs, (unsigned int)MAX_PACKS); 289 - } else 290 - urb_packs = 1; 291 - urb_packs *= packs_per_ms; 292 - if (subs->syncpipe) 293 - urb_packs = min(urb_packs, 1U << subs->syncinterval); 294 - 295 - /* decide how many packets to be used */ 296 - if (is_playback) { 297 - unsigned int minsize, maxpacks; 298 - /* determine how small a packet can be */ 299 - minsize = (subs->freqn >> (16 - subs->datainterval)) 300 - * (frame_bits >> 3); 301 - /* with sync from device, assume it can be 12% lower */ 302 - if (subs->syncpipe) 303 - minsize -= minsize >> 3; 304 - minsize = max(minsize, 1u); 305 - total_packs = (period_bytes + minsize - 1) / minsize; 306 - /* we need at least two URBs for queueing */ 307 - if (total_packs < 2) { 308 - total_packs = 2; 309 - } else { 310 - /* and we don't want too long a queue either */ 311 - maxpacks = max(MAX_QUEUE * packs_per_ms, urb_packs * 2); 312 - total_packs = min(total_packs, maxpacks); 313 - } 314 - } else { 315 - while (urb_packs > 1 && urb_packs * maxsize >= period_bytes) 316 - urb_packs >>= 1; 317 - total_packs = MAX_URBS * urb_packs; 318 - } 319 - subs->nurbs = (total_packs + urb_packs - 1) / urb_packs; 320 - if (subs->nurbs > MAX_URBS) { 321 - /* too much... */ 322 - subs->nurbs = MAX_URBS; 323 - total_packs = MAX_URBS * urb_packs; 324 - } else if (subs->nurbs < 2) { 325 - /* too little - we need at least two packets 326 - * to ensure contiguous playback/capture 327 - */ 328 - subs->nurbs = 2; 329 - } 330 - 331 - /* allocate and initialize data urbs */ 332 - for (i = 0; i < subs->nurbs; i++) { 333 - struct snd_urb_ctx *u = &subs->dataurb[i]; 334 - u->index = i; 335 - u->subs = subs; 336 - u->packets = (i + 1) * total_packs / subs->nurbs 337 - - i * total_packs / subs->nurbs; 338 - u->buffer_size = maxsize * u->packets; 339 - if (subs->fmt_type == UAC_FORMAT_TYPE_II) 340 - u->packets++; /* for transfer delimiter */ 341 - u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); 342 - if (!u->urb) 343 - goto out_of_memory; 344 - u->urb->transfer_buffer = 345 - usb_alloc_coherent(subs->dev, u->buffer_size, 346 - GFP_KERNEL, &u->urb->transfer_dma); 347 - if (!u->urb->transfer_buffer) 348 - goto out_of_memory; 349 - u->urb->pipe = subs->datapipe; 350 - u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 351 - u->urb->interval = 1 << subs->datainterval; 352 - u->urb->context = u; 353 - u->urb->complete = snd_complete_urb; 354 - } 355 - 356 - if (subs->syncpipe) { 357 - /* allocate and initialize sync urbs */ 358 - subs->syncbuf = usb_alloc_coherent(subs->dev, SYNC_URBS * 4, 359 - GFP_KERNEL, &subs->sync_dma); 360 - if (!subs->syncbuf) 361 - goto out_of_memory; 362 - for (i = 0; i < SYNC_URBS; i++) { 363 - struct snd_urb_ctx *u = &subs->syncurb[i]; 364 - u->index = i; 365 - u->subs = subs; 366 - u->packets = 1; 367 - u->urb = usb_alloc_urb(1, GFP_KERNEL); 368 - if (!u->urb) 369 - goto out_of_memory; 370 - u->urb->transfer_buffer = subs->syncbuf + i * 4; 371 - u->urb->transfer_dma = subs->sync_dma + i * 4; 372 - u->urb->transfer_buffer_length = 4; 373 - u->urb->pipe = subs->syncpipe; 374 - u->urb->transfer_flags = URB_ISO_ASAP | 375 - URB_NO_TRANSFER_DMA_MAP; 376 - u->urb->number_of_packets = 1; 377 - u->urb->interval = 1 << subs->syncinterval; 378 - u->urb->context = u; 379 - u->urb->complete = snd_complete_sync_urb; 380 - } 381 - } 382 - return 0; 383 - 384 - out_of_memory: 385 - snd_usb_release_substream_urbs(subs, 0); 386 - return -ENOMEM; 387 - } 388 - 389 - /* 390 - * prepare urb for full speed capture sync pipe 391 - * 392 - * fill the length and offset of each urb descriptor. 393 - * the fixed 10.14 frequency is passed through the pipe. 394 - */ 395 - static int prepare_capture_sync_urb(struct snd_usb_substream *subs, 396 - struct snd_pcm_runtime *runtime, 397 - struct urb *urb) 398 - { 399 - unsigned char *cp = urb->transfer_buffer; 400 - struct snd_urb_ctx *ctx = urb->context; 401 - 402 - urb->dev = ctx->subs->dev; /* we need to set this at each time */ 403 - urb->iso_frame_desc[0].length = 3; 404 - urb->iso_frame_desc[0].offset = 0; 405 - cp[0] = subs->freqn >> 2; 406 - cp[1] = subs->freqn >> 10; 407 - cp[2] = subs->freqn >> 18; 408 - return 0; 409 - } 410 - 411 - /* 412 - * prepare urb for high speed capture sync pipe 413 - * 414 - * fill the length and offset of each urb descriptor. 415 - * the fixed 12.13 frequency is passed as 16.16 through the pipe. 416 - */ 417 - static int prepare_capture_sync_urb_hs(struct snd_usb_substream *subs, 418 - struct snd_pcm_runtime *runtime, 419 - struct urb *urb) 420 - { 421 - unsigned char *cp = urb->transfer_buffer; 422 - struct snd_urb_ctx *ctx = urb->context; 423 - 424 - urb->dev = ctx->subs->dev; /* we need to set this at each time */ 425 - urb->iso_frame_desc[0].length = 4; 426 - urb->iso_frame_desc[0].offset = 0; 427 - cp[0] = subs->freqn; 428 - cp[1] = subs->freqn >> 8; 429 - cp[2] = subs->freqn >> 16; 430 - cp[3] = subs->freqn >> 24; 431 - return 0; 432 - } 433 - 434 - /* 435 - * process after capture sync complete 436 - * - nothing to do 437 - */ 438 - static int retire_capture_sync_urb(struct snd_usb_substream *subs, 439 - struct snd_pcm_runtime *runtime, 440 - struct urb *urb) 441 - { 442 - return 0; 443 - } 444 - 445 - /* 446 - * prepare urb for capture data pipe 447 - * 448 - * fill the offset and length of each descriptor. 449 - * 450 - * we use a temporary buffer to write the captured data. 451 - * since the length of written data is determined by host, we cannot 452 - * write onto the pcm buffer directly... the data is thus copied 453 - * later at complete callback to the global buffer. 454 - */ 455 - static int prepare_capture_urb(struct snd_usb_substream *subs, 456 - struct snd_pcm_runtime *runtime, 457 - struct urb *urb) 458 - { 459 - int i, offs; 460 - struct snd_urb_ctx *ctx = urb->context; 461 - 462 - offs = 0; 463 - urb->dev = ctx->subs->dev; /* we need to set this at each time */ 464 - for (i = 0; i < ctx->packets; i++) { 465 - urb->iso_frame_desc[i].offset = offs; 466 - urb->iso_frame_desc[i].length = subs->curpacksize; 467 - offs += subs->curpacksize; 468 - } 469 - urb->transfer_buffer_length = offs; 470 - urb->number_of_packets = ctx->packets; 471 - return 0; 472 - } 473 - 474 - /* 475 - * process after capture complete 476 - * 477 - * copy the data from each desctiptor to the pcm buffer, and 478 - * update the current position. 479 - */ 480 - static int retire_capture_urb(struct snd_usb_substream *subs, 481 - struct snd_pcm_runtime *runtime, 482 - struct urb *urb) 483 - { 484 - unsigned long flags; 485 - unsigned char *cp; 486 - int i; 487 - unsigned int stride, frames, bytes, oldptr; 488 - int period_elapsed = 0; 489 - 490 - stride = runtime->frame_bits >> 3; 491 - 492 - for (i = 0; i < urb->number_of_packets; i++) { 493 - cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset; 494 - if (urb->iso_frame_desc[i].status && printk_ratelimit()) { 495 - snd_printdd("frame %d active: %d\n", i, urb->iso_frame_desc[i].status); 496 - // continue; 497 - } 498 - bytes = urb->iso_frame_desc[i].actual_length; 499 - frames = bytes / stride; 500 - if (!subs->txfr_quirk) 501 - bytes = frames * stride; 502 - if (bytes % (runtime->sample_bits >> 3) != 0) { 503 - #ifdef CONFIG_SND_DEBUG_VERBOSE 504 - int oldbytes = bytes; 505 - #endif 506 - bytes = frames * stride; 507 - snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n", 508 - oldbytes, bytes); 509 - } 510 - /* update the current pointer */ 511 - spin_lock_irqsave(&subs->lock, flags); 512 - oldptr = subs->hwptr_done; 513 - subs->hwptr_done += bytes; 514 - if (subs->hwptr_done >= runtime->buffer_size * stride) 515 - subs->hwptr_done -= runtime->buffer_size * stride; 516 - frames = (bytes + (oldptr % stride)) / stride; 517 - subs->transfer_done += frames; 518 - if (subs->transfer_done >= runtime->period_size) { 519 - subs->transfer_done -= runtime->period_size; 520 - period_elapsed = 1; 521 - } 522 - spin_unlock_irqrestore(&subs->lock, flags); 523 - /* copy a data chunk */ 524 - if (oldptr + bytes > runtime->buffer_size * stride) { 525 - unsigned int bytes1 = 526 - runtime->buffer_size * stride - oldptr; 527 - memcpy(runtime->dma_area + oldptr, cp, bytes1); 528 - memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1); 529 - } else { 530 - memcpy(runtime->dma_area + oldptr, cp, bytes); 531 - } 532 - } 533 - if (period_elapsed) 534 - snd_pcm_period_elapsed(subs->pcm_substream); 535 - return 0; 536 - } 537 - 538 - /* 539 - * Process after capture complete when paused. Nothing to do. 540 - */ 541 - static int retire_paused_capture_urb(struct snd_usb_substream *subs, 542 - struct snd_pcm_runtime *runtime, 543 - struct urb *urb) 544 - { 545 - return 0; 546 - } 547 - 548 - 549 - /* 550 - * prepare urb for playback sync pipe 551 - * 552 - * set up the offset and length to receive the current frequency. 553 - */ 554 - static int prepare_playback_sync_urb(struct snd_usb_substream *subs, 555 - struct snd_pcm_runtime *runtime, 556 - struct urb *urb) 557 - { 558 - struct snd_urb_ctx *ctx = urb->context; 559 - 560 - urb->dev = ctx->subs->dev; /* we need to set this at each time */ 561 - urb->iso_frame_desc[0].length = min(4u, ctx->subs->syncmaxsize); 562 - urb->iso_frame_desc[0].offset = 0; 563 - return 0; 564 - } 565 - 566 - /* 567 - * process after playback sync complete 568 - * 569 - * Full speed devices report feedback values in 10.14 format as samples per 570 - * frame, high speed devices in 16.16 format as samples per microframe. 571 - * Because the Audio Class 1 spec was written before USB 2.0, many high speed 572 - * devices use a wrong interpretation, some others use an entirely different 573 - * format. Therefore, we cannot predict what format any particular device uses 574 - * and must detect it automatically. 575 - */ 576 - static int retire_playback_sync_urb(struct snd_usb_substream *subs, 577 - struct snd_pcm_runtime *runtime, 578 - struct urb *urb) 579 - { 580 - unsigned int f; 581 - int shift; 582 - unsigned long flags; 583 - 584 - if (urb->iso_frame_desc[0].status != 0 || 585 - urb->iso_frame_desc[0].actual_length < 3) 586 - return 0; 587 - 588 - f = le32_to_cpup(urb->transfer_buffer); 589 - if (urb->iso_frame_desc[0].actual_length == 3) 590 - f &= 0x00ffffff; 591 - else 592 - f &= 0x0fffffff; 593 - if (f == 0) 594 - return 0; 595 - 596 - if (unlikely(subs->freqshift == INT_MIN)) { 597 - /* 598 - * The first time we see a feedback value, determine its format 599 - * by shifting it left or right until it matches the nominal 600 - * frequency value. This assumes that the feedback does not 601 - * differ from the nominal value more than +50% or -25%. 602 - */ 603 - shift = 0; 604 - while (f < subs->freqn - subs->freqn / 4) { 605 - f <<= 1; 606 - shift++; 607 - } 608 - while (f > subs->freqn + subs->freqn / 2) { 609 - f >>= 1; 610 - shift--; 611 - } 612 - subs->freqshift = shift; 613 - } 614 - else if (subs->freqshift >= 0) 615 - f <<= subs->freqshift; 616 - else 617 - f >>= -subs->freqshift; 618 - 619 - if (likely(f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax)) { 620 - /* 621 - * If the frequency looks valid, set it. 622 - * This value is referred to in prepare_playback_urb(). 623 - */ 624 - spin_lock_irqsave(&subs->lock, flags); 625 - subs->freqm = f; 626 - spin_unlock_irqrestore(&subs->lock, flags); 627 - } else { 628 - /* 629 - * Out of range; maybe the shift value is wrong. 630 - * Reset it so that we autodetect again the next time. 631 - */ 632 - subs->freqshift = INT_MIN; 633 - } 634 - 635 - return 0; 636 - } 637 - 638 - /* determine the number of frames in the next packet */ 639 - static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs) 640 - { 641 - if (subs->fill_max) 642 - return subs->maxframesize; 643 - else { 644 - subs->phase = (subs->phase & 0xffff) 645 - + (subs->freqm << subs->datainterval); 646 - return min(subs->phase >> 16, subs->maxframesize); 647 - } 648 - } 649 - 650 - /* 651 - * Prepare urb for streaming before playback starts or when paused. 652 - * 653 - * We don't have any data, so we send silence. 654 - */ 655 - static int prepare_nodata_playback_urb(struct snd_usb_substream *subs, 656 - struct snd_pcm_runtime *runtime, 657 - struct urb *urb) 658 - { 659 - unsigned int i, offs, counts; 660 - struct snd_urb_ctx *ctx = urb->context; 661 - int stride = runtime->frame_bits >> 3; 662 - 663 - offs = 0; 664 - urb->dev = ctx->subs->dev; 665 - for (i = 0; i < ctx->packets; ++i) { 666 - counts = snd_usb_audio_next_packet_size(subs); 667 - urb->iso_frame_desc[i].offset = offs * stride; 668 - urb->iso_frame_desc[i].length = counts * stride; 669 - offs += counts; 670 - } 671 - urb->number_of_packets = ctx->packets; 672 - urb->transfer_buffer_length = offs * stride; 673 - memset(urb->transfer_buffer, 674 - runtime->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0, 675 - offs * stride); 676 - return 0; 677 - } 678 - 679 - /* 680 - * prepare urb for playback data pipe 681 - * 682 - * Since a URB can handle only a single linear buffer, we must use double 683 - * buffering when the data to be transferred overflows the buffer boundary. 684 - * To avoid inconsistencies when updating hwptr_done, we use double buffering 685 - * for all URBs. 686 - */ 687 - static int prepare_playback_urb(struct snd_usb_substream *subs, 688 - struct snd_pcm_runtime *runtime, 689 - struct urb *urb) 690 - { 691 - int i, stride; 692 - unsigned int counts, frames, bytes; 693 - unsigned long flags; 694 - int period_elapsed = 0; 695 - struct snd_urb_ctx *ctx = urb->context; 696 - 697 - stride = runtime->frame_bits >> 3; 698 - 699 - frames = 0; 700 - urb->dev = ctx->subs->dev; /* we need to set this at each time */ 701 - urb->number_of_packets = 0; 702 - spin_lock_irqsave(&subs->lock, flags); 703 - for (i = 0; i < ctx->packets; i++) { 704 - counts = snd_usb_audio_next_packet_size(subs); 705 - /* set up descriptor */ 706 - urb->iso_frame_desc[i].offset = frames * stride; 707 - urb->iso_frame_desc[i].length = counts * stride; 708 - frames += counts; 709 - urb->number_of_packets++; 710 - subs->transfer_done += counts; 711 - if (subs->transfer_done >= runtime->period_size) { 712 - subs->transfer_done -= runtime->period_size; 713 - period_elapsed = 1; 714 - if (subs->fmt_type == UAC_FORMAT_TYPE_II) { 715 - if (subs->transfer_done > 0) { 716 - /* FIXME: fill-max mode is not 717 - * supported yet */ 718 - frames -= subs->transfer_done; 719 - counts -= subs->transfer_done; 720 - urb->iso_frame_desc[i].length = 721 - counts * stride; 722 - subs->transfer_done = 0; 723 - } 724 - i++; 725 - if (i < ctx->packets) { 726 - /* add a transfer delimiter */ 727 - urb->iso_frame_desc[i].offset = 728 - frames * stride; 729 - urb->iso_frame_desc[i].length = 0; 730 - urb->number_of_packets++; 731 - } 732 - break; 733 - } 734 - } 735 - if (period_elapsed) /* finish at the period boundary */ 736 - break; 737 - } 738 - bytes = frames * stride; 739 - if (subs->hwptr_done + bytes > runtime->buffer_size * stride) { 740 - /* err, the transferred area goes over buffer boundary. */ 741 - unsigned int bytes1 = 742 - runtime->buffer_size * stride - subs->hwptr_done; 743 - memcpy(urb->transfer_buffer, 744 - runtime->dma_area + subs->hwptr_done, bytes1); 745 - memcpy(urb->transfer_buffer + bytes1, 746 - runtime->dma_area, bytes - bytes1); 747 - } else { 748 - memcpy(urb->transfer_buffer, 749 - runtime->dma_area + subs->hwptr_done, bytes); 750 - } 751 - subs->hwptr_done += bytes; 752 - if (subs->hwptr_done >= runtime->buffer_size * stride) 753 - subs->hwptr_done -= runtime->buffer_size * stride; 754 - 755 - /* update delay with exact number of samples queued */ 756 - runtime->delay = subs->last_delay; 757 - runtime->delay += frames; 758 - subs->last_delay = runtime->delay; 759 - 760 - /* realign last_frame_number */ 761 - subs->last_frame_number = usb_get_current_frame_number(subs->dev); 762 - subs->last_frame_number &= 0xFF; /* keep 8 LSBs */ 763 - 764 - spin_unlock_irqrestore(&subs->lock, flags); 765 - urb->transfer_buffer_length = bytes; 766 - if (period_elapsed) 767 - snd_pcm_period_elapsed(subs->pcm_substream); 768 - return 0; 769 - } 770 - 771 - /* 772 - * process after playback data complete 773 - * - decrease the delay count again 774 - */ 775 - static int retire_playback_urb(struct snd_usb_substream *subs, 776 - struct snd_pcm_runtime *runtime, 777 - struct urb *urb) 778 - { 779 - unsigned long flags; 780 - int stride = runtime->frame_bits >> 3; 781 - int processed = urb->transfer_buffer_length / stride; 782 - int est_delay; 783 - 784 - spin_lock_irqsave(&subs->lock, flags); 785 - 786 - est_delay = snd_usb_pcm_delay(subs, runtime->rate); 787 - /* update delay with exact number of samples played */ 788 - if (processed > subs->last_delay) 789 - subs->last_delay = 0; 790 - else 791 - subs->last_delay -= processed; 792 - runtime->delay = subs->last_delay; 793 - 794 - /* 795 - * Report when delay estimate is off by more than 2ms. 796 - * The error should be lower than 2ms since the estimate relies 797 - * on two reads of a counter updated every ms. 798 - */ 799 - if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2) 800 - snd_printk(KERN_DEBUG "delay: estimated %d, actual %d\n", 801 - est_delay, subs->last_delay); 802 - 803 - spin_unlock_irqrestore(&subs->lock, flags); 804 - return 0; 56 + if (u->buffer_size) 57 + usb_free_coherent(u->ep->chip->dev, u->buffer_size, 58 + u->urb->transfer_buffer, 59 + u->urb->transfer_dma); 60 + usb_free_urb(u->urb); 61 + u->urb = NULL; 805 62 } 806 63 807 64 static const char *usb_error_string(int err) ··· 118 797 } 119 798 } 120 799 121 - /* 122 - * set up and start data/sync urbs 800 + /** 801 + * snd_usb_endpoint_implicit_feedback_sink: Report endpoint usage type 802 + * 803 + * @ep: The snd_usb_endpoint 804 + * 805 + * Determine whether an endpoint is driven by an implicit feedback 806 + * data endpoint source. 123 807 */ 124 - static int start_urbs(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime) 808 + int snd_usb_endpoint_implict_feedback_sink(struct snd_usb_endpoint *ep) 125 809 { 126 - unsigned int i; 810 + return ep->sync_master && 811 + ep->sync_master->type == SND_USB_ENDPOINT_TYPE_DATA && 812 + ep->type == SND_USB_ENDPOINT_TYPE_DATA && 813 + usb_pipeout(ep->pipe); 814 + } 815 + 816 + /* 817 + * For streaming based on information derived from sync endpoints, 818 + * prepare_outbound_urb_sizes() will call next_packet_size() to 819 + * determine the number of samples to be sent in the next packet. 820 + * 821 + * For implicit feedback, next_packet_size() is unused. 822 + */ 823 + static int next_packet_size(struct snd_usb_endpoint *ep) 824 + { 825 + unsigned long flags; 826 + int ret; 827 + 828 + if (ep->fill_max) 829 + return ep->maxframesize; 830 + 831 + spin_lock_irqsave(&ep->lock, flags); 832 + ep->phase = (ep->phase & 0xffff) 833 + + (ep->freqm << ep->datainterval); 834 + ret = min(ep->phase >> 16, ep->maxframesize); 835 + spin_unlock_irqrestore(&ep->lock, flags); 836 + 837 + return ret; 838 + } 839 + 840 + static void retire_outbound_urb(struct snd_usb_endpoint *ep, 841 + struct snd_urb_ctx *urb_ctx) 842 + { 843 + if (ep->retire_data_urb) 844 + ep->retire_data_urb(ep->data_subs, urb_ctx->urb); 845 + } 846 + 847 + static void retire_inbound_urb(struct snd_usb_endpoint *ep, 848 + struct snd_urb_ctx *urb_ctx) 849 + { 850 + struct urb *urb = urb_ctx->urb; 851 + 852 + if (ep->sync_slave) 853 + snd_usb_handle_sync_urb(ep->sync_slave, ep, urb); 854 + 855 + if (ep->retire_data_urb) 856 + ep->retire_data_urb(ep->data_subs, urb); 857 + } 858 + 859 + static void prepare_outbound_urb_sizes(struct snd_usb_endpoint *ep, 860 + struct snd_urb_ctx *ctx) 861 + { 862 + int i; 863 + 864 + for (i = 0; i < ctx->packets; ++i) 865 + ctx->packet_size[i] = next_packet_size(ep); 866 + } 867 + 868 + /* 869 + * Prepare a PLAYBACK urb for submission to the bus. 870 + */ 871 + static void prepare_outbound_urb(struct snd_usb_endpoint *ep, 872 + struct snd_urb_ctx *ctx) 873 + { 874 + int i; 875 + struct urb *urb = ctx->urb; 876 + unsigned char *cp = urb->transfer_buffer; 877 + 878 + urb->dev = ep->chip->dev; /* we need to set this at each time */ 879 + 880 + switch (ep->type) { 881 + case SND_USB_ENDPOINT_TYPE_DATA: 882 + if (ep->prepare_data_urb) { 883 + ep->prepare_data_urb(ep->data_subs, urb); 884 + } else { 885 + /* no data provider, so send silence */ 886 + unsigned int offs = 0; 887 + for (i = 0; i < ctx->packets; ++i) { 888 + int counts = ctx->packet_size[i]; 889 + urb->iso_frame_desc[i].offset = offs * ep->stride; 890 + urb->iso_frame_desc[i].length = counts * ep->stride; 891 + offs += counts; 892 + } 893 + 894 + urb->number_of_packets = ctx->packets; 895 + urb->transfer_buffer_length = offs * ep->stride; 896 + memset(urb->transfer_buffer, ep->silence_value, 897 + offs * ep->stride); 898 + } 899 + break; 900 + 901 + case SND_USB_ENDPOINT_TYPE_SYNC: 902 + if (snd_usb_get_speed(ep->chip->dev) >= USB_SPEED_HIGH) { 903 + /* 904 + * fill the length and offset of each urb descriptor. 905 + * the fixed 12.13 frequency is passed as 16.16 through the pipe. 906 + */ 907 + urb->iso_frame_desc[0].length = 4; 908 + urb->iso_frame_desc[0].offset = 0; 909 + cp[0] = ep->freqn; 910 + cp[1] = ep->freqn >> 8; 911 + cp[2] = ep->freqn >> 16; 912 + cp[3] = ep->freqn >> 24; 913 + } else { 914 + /* 915 + * fill the length and offset of each urb descriptor. 916 + * the fixed 10.14 frequency is passed through the pipe. 917 + */ 918 + urb->iso_frame_desc[0].length = 3; 919 + urb->iso_frame_desc[0].offset = 0; 920 + cp[0] = ep->freqn >> 2; 921 + cp[1] = ep->freqn >> 10; 922 + cp[2] = ep->freqn >> 18; 923 + } 924 + 925 + break; 926 + } 927 + } 928 + 929 + /* 930 + * Prepare a CAPTURE or SYNC urb for submission to the bus. 931 + */ 932 + static inline void prepare_inbound_urb(struct snd_usb_endpoint *ep, 933 + struct snd_urb_ctx *urb_ctx) 934 + { 935 + int i, offs; 936 + struct urb *urb = urb_ctx->urb; 937 + 938 + urb->dev = ep->chip->dev; /* we need to set this at each time */ 939 + 940 + switch (ep->type) { 941 + case SND_USB_ENDPOINT_TYPE_DATA: 942 + offs = 0; 943 + for (i = 0; i < urb_ctx->packets; i++) { 944 + urb->iso_frame_desc[i].offset = offs; 945 + urb->iso_frame_desc[i].length = ep->curpacksize; 946 + offs += ep->curpacksize; 947 + } 948 + 949 + urb->transfer_buffer_length = offs; 950 + urb->number_of_packets = urb_ctx->packets; 951 + break; 952 + 953 + case SND_USB_ENDPOINT_TYPE_SYNC: 954 + urb->iso_frame_desc[0].length = min(4u, ep->syncmaxsize); 955 + urb->iso_frame_desc[0].offset = 0; 956 + break; 957 + } 958 + } 959 + 960 + /* 961 + * Send output urbs that have been prepared previously. URBs are dequeued 962 + * from ep->ready_playback_urbs and in case there there aren't any available 963 + * or there are no packets that have been prepared, this function does 964 + * nothing. 965 + * 966 + * The reason why the functionality of sending and preparing URBs is separated 967 + * is that host controllers don't guarantee the order in which they return 968 + * inbound and outbound packets to their submitters. 969 + * 970 + * This function is only used for implicit feedback endpoints. For endpoints 971 + * driven by dedicated sync endpoints, URBs are immediately re-submitted 972 + * from their completion handler. 973 + */ 974 + static void queue_pending_output_urbs(struct snd_usb_endpoint *ep) 975 + { 976 + while (test_bit(EP_FLAG_RUNNING, &ep->flags)) { 977 + 978 + unsigned long flags; 979 + struct snd_usb_packet_info *uninitialized_var(packet); 980 + struct snd_urb_ctx *ctx = NULL; 981 + struct urb *urb; 982 + int err, i; 983 + 984 + spin_lock_irqsave(&ep->lock, flags); 985 + if (ep->next_packet_read_pos != ep->next_packet_write_pos) { 986 + packet = ep->next_packet + ep->next_packet_read_pos; 987 + ep->next_packet_read_pos++; 988 + ep->next_packet_read_pos %= MAX_URBS; 989 + 990 + /* take URB out of FIFO */ 991 + if (!list_empty(&ep->ready_playback_urbs)) 992 + ctx = list_first_entry(&ep->ready_playback_urbs, 993 + struct snd_urb_ctx, ready_list); 994 + } 995 + spin_unlock_irqrestore(&ep->lock, flags); 996 + 997 + if (ctx == NULL) 998 + return; 999 + 1000 + list_del_init(&ctx->ready_list); 1001 + urb = ctx->urb; 1002 + 1003 + /* copy over the length information */ 1004 + for (i = 0; i < packet->packets; i++) 1005 + ctx->packet_size[i] = packet->packet_size[i]; 1006 + 1007 + /* call the data handler to fill in playback data */ 1008 + prepare_outbound_urb(ep, ctx); 1009 + 1010 + err = usb_submit_urb(ctx->urb, GFP_ATOMIC); 1011 + if (err < 0) 1012 + snd_printk(KERN_ERR "Unable to submit urb #%d: %d (urb %p)\n", 1013 + ctx->index, err, ctx->urb); 1014 + else 1015 + set_bit(ctx->index, &ep->active_mask); 1016 + } 1017 + } 1018 + 1019 + /* 1020 + * complete callback for urbs 1021 + */ 1022 + static void snd_complete_urb(struct urb *urb) 1023 + { 1024 + struct snd_urb_ctx *ctx = urb->context; 1025 + struct snd_usb_endpoint *ep = ctx->ep; 127 1026 int err; 128 1027 129 - if (subs->stream->chip->shutdown) 130 - return -EBADFD; 1028 + if (unlikely(urb->status == -ENOENT || /* unlinked */ 1029 + urb->status == -ENODEV || /* device removed */ 1030 + urb->status == -ECONNRESET || /* unlinked */ 1031 + urb->status == -ESHUTDOWN || /* device disabled */ 1032 + ep->chip->shutdown)) /* device disconnected */ 1033 + goto exit_clear; 131 1034 132 - for (i = 0; i < subs->nurbs; i++) { 133 - if (snd_BUG_ON(!subs->dataurb[i].urb)) 134 - return -EINVAL; 135 - if (subs->ops.prepare(subs, runtime, subs->dataurb[i].urb) < 0) { 136 - snd_printk(KERN_ERR "cannot prepare datapipe for urb %d\n", i); 137 - goto __error; 1035 + if (usb_pipeout(ep->pipe)) { 1036 + retire_outbound_urb(ep, ctx); 1037 + /* can be stopped during retire callback */ 1038 + if (unlikely(!test_bit(EP_FLAG_RUNNING, &ep->flags))) 1039 + goto exit_clear; 1040 + 1041 + if (snd_usb_endpoint_implict_feedback_sink(ep)) { 1042 + unsigned long flags; 1043 + 1044 + spin_lock_irqsave(&ep->lock, flags); 1045 + list_add_tail(&ctx->ready_list, &ep->ready_playback_urbs); 1046 + spin_unlock_irqrestore(&ep->lock, flags); 1047 + queue_pending_output_urbs(ep); 1048 + 1049 + goto exit_clear; 1050 + } 1051 + 1052 + prepare_outbound_urb_sizes(ep, ctx); 1053 + prepare_outbound_urb(ep, ctx); 1054 + } else { 1055 + retire_inbound_urb(ep, ctx); 1056 + /* can be stopped during retire callback */ 1057 + if (unlikely(!test_bit(EP_FLAG_RUNNING, &ep->flags))) 1058 + goto exit_clear; 1059 + 1060 + prepare_inbound_urb(ep, ctx); 1061 + } 1062 + 1063 + err = usb_submit_urb(urb, GFP_ATOMIC); 1064 + if (err == 0) 1065 + return; 1066 + 1067 + snd_printk(KERN_ERR "cannot submit urb (err = %d)\n", err); 1068 + //snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); 1069 + 1070 + exit_clear: 1071 + clear_bit(ctx->index, &ep->active_mask); 1072 + } 1073 + 1074 + /** 1075 + * snd_usb_add_endpoint: Add an endpoint to an USB audio chip 1076 + * 1077 + * @chip: The chip 1078 + * @alts: The USB host interface 1079 + * @ep_num: The number of the endpoint to use 1080 + * @direction: SNDRV_PCM_STREAM_PLAYBACK or SNDRV_PCM_STREAM_CAPTURE 1081 + * @type: SND_USB_ENDPOINT_TYPE_DATA or SND_USB_ENDPOINT_TYPE_SYNC 1082 + * 1083 + * If the requested endpoint has not been added to the given chip before, 1084 + * a new instance is created. Otherwise, a pointer to the previoulsy 1085 + * created instance is returned. In case of any error, NULL is returned. 1086 + * 1087 + * New endpoints will be added to chip->ep_list and must be freed by 1088 + * calling snd_usb_endpoint_free(). 1089 + */ 1090 + struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip, 1091 + struct usb_host_interface *alts, 1092 + int ep_num, int direction, int type) 1093 + { 1094 + struct list_head *p; 1095 + struct snd_usb_endpoint *ep; 1096 + int ret, is_playback = direction == SNDRV_PCM_STREAM_PLAYBACK; 1097 + 1098 + mutex_lock(&chip->mutex); 1099 + 1100 + list_for_each(p, &chip->ep_list) { 1101 + ep = list_entry(p, struct snd_usb_endpoint, list); 1102 + if (ep->ep_num == ep_num && 1103 + ep->iface == alts->desc.bInterfaceNumber && 1104 + ep->alt_idx == alts->desc.bAlternateSetting) { 1105 + snd_printdd(KERN_DEBUG "Re-using EP %x in iface %d,%d @%p\n", 1106 + ep_num, ep->iface, ep->alt_idx, ep); 1107 + goto __exit_unlock; 138 1108 } 139 1109 } 140 - if (subs->syncpipe) { 141 - for (i = 0; i < SYNC_URBS; i++) { 142 - if (snd_BUG_ON(!subs->syncurb[i].urb)) 143 - return -EINVAL; 144 - if (subs->ops.prepare_sync(subs, runtime, subs->syncurb[i].urb) < 0) { 145 - snd_printk(KERN_ERR "cannot prepare syncpipe for urb %d\n", i); 146 - goto __error; 1110 + 1111 + snd_printdd(KERN_DEBUG "Creating new %s %s endpoint #%x\n", 1112 + is_playback ? "playback" : "capture", 1113 + type == SND_USB_ENDPOINT_TYPE_DATA ? "data" : "sync", 1114 + ep_num); 1115 + 1116 + /* select the alt setting once so the endpoints become valid */ 1117 + ret = usb_set_interface(chip->dev, alts->desc.bInterfaceNumber, 1118 + alts->desc.bAlternateSetting); 1119 + if (ret < 0) { 1120 + snd_printk(KERN_ERR "%s(): usb_set_interface() failed, ret = %d\n", 1121 + __func__, ret); 1122 + ep = NULL; 1123 + goto __exit_unlock; 1124 + } 1125 + 1126 + ep = kzalloc(sizeof(*ep), GFP_KERNEL); 1127 + if (!ep) 1128 + goto __exit_unlock; 1129 + 1130 + ep->chip = chip; 1131 + spin_lock_init(&ep->lock); 1132 + ep->type = type; 1133 + ep->ep_num = ep_num; 1134 + ep->iface = alts->desc.bInterfaceNumber; 1135 + ep->alt_idx = alts->desc.bAlternateSetting; 1136 + INIT_LIST_HEAD(&ep->ready_playback_urbs); 1137 + ep_num &= USB_ENDPOINT_NUMBER_MASK; 1138 + 1139 + if (is_playback) 1140 + ep->pipe = usb_sndisocpipe(chip->dev, ep_num); 1141 + else 1142 + ep->pipe = usb_rcvisocpipe(chip->dev, ep_num); 1143 + 1144 + if (type == SND_USB_ENDPOINT_TYPE_SYNC) { 1145 + if (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && 1146 + get_endpoint(alts, 1)->bRefresh >= 1 && 1147 + get_endpoint(alts, 1)->bRefresh <= 9) 1148 + ep->syncinterval = get_endpoint(alts, 1)->bRefresh; 1149 + else if (snd_usb_get_speed(chip->dev) == USB_SPEED_FULL) 1150 + ep->syncinterval = 1; 1151 + else if (get_endpoint(alts, 1)->bInterval >= 1 && 1152 + get_endpoint(alts, 1)->bInterval <= 16) 1153 + ep->syncinterval = get_endpoint(alts, 1)->bInterval - 1; 1154 + else 1155 + ep->syncinterval = 3; 1156 + 1157 + ep->syncmaxsize = le16_to_cpu(get_endpoint(alts, 1)->wMaxPacketSize); 1158 + } 1159 + 1160 + list_add_tail(&ep->list, &chip->ep_list); 1161 + 1162 + __exit_unlock: 1163 + mutex_unlock(&chip->mutex); 1164 + 1165 + return ep; 1166 + } 1167 + 1168 + /* 1169 + * wait until all urbs are processed. 1170 + */ 1171 + static int wait_clear_urbs(struct snd_usb_endpoint *ep) 1172 + { 1173 + unsigned long end_time = jiffies + msecs_to_jiffies(1000); 1174 + unsigned int i; 1175 + int alive; 1176 + 1177 + do { 1178 + alive = 0; 1179 + for (i = 0; i < ep->nurbs; i++) 1180 + if (test_bit(i, &ep->active_mask)) 1181 + alive++; 1182 + 1183 + if (!alive) 1184 + break; 1185 + 1186 + schedule_timeout_uninterruptible(1); 1187 + } while (time_before(jiffies, end_time)); 1188 + 1189 + if (alive) 1190 + snd_printk(KERN_ERR "timeout: still %d active urbs on EP #%x\n", 1191 + alive, ep->ep_num); 1192 + 1193 + return 0; 1194 + } 1195 + 1196 + /* 1197 + * unlink active urbs. 1198 + */ 1199 + static int deactivate_urbs(struct snd_usb_endpoint *ep, int force, int can_sleep) 1200 + { 1201 + unsigned int i; 1202 + int async; 1203 + 1204 + if (!force && ep->chip->shutdown) /* to be sure... */ 1205 + return -EBADFD; 1206 + 1207 + async = !can_sleep && ep->chip->async_unlink; 1208 + 1209 + clear_bit(EP_FLAG_RUNNING, &ep->flags); 1210 + 1211 + INIT_LIST_HEAD(&ep->ready_playback_urbs); 1212 + ep->next_packet_read_pos = 0; 1213 + ep->next_packet_write_pos = 0; 1214 + 1215 + if (!async && in_interrupt()) 1216 + return 0; 1217 + 1218 + for (i = 0; i < ep->nurbs; i++) { 1219 + if (test_bit(i, &ep->active_mask)) { 1220 + if (!test_and_set_bit(i, &ep->unlink_mask)) { 1221 + struct urb *u = ep->urb[i].urb; 1222 + if (async) 1223 + usb_unlink_urb(u); 1224 + else 1225 + usb_kill_urb(u); 147 1226 } 148 1227 } 149 1228 } 150 1229 151 - subs->active_mask = 0; 152 - subs->unlink_mask = 0; 153 - subs->running = 1; 154 - for (i = 0; i < subs->nurbs; i++) { 155 - err = usb_submit_urb(subs->dataurb[i].urb, GFP_ATOMIC); 1230 + return 0; 1231 + } 1232 + 1233 + /* 1234 + * release an endpoint's urbs 1235 + */ 1236 + static void release_urbs(struct snd_usb_endpoint *ep, int force) 1237 + { 1238 + int i; 1239 + 1240 + /* route incoming urbs to nirvana */ 1241 + ep->retire_data_urb = NULL; 1242 + ep->prepare_data_urb = NULL; 1243 + 1244 + /* stop urbs */ 1245 + deactivate_urbs(ep, force, 1); 1246 + wait_clear_urbs(ep); 1247 + 1248 + for (i = 0; i < ep->nurbs; i++) 1249 + release_urb_ctx(&ep->urb[i]); 1250 + 1251 + if (ep->syncbuf) 1252 + usb_free_coherent(ep->chip->dev, SYNC_URBS * 4, 1253 + ep->syncbuf, ep->sync_dma); 1254 + 1255 + ep->syncbuf = NULL; 1256 + ep->nurbs = 0; 1257 + } 1258 + 1259 + /* 1260 + * configure a data endpoint 1261 + */ 1262 + static int data_ep_set_params(struct snd_usb_endpoint *ep, 1263 + struct snd_pcm_hw_params *hw_params, 1264 + struct audioformat *fmt, 1265 + struct snd_usb_endpoint *sync_ep) 1266 + { 1267 + unsigned int maxsize, i, urb_packs, total_packs, packs_per_ms; 1268 + int period_bytes = params_period_bytes(hw_params); 1269 + int format = params_format(hw_params); 1270 + int is_playback = usb_pipeout(ep->pipe); 1271 + int frame_bits = snd_pcm_format_physical_width(params_format(hw_params)) * 1272 + params_channels(hw_params); 1273 + 1274 + ep->datainterval = fmt->datainterval; 1275 + ep->stride = frame_bits >> 3; 1276 + ep->silence_value = format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0; 1277 + 1278 + /* calculate max. frequency */ 1279 + if (ep->maxpacksize) { 1280 + /* whatever fits into a max. size packet */ 1281 + maxsize = ep->maxpacksize; 1282 + ep->freqmax = (maxsize / (frame_bits >> 3)) 1283 + << (16 - ep->datainterval); 1284 + } else { 1285 + /* no max. packet size: just take 25% higher than nominal */ 1286 + ep->freqmax = ep->freqn + (ep->freqn >> 2); 1287 + maxsize = ((ep->freqmax + 0xffff) * (frame_bits >> 3)) 1288 + >> (16 - ep->datainterval); 1289 + } 1290 + 1291 + if (ep->fill_max) 1292 + ep->curpacksize = ep->maxpacksize; 1293 + else 1294 + ep->curpacksize = maxsize; 1295 + 1296 + if (snd_usb_get_speed(ep->chip->dev) != USB_SPEED_FULL) 1297 + packs_per_ms = 8 >> ep->datainterval; 1298 + else 1299 + packs_per_ms = 1; 1300 + 1301 + if (is_playback && !snd_usb_endpoint_implict_feedback_sink(ep)) { 1302 + urb_packs = max(ep->chip->nrpacks, 1); 1303 + urb_packs = min(urb_packs, (unsigned int) MAX_PACKS); 1304 + } else { 1305 + urb_packs = 1; 1306 + } 1307 + 1308 + urb_packs *= packs_per_ms; 1309 + 1310 + if (sync_ep && !snd_usb_endpoint_implict_feedback_sink(ep)) 1311 + urb_packs = min(urb_packs, 1U << sync_ep->syncinterval); 1312 + 1313 + /* decide how many packets to be used */ 1314 + if (is_playback && !snd_usb_endpoint_implict_feedback_sink(ep)) { 1315 + unsigned int minsize, maxpacks; 1316 + /* determine how small a packet can be */ 1317 + minsize = (ep->freqn >> (16 - ep->datainterval)) 1318 + * (frame_bits >> 3); 1319 + /* with sync from device, assume it can be 12% lower */ 1320 + if (sync_ep) 1321 + minsize -= minsize >> 3; 1322 + minsize = max(minsize, 1u); 1323 + total_packs = (period_bytes + minsize - 1) / minsize; 1324 + /* we need at least two URBs for queueing */ 1325 + if (total_packs < 2) { 1326 + total_packs = 2; 1327 + } else { 1328 + /* and we don't want too long a queue either */ 1329 + maxpacks = max(MAX_QUEUE * packs_per_ms, urb_packs * 2); 1330 + total_packs = min(total_packs, maxpacks); 1331 + } 1332 + } else { 1333 + while (urb_packs > 1 && urb_packs * maxsize >= period_bytes) 1334 + urb_packs >>= 1; 1335 + total_packs = MAX_URBS * urb_packs; 1336 + } 1337 + 1338 + ep->nurbs = (total_packs + urb_packs - 1) / urb_packs; 1339 + if (ep->nurbs > MAX_URBS) { 1340 + /* too much... */ 1341 + ep->nurbs = MAX_URBS; 1342 + total_packs = MAX_URBS * urb_packs; 1343 + } else if (ep->nurbs < 2) { 1344 + /* too little - we need at least two packets 1345 + * to ensure contiguous playback/capture 1346 + */ 1347 + ep->nurbs = 2; 1348 + } 1349 + 1350 + /* allocate and initialize data urbs */ 1351 + for (i = 0; i < ep->nurbs; i++) { 1352 + struct snd_urb_ctx *u = &ep->urb[i]; 1353 + u->index = i; 1354 + u->ep = ep; 1355 + u->packets = (i + 1) * total_packs / ep->nurbs 1356 + - i * total_packs / ep->nurbs; 1357 + u->buffer_size = maxsize * u->packets; 1358 + 1359 + if (fmt->fmt_type == UAC_FORMAT_TYPE_II) 1360 + u->packets++; /* for transfer delimiter */ 1361 + u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); 1362 + if (!u->urb) 1363 + goto out_of_memory; 1364 + 1365 + u->urb->transfer_buffer = 1366 + usb_alloc_coherent(ep->chip->dev, u->buffer_size, 1367 + GFP_KERNEL, &u->urb->transfer_dma); 1368 + if (!u->urb->transfer_buffer) 1369 + goto out_of_memory; 1370 + u->urb->pipe = ep->pipe; 1371 + u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 1372 + u->urb->interval = 1 << ep->datainterval; 1373 + u->urb->context = u; 1374 + u->urb->complete = snd_complete_urb; 1375 + INIT_LIST_HEAD(&u->ready_list); 1376 + } 1377 + 1378 + return 0; 1379 + 1380 + out_of_memory: 1381 + release_urbs(ep, 0); 1382 + return -ENOMEM; 1383 + } 1384 + 1385 + /* 1386 + * configure a sync endpoint 1387 + */ 1388 + static int sync_ep_set_params(struct snd_usb_endpoint *ep, 1389 + struct snd_pcm_hw_params *hw_params, 1390 + struct audioformat *fmt) 1391 + { 1392 + int i; 1393 + 1394 + ep->syncbuf = usb_alloc_coherent(ep->chip->dev, SYNC_URBS * 4, 1395 + GFP_KERNEL, &ep->sync_dma); 1396 + if (!ep->syncbuf) 1397 + return -ENOMEM; 1398 + 1399 + for (i = 0; i < SYNC_URBS; i++) { 1400 + struct snd_urb_ctx *u = &ep->urb[i]; 1401 + u->index = i; 1402 + u->ep = ep; 1403 + u->packets = 1; 1404 + u->urb = usb_alloc_urb(1, GFP_KERNEL); 1405 + if (!u->urb) 1406 + goto out_of_memory; 1407 + u->urb->transfer_buffer = ep->syncbuf + i * 4; 1408 + u->urb->transfer_dma = ep->sync_dma + i * 4; 1409 + u->urb->transfer_buffer_length = 4; 1410 + u->urb->pipe = ep->pipe; 1411 + u->urb->transfer_flags = URB_ISO_ASAP | 1412 + URB_NO_TRANSFER_DMA_MAP; 1413 + u->urb->number_of_packets = 1; 1414 + u->urb->interval = 1 << ep->syncinterval; 1415 + u->urb->context = u; 1416 + u->urb->complete = snd_complete_urb; 1417 + } 1418 + 1419 + ep->nurbs = SYNC_URBS; 1420 + 1421 + return 0; 1422 + 1423 + out_of_memory: 1424 + release_urbs(ep, 0); 1425 + return -ENOMEM; 1426 + } 1427 + 1428 + /** 1429 + * snd_usb_endpoint_set_params: configure an snd_usb_endpoint 1430 + * 1431 + * @ep: the snd_usb_endpoint to configure 1432 + * @hw_params: the hardware parameters 1433 + * @fmt: the USB audio format information 1434 + * @sync_ep: the sync endpoint to use, if any 1435 + * 1436 + * Determine the number of URBs to be used on this endpoint. 1437 + * An endpoint must be configured before it can be started. 1438 + * An endpoint that is already running can not be reconfigured. 1439 + */ 1440 + int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep, 1441 + struct snd_pcm_hw_params *hw_params, 1442 + struct audioformat *fmt, 1443 + struct snd_usb_endpoint *sync_ep) 1444 + { 1445 + int err; 1446 + 1447 + if (ep->use_count != 0) { 1448 + snd_printk(KERN_WARNING "Unable to change format on ep #%x: already in use\n", 1449 + ep->ep_num); 1450 + return -EBUSY; 1451 + } 1452 + 1453 + /* release old buffers, if any */ 1454 + release_urbs(ep, 0); 1455 + 1456 + ep->datainterval = fmt->datainterval; 1457 + ep->maxpacksize = fmt->maxpacksize; 1458 + ep->fill_max = !!(fmt->attributes & UAC_EP_CS_ATTR_FILL_MAX); 1459 + 1460 + if (snd_usb_get_speed(ep->chip->dev) == USB_SPEED_FULL) 1461 + ep->freqn = get_usb_full_speed_rate(params_rate(hw_params)); 1462 + else 1463 + ep->freqn = get_usb_high_speed_rate(params_rate(hw_params)); 1464 + 1465 + /* calculate the frequency in 16.16 format */ 1466 + ep->freqm = ep->freqn; 1467 + ep->freqshift = INT_MIN; 1468 + 1469 + ep->phase = 0; 1470 + 1471 + switch (ep->type) { 1472 + case SND_USB_ENDPOINT_TYPE_DATA: 1473 + err = data_ep_set_params(ep, hw_params, fmt, sync_ep); 1474 + break; 1475 + case SND_USB_ENDPOINT_TYPE_SYNC: 1476 + err = sync_ep_set_params(ep, hw_params, fmt); 1477 + break; 1478 + default: 1479 + err = -EINVAL; 1480 + } 1481 + 1482 + snd_printdd(KERN_DEBUG "Setting params for ep #%x (type %d, %d urbs), ret=%d\n", 1483 + ep->ep_num, ep->type, ep->nurbs, err); 1484 + 1485 + return err; 1486 + } 1487 + 1488 + /** 1489 + * snd_usb_endpoint_start: start an snd_usb_endpoint 1490 + * 1491 + * @ep: the endpoint to start 1492 + * 1493 + * A call to this function will increment the use count of the endpoint. 1494 + * In case it is not already running, the URBs for this endpoint will be 1495 + * submitted. Otherwise, this function does nothing. 1496 + * 1497 + * Must be balanced to calls of snd_usb_endpoint_stop(). 1498 + * 1499 + * Returns an error if the URB submission failed, 0 in all other cases. 1500 + */ 1501 + int snd_usb_endpoint_start(struct snd_usb_endpoint *ep) 1502 + { 1503 + int err; 1504 + unsigned int i; 1505 + 1506 + if (ep->chip->shutdown) 1507 + return -EBADFD; 1508 + 1509 + /* already running? */ 1510 + if (++ep->use_count != 1) 1511 + return 0; 1512 + 1513 + if (snd_BUG_ON(!test_bit(EP_FLAG_ACTIVATED, &ep->flags))) 1514 + return -EINVAL; 1515 + 1516 + /* just to be sure */ 1517 + deactivate_urbs(ep, 0, 1); 1518 + wait_clear_urbs(ep); 1519 + 1520 + ep->active_mask = 0; 1521 + ep->unlink_mask = 0; 1522 + ep->phase = 0; 1523 + 1524 + /* 1525 + * If this endpoint has a data endpoint as implicit feedback source, 1526 + * don't start the urbs here. Instead, mark them all as available, 1527 + * wait for the record urbs to return and queue the playback urbs 1528 + * from that context. 1529 + */ 1530 + 1531 + set_bit(EP_FLAG_RUNNING, &ep->flags); 1532 + 1533 + if (snd_usb_endpoint_implict_feedback_sink(ep)) { 1534 + for (i = 0; i < ep->nurbs; i++) { 1535 + struct snd_urb_ctx *ctx = ep->urb + i; 1536 + list_add_tail(&ctx->ready_list, &ep->ready_playback_urbs); 1537 + } 1538 + 1539 + return 0; 1540 + } 1541 + 1542 + for (i = 0; i < ep->nurbs; i++) { 1543 + struct urb *urb = ep->urb[i].urb; 1544 + 1545 + if (snd_BUG_ON(!urb)) 1546 + goto __error; 1547 + 1548 + if (usb_pipeout(ep->pipe)) { 1549 + prepare_outbound_urb_sizes(ep, urb->context); 1550 + prepare_outbound_urb(ep, urb->context); 1551 + } else { 1552 + prepare_inbound_urb(ep, urb->context); 1553 + } 1554 + 1555 + err = usb_submit_urb(urb, GFP_ATOMIC); 156 1556 if (err < 0) { 157 - snd_printk(KERN_ERR "cannot submit datapipe " 158 - "for urb %d, error %d: %s\n", 1557 + snd_printk(KERN_ERR "cannot submit urb %d, error %d: %s\n", 159 1558 i, err, usb_error_string(err)); 160 1559 goto __error; 161 1560 } 162 - set_bit(i, &subs->active_mask); 1561 + set_bit(i, &ep->active_mask); 163 1562 } 164 - if (subs->syncpipe) { 165 - for (i = 0; i < SYNC_URBS; i++) { 166 - err = usb_submit_urb(subs->syncurb[i].urb, GFP_ATOMIC); 167 - if (err < 0) { 168 - snd_printk(KERN_ERR "cannot submit syncpipe " 169 - "for urb %d, error %d: %s\n", 170 - i, err, usb_error_string(err)); 171 - goto __error; 172 - } 173 - set_bit(i + 16, &subs->active_mask); 174 - } 175 - } 1563 + 176 1564 return 0; 177 1565 178 - __error: 179 - // snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN); 180 - deactivate_urbs(subs, 0, 0); 1566 + __error: 1567 + clear_bit(EP_FLAG_RUNNING, &ep->flags); 1568 + ep->use_count--; 1569 + deactivate_urbs(ep, 0, 0); 181 1570 return -EPIPE; 182 1571 } 183 1572 184 - 185 - /* 1573 + /** 1574 + * snd_usb_endpoint_stop: stop an snd_usb_endpoint 1575 + * 1576 + * @ep: the endpoint to stop (may be NULL) 1577 + * 1578 + * A call to this function will decrement the use count of the endpoint. 1579 + * In case the last user has requested the endpoint stop, the URBs will 1580 + * actually be deactivated. 1581 + * 1582 + * Must be balanced to calls of snd_usb_endpoint_start(). 186 1583 */ 187 - static struct snd_urb_ops audio_urb_ops[2] = { 188 - { 189 - .prepare = prepare_nodata_playback_urb, 190 - .retire = retire_playback_urb, 191 - .prepare_sync = prepare_playback_sync_urb, 192 - .retire_sync = retire_playback_sync_urb, 193 - }, 194 - { 195 - .prepare = prepare_capture_urb, 196 - .retire = retire_capture_urb, 197 - .prepare_sync = prepare_capture_sync_urb, 198 - .retire_sync = retire_capture_sync_urb, 199 - }, 200 - }; 1584 + void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep, 1585 + int force, int can_sleep, int wait) 1586 + { 1587 + if (!ep) 1588 + return; 201 1589 202 - /* 203 - * initialize the substream instance. 1590 + if (snd_BUG_ON(ep->use_count == 0)) 1591 + return; 1592 + 1593 + if (snd_BUG_ON(!test_bit(EP_FLAG_ACTIVATED, &ep->flags))) 1594 + return; 1595 + 1596 + if (--ep->use_count == 0) { 1597 + deactivate_urbs(ep, force, can_sleep); 1598 + ep->data_subs = NULL; 1599 + ep->sync_slave = NULL; 1600 + ep->retire_data_urb = NULL; 1601 + ep->prepare_data_urb = NULL; 1602 + 1603 + if (wait) 1604 + wait_clear_urbs(ep); 1605 + } 1606 + } 1607 + 1608 + /** 1609 + * snd_usb_endpoint_activate: activate an snd_usb_endpoint 1610 + * 1611 + * @ep: the endpoint to activate 1612 + * 1613 + * If the endpoint is not currently in use, this functions will select the 1614 + * correct alternate interface setting for the interface of this endpoint. 1615 + * 1616 + * In case of any active users, this functions does nothing. 1617 + * 1618 + * Returns an error if usb_set_interface() failed, 0 in all other 1619 + * cases. 204 1620 */ 205 - 206 - void snd_usb_init_substream(struct snd_usb_stream *as, 207 - int stream, struct audioformat *fp) 1621 + int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep) 208 1622 { 209 - struct snd_usb_substream *subs = &as->substream[stream]; 210 - 211 - INIT_LIST_HEAD(&subs->fmt_list); 212 - spin_lock_init(&subs->lock); 213 - 214 - subs->stream = as; 215 - subs->direction = stream; 216 - subs->dev = as->chip->dev; 217 - subs->txfr_quirk = as->chip->txfr_quirk; 218 - subs->ops = audio_urb_ops[stream]; 219 - if (snd_usb_get_speed(subs->dev) >= USB_SPEED_HIGH) 220 - subs->ops.prepare_sync = prepare_capture_sync_urb_hs; 221 - 222 - snd_usb_set_pcm_ops(as->pcm, stream); 223 - 224 - list_add_tail(&fp->list, &subs->fmt_list); 225 - subs->formats |= fp->formats; 226 - subs->endpoint = fp->endpoint; 227 - subs->num_formats++; 228 - subs->fmt_type = fp->fmt_type; 229 - } 230 - 231 - int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd) 232 - { 233 - struct snd_usb_substream *subs = substream->runtime->private_data; 234 - 235 - switch (cmd) { 236 - case SNDRV_PCM_TRIGGER_START: 237 - case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 238 - subs->ops.prepare = prepare_playback_urb; 1623 + if (ep->use_count != 0) 239 1624 return 0; 240 - case SNDRV_PCM_TRIGGER_STOP: 241 - return deactivate_urbs(subs, 0, 0); 242 - case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 243 - subs->ops.prepare = prepare_nodata_playback_urb; 1625 + 1626 + if (!ep->chip->shutdown && 1627 + !test_and_set_bit(EP_FLAG_ACTIVATED, &ep->flags)) { 1628 + int ret; 1629 + 1630 + ret = usb_set_interface(ep->chip->dev, ep->iface, ep->alt_idx); 1631 + if (ret < 0) { 1632 + snd_printk(KERN_ERR "%s() usb_set_interface() failed, ret = %d\n", 1633 + __func__, ret); 1634 + clear_bit(EP_FLAG_ACTIVATED, &ep->flags); 1635 + return ret; 1636 + } 1637 + 244 1638 return 0; 245 1639 } 246 1640 247 - return -EINVAL; 1641 + return -EBUSY; 248 1642 } 249 1643 250 - int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd) 1644 + /** 1645 + * snd_usb_endpoint_deactivate: deactivate an snd_usb_endpoint 1646 + * 1647 + * @ep: the endpoint to deactivate 1648 + * 1649 + * If the endpoint is not currently in use, this functions will select the 1650 + * alternate interface setting 0 for the interface of this endpoint. 1651 + * 1652 + * In case of any active users, this functions does nothing. 1653 + * 1654 + * Returns an error if usb_set_interface() failed, 0 in all other 1655 + * cases. 1656 + */ 1657 + int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep) 251 1658 { 252 - struct snd_usb_substream *subs = substream->runtime->private_data; 1659 + if (!ep) 1660 + return -EINVAL; 253 1661 254 - switch (cmd) { 255 - case SNDRV_PCM_TRIGGER_START: 256 - subs->ops.retire = retire_capture_urb; 257 - return start_urbs(subs, substream->runtime); 258 - case SNDRV_PCM_TRIGGER_STOP: 259 - return deactivate_urbs(subs, 0, 0); 260 - case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 261 - subs->ops.retire = retire_paused_capture_urb; 1662 + if (ep->use_count != 0) 262 1663 return 0; 263 - case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 264 - subs->ops.retire = retire_capture_urb; 1664 + 1665 + if (!ep->chip->shutdown && 1666 + test_and_clear_bit(EP_FLAG_ACTIVATED, &ep->flags)) { 1667 + int ret; 1668 + 1669 + ret = usb_set_interface(ep->chip->dev, ep->iface, 0); 1670 + if (ret < 0) { 1671 + snd_printk(KERN_ERR "%s(): usb_set_interface() failed, ret = %d\n", 1672 + __func__, ret); 1673 + return ret; 1674 + } 1675 + 265 1676 return 0; 266 1677 } 267 1678 268 - return -EINVAL; 1679 + return -EBUSY; 269 1680 } 270 1681 271 - int snd_usb_substream_prepare(struct snd_usb_substream *subs, 272 - struct snd_pcm_runtime *runtime) 1682 + /** 1683 + * snd_usb_endpoint_free: Free the resources of an snd_usb_endpoint 1684 + * 1685 + * @ep: the list header of the endpoint to free 1686 + * 1687 + * This function does not care for the endpoint's use count but will tear 1688 + * down all the streaming URBs immediately and free all resources. 1689 + */ 1690 + void snd_usb_endpoint_free(struct list_head *head) 273 1691 { 274 - /* clear urbs (to be sure) */ 275 - deactivate_urbs(subs, 0, 1); 276 - wait_clear_urbs(subs); 1692 + struct snd_usb_endpoint *ep; 277 1693 278 - /* for playback, submit the URBs now; otherwise, the first hwptr_done 279 - * updates for all URBs would happen at the same time when starting */ 280 - if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) { 281 - subs->ops.prepare = prepare_nodata_playback_urb; 282 - return start_urbs(subs, runtime); 1694 + ep = list_entry(head, struct snd_usb_endpoint, list); 1695 + release_urbs(ep, 1); 1696 + kfree(ep); 1697 + } 1698 + 1699 + /** 1700 + * snd_usb_handle_sync_urb: parse an USB sync packet 1701 + * 1702 + * @ep: the endpoint to handle the packet 1703 + * @sender: the sending endpoint 1704 + * @urb: the received packet 1705 + * 1706 + * This function is called from the context of an endpoint that received 1707 + * the packet and is used to let another endpoint object handle the payload. 1708 + */ 1709 + void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep, 1710 + struct snd_usb_endpoint *sender, 1711 + const struct urb *urb) 1712 + { 1713 + int shift; 1714 + unsigned int f; 1715 + unsigned long flags; 1716 + 1717 + snd_BUG_ON(ep == sender); 1718 + 1719 + /* 1720 + * In case the endpoint is operating in implicit feedback mode, prepare 1721 + * a new outbound URB that has the same layout as the received packet 1722 + * and add it to the list of pending urbs. queue_pending_output_urbs() 1723 + * will take care of them later. 1724 + */ 1725 + if (snd_usb_endpoint_implict_feedback_sink(ep) && 1726 + ep->use_count != 0) { 1727 + 1728 + /* implicit feedback case */ 1729 + int i, bytes = 0; 1730 + struct snd_urb_ctx *in_ctx; 1731 + struct snd_usb_packet_info *out_packet; 1732 + 1733 + in_ctx = urb->context; 1734 + 1735 + /* Count overall packet size */ 1736 + for (i = 0; i < in_ctx->packets; i++) 1737 + if (urb->iso_frame_desc[i].status == 0) 1738 + bytes += urb->iso_frame_desc[i].actual_length; 1739 + 1740 + /* 1741 + * skip empty packets. At least M-Audio's Fast Track Ultra stops 1742 + * streaming once it received a 0-byte OUT URB 1743 + */ 1744 + if (bytes == 0) 1745 + return; 1746 + 1747 + spin_lock_irqsave(&ep->lock, flags); 1748 + out_packet = ep->next_packet + ep->next_packet_write_pos; 1749 + 1750 + /* 1751 + * Iterate through the inbound packet and prepare the lengths 1752 + * for the output packet. The OUT packet we are about to send 1753 + * will have the same amount of payload bytes than the IN 1754 + * packet we just received. 1755 + */ 1756 + 1757 + out_packet->packets = in_ctx->packets; 1758 + for (i = 0; i < in_ctx->packets; i++) { 1759 + if (urb->iso_frame_desc[i].status == 0) 1760 + out_packet->packet_size[i] = 1761 + urb->iso_frame_desc[i].actual_length / ep->stride; 1762 + else 1763 + out_packet->packet_size[i] = 0; 1764 + } 1765 + 1766 + ep->next_packet_write_pos++; 1767 + ep->next_packet_write_pos %= MAX_URBS; 1768 + spin_unlock_irqrestore(&ep->lock, flags); 1769 + queue_pending_output_urbs(ep); 1770 + 1771 + return; 283 1772 } 284 1773 285 - return 0; 1774 + /* 1775 + * process after playback sync complete 1776 + * 1777 + * Full speed devices report feedback values in 10.14 format as samples 1778 + * per frame, high speed devices in 16.16 format as samples per 1779 + * microframe. 1780 + * 1781 + * Because the Audio Class 1 spec was written before USB 2.0, many high 1782 + * speed devices use a wrong interpretation, some others use an 1783 + * entirely different format. 1784 + * 1785 + * Therefore, we cannot predict what format any particular device uses 1786 + * and must detect it automatically. 1787 + */ 1788 + 1789 + if (urb->iso_frame_desc[0].status != 0 || 1790 + urb->iso_frame_desc[0].actual_length < 3) 1791 + return; 1792 + 1793 + f = le32_to_cpup(urb->transfer_buffer); 1794 + if (urb->iso_frame_desc[0].actual_length == 3) 1795 + f &= 0x00ffffff; 1796 + else 1797 + f &= 0x0fffffff; 1798 + 1799 + if (f == 0) 1800 + return; 1801 + 1802 + if (unlikely(ep->freqshift == INT_MIN)) { 1803 + /* 1804 + * The first time we see a feedback value, determine its format 1805 + * by shifting it left or right until it matches the nominal 1806 + * frequency value. This assumes that the feedback does not 1807 + * differ from the nominal value more than +50% or -25%. 1808 + */ 1809 + shift = 0; 1810 + while (f < ep->freqn - ep->freqn / 4) { 1811 + f <<= 1; 1812 + shift++; 1813 + } 1814 + while (f > ep->freqn + ep->freqn / 2) { 1815 + f >>= 1; 1816 + shift--; 1817 + } 1818 + ep->freqshift = shift; 1819 + } else if (ep->freqshift >= 0) 1820 + f <<= ep->freqshift; 1821 + else 1822 + f >>= -ep->freqshift; 1823 + 1824 + if (likely(f >= ep->freqn - ep->freqn / 8 && f <= ep->freqmax)) { 1825 + /* 1826 + * If the frequency looks valid, set it. 1827 + * This value is referred to in prepare_playback_urb(). 1828 + */ 1829 + spin_lock_irqsave(&ep->lock, flags); 1830 + ep->freqm = f; 1831 + spin_unlock_irqrestore(&ep->lock, flags); 1832 + } else { 1833 + /* 1834 + * Out of range; maybe the shift value is wrong. 1835 + * Reset it so that we autodetect again the next time. 1836 + */ 1837 + ep->freqshift = INT_MIN; 1838 + } 286 1839 } 287 1840
+20 -12
sound/usb/endpoint.h
··· 1 1 #ifndef __USBAUDIO_ENDPOINT_H 2 2 #define __USBAUDIO_ENDPOINT_H 3 3 4 - void snd_usb_init_substream(struct snd_usb_stream *as, 5 - int stream, 6 - struct audioformat *fp); 4 + #define SND_USB_ENDPOINT_TYPE_DATA 0 5 + #define SND_USB_ENDPOINT_TYPE_SYNC 1 7 6 8 - int snd_usb_init_substream_urbs(struct snd_usb_substream *subs, 9 - unsigned int period_bytes, 10 - unsigned int rate, 11 - unsigned int frame_bits); 7 + struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip, 8 + struct usb_host_interface *alts, 9 + int ep_num, int direction, int type); 12 10 13 - void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force); 11 + int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep, 12 + struct snd_pcm_hw_params *hw_params, 13 + struct audioformat *fmt, 14 + struct snd_usb_endpoint *sync_ep); 14 15 15 - int snd_usb_substream_prepare(struct snd_usb_substream *subs, 16 - struct snd_pcm_runtime *runtime); 16 + int snd_usb_endpoint_start(struct snd_usb_endpoint *ep); 17 + void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep, 18 + int force, int can_sleep, int wait); 19 + int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep); 20 + int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep); 21 + void snd_usb_endpoint_free(struct list_head *head); 17 22 18 - int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd); 19 - int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd); 23 + int snd_usb_endpoint_implict_feedback_sink(struct snd_usb_endpoint *ep); 24 + 25 + void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep, 26 + struct snd_usb_endpoint *sender, 27 + const struct urb *urb); 20 28 21 29 #endif /* __USBAUDIO_ENDPOINT_H */
+35 -15
sound/usb/mixer.c
··· 486 486 /* 487 487 * TLV callback for mixer volume controls 488 488 */ 489 - static int mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, 489 + int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, 490 490 unsigned int size, unsigned int __user *_tlv) 491 491 { 492 492 struct usb_mixer_elem_info *cval = kcontrol->private_data; ··· 770 770 struct snd_kcontrol *kctl) 771 771 { 772 772 switch (cval->mixer->chip->usb_id) { 773 + case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ 774 + case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ 775 + if (strcmp(kctl->id.name, "Effect Duration") == 0) { 776 + snd_printk(KERN_INFO 777 + "usb-audio: set quirk for FTU Effect Duration\n"); 778 + cval->min = 0x0000; 779 + cval->max = 0x7f00; 780 + cval->res = 0x0100; 781 + break; 782 + } 783 + if (strcmp(kctl->id.name, "Effect Volume") == 0 || 784 + strcmp(kctl->id.name, "Effect Feedback Volume") == 0) { 785 + snd_printk(KERN_INFO 786 + "usb-audio: set quirks for FTU Effect Feedback/Volume\n"); 787 + cval->min = 0x00; 788 + cval->max = 0x7f; 789 + break; 790 + } 791 + break; 792 + 773 793 case USB_ID(0x0471, 0x0101): 774 794 case USB_ID(0x0471, 0x0104): 775 795 case USB_ID(0x0471, 0x0105): ··· 1141 1121 len = snd_usb_copy_string_desc(state, nameid, 1142 1122 kctl->id.name, sizeof(kctl->id.name)); 1143 1123 1144 - /* get min/max values */ 1145 - get_min_max_with_quirks(cval, 0, kctl); 1146 - 1147 1124 switch (control) { 1148 1125 case UAC_FU_MUTE: 1149 1126 case UAC_FU_VOLUME: ··· 1172 1155 } 1173 1156 append_ctl_name(kctl, control == UAC_FU_MUTE ? 1174 1157 " Switch" : " Volume"); 1175 - if (control == UAC_FU_VOLUME) { 1176 - check_mapped_dB(map, cval); 1177 - if (cval->dBmin < cval->dBmax || !cval->initialized) { 1178 - kctl->tlv.c = mixer_vol_tlv; 1179 - kctl->vd[0].access |= 1180 - SNDRV_CTL_ELEM_ACCESS_TLV_READ | 1181 - SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; 1182 - } 1183 - } 1184 1158 break; 1185 - 1186 1159 default: 1187 1160 if (! len) 1188 1161 strlcpy(kctl->id.name, audio_feature_info[control-1].name, 1189 1162 sizeof(kctl->id.name)); 1190 1163 break; 1164 + } 1165 + 1166 + /* get min/max values */ 1167 + get_min_max_with_quirks(cval, 0, kctl); 1168 + 1169 + if (control == UAC_FU_VOLUME) { 1170 + check_mapped_dB(map, cval); 1171 + if (cval->dBmin < cval->dBmax || !cval->initialized) { 1172 + kctl->tlv.c = snd_usb_mixer_vol_tlv; 1173 + kctl->vd[0].access |= 1174 + SNDRV_CTL_ELEM_ACCESS_TLV_READ | 1175 + SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; 1176 + } 1191 1177 } 1192 1178 1193 1179 range = (cval->max - cval->min) / cval->res; ··· 1408 1388 for (pin = 0; pin < input_pins; pin++) { 1409 1389 err = parse_audio_unit(state, desc->baSourceID[pin]); 1410 1390 if (err < 0) 1411 - return err; 1391 + continue; 1412 1392 err = check_input_term(state, desc->baSourceID[pin], &iterm); 1413 1393 if (err < 0) 1414 1394 return err;
+3
sound/usb/mixer.h
··· 68 68 int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer, 69 69 struct snd_kcontrol *kctl); 70 70 71 + int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, 72 + unsigned int size, unsigned int __user *_tlv); 73 + 71 74 #endif /* __USBMIXER_H */
+13
sound/usb/mixer_maps.c
··· 288 288 { 0 } /* terminator */ 289 289 }; 290 290 291 + static struct usbmix_name_map ebox44_map[] = { 292 + { 4, NULL }, /* FU */ 293 + { 6, NULL }, /* MU */ 294 + { 7, NULL }, /* FU */ 295 + { 10, NULL }, /* FU */ 296 + { 11, NULL }, /* MU */ 297 + { 0 } 298 + }; 299 + 291 300 /* "Gamesurround Muse Pocket LT" looks same like "Sound Blaster MP3+" 292 301 * most importand difference is SU[8], it should be set to "Capture Source" 293 302 * to make alsamixer and PA working properly. ··· 379 370 .id = USB_ID(0x13e5, 0x0001), 380 371 .map = scratch_live_map, 381 372 .ignore_ctl_error = 1, 373 + }, 374 + { 375 + .id = USB_ID(0x200c, 0x1018), 376 + .map = ebox44_map, 382 377 }, 383 378 { 0 } /* terminator */ 384 379 };
+446 -28
sound/usb/mixer_quirks.c
··· 42 42 43 43 extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl; 44 44 45 + /* private_free callback */ 46 + static void usb_mixer_elem_free(struct snd_kcontrol *kctl) 47 + { 48 + kfree(kctl->private_data); 49 + kctl->private_data = NULL; 50 + } 51 + 52 + /* This function allows for the creation of standard UAC controls. 53 + * See the quirks for M-Audio FTUs or Ebox-44. 54 + * If you don't want to set a TLV callback pass NULL. 55 + * 56 + * Since there doesn't seem to be a devices that needs a multichannel 57 + * version, we keep it mono for simplicity. 58 + */ 59 + static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer, 60 + unsigned int unitid, 61 + unsigned int control, 62 + unsigned int cmask, 63 + int val_type, 64 + const char *name, 65 + snd_kcontrol_tlv_rw_t *tlv_callback) 66 + { 67 + int err; 68 + struct usb_mixer_elem_info *cval; 69 + struct snd_kcontrol *kctl; 70 + 71 + cval = kzalloc(sizeof(*cval), GFP_KERNEL); 72 + if (!cval) 73 + return -ENOMEM; 74 + 75 + cval->id = unitid; 76 + cval->mixer = mixer; 77 + cval->val_type = val_type; 78 + cval->channels = 1; 79 + cval->control = control; 80 + cval->cmask = cmask; 81 + 82 + /* get_min_max() is called only for integer volumes later, 83 + * so provide a short-cut for booleans */ 84 + cval->min = 0; 85 + cval->max = 1; 86 + cval->res = 0; 87 + cval->dBmin = 0; 88 + cval->dBmax = 0; 89 + 90 + /* Create control */ 91 + kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval); 92 + if (!kctl) { 93 + kfree(cval); 94 + return -ENOMEM; 95 + } 96 + 97 + /* Set name */ 98 + snprintf(kctl->id.name, sizeof(kctl->id.name), name); 99 + kctl->private_free = usb_mixer_elem_free; 100 + 101 + /* set TLV */ 102 + if (tlv_callback) { 103 + kctl->tlv.c = tlv_callback; 104 + kctl->vd[0].access |= 105 + SNDRV_CTL_ELEM_ACCESS_TLV_READ | 106 + SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; 107 + } 108 + /* Add control to mixer */ 109 + err = snd_usb_mixer_add_control(mixer, kctl); 110 + if (err < 0) 111 + return err; 112 + 113 + return 0; 114 + } 115 + 45 116 /* 46 117 * Sound Blaster remote control configuration 47 118 * ··· 566 495 } 567 496 568 497 /* M-Audio FastTrack Ultra quirks */ 498 + /* FTU Effect switch */ 499 + struct snd_ftu_eff_switch_priv_val { 500 + struct usb_mixer_interface *mixer; 501 + int cached_value; 502 + int is_cached; 503 + }; 569 504 570 - /* private_free callback */ 571 - static void usb_mixer_elem_free(struct snd_kcontrol *kctl) 505 + static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol, 506 + struct snd_ctl_elem_info *uinfo) 572 507 { 573 - kfree(kctl->private_data); 574 - kctl->private_data = NULL; 508 + static const char *texts[8] = {"Room 1", 509 + "Room 2", 510 + "Room 3", 511 + "Hall 1", 512 + "Hall 2", 513 + "Plate", 514 + "Delay", 515 + "Echo" 516 + }; 517 + 518 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 519 + uinfo->count = 1; 520 + uinfo->value.enumerated.items = 8; 521 + if (uinfo->value.enumerated.item > 7) 522 + uinfo->value.enumerated.item = 7; 523 + strcpy(uinfo->value.enumerated.name, 524 + texts[uinfo->value.enumerated.item]); 525 + 526 + return 0; 575 527 } 576 528 577 - static int snd_maudio_ftu_create_ctl(struct usb_mixer_interface *mixer, 578 - int in, int out, const char *name) 529 + static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl, 530 + struct snd_ctl_elem_value *ucontrol) 579 531 { 580 - struct usb_mixer_elem_info *cval; 581 - struct snd_kcontrol *kctl; 532 + struct snd_usb_audio *chip; 533 + struct usb_mixer_interface *mixer; 534 + struct snd_ftu_eff_switch_priv_val *pval; 535 + int err; 536 + unsigned char value[2]; 582 537 583 - cval = kzalloc(sizeof(*cval), GFP_KERNEL); 584 - if (!cval) 538 + const int id = 6; 539 + const int validx = 1; 540 + const int val_len = 2; 541 + 542 + value[0] = 0x00; 543 + value[1] = 0x00; 544 + 545 + pval = (struct snd_ftu_eff_switch_priv_val *) 546 + kctl->private_value; 547 + 548 + if (pval->is_cached) { 549 + ucontrol->value.enumerated.item[0] = pval->cached_value; 550 + return 0; 551 + } 552 + 553 + mixer = (struct usb_mixer_interface *) pval->mixer; 554 + if (snd_BUG_ON(!mixer)) 555 + return -EINVAL; 556 + 557 + chip = (struct snd_usb_audio *) mixer->chip; 558 + if (snd_BUG_ON(!chip)) 559 + return -EINVAL; 560 + 561 + 562 + err = snd_usb_ctl_msg(chip->dev, 563 + usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR, 564 + USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 565 + validx << 8, snd_usb_ctrl_intf(chip) | (id << 8), 566 + value, val_len); 567 + if (err < 0) 568 + return err; 569 + 570 + ucontrol->value.enumerated.item[0] = value[0]; 571 + pval->cached_value = value[0]; 572 + pval->is_cached = 1; 573 + 574 + return 0; 575 + } 576 + 577 + static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl, 578 + struct snd_ctl_elem_value *ucontrol) 579 + { 580 + struct snd_usb_audio *chip; 581 + struct snd_ftu_eff_switch_priv_val *pval; 582 + 583 + struct usb_mixer_interface *mixer; 584 + int changed, cur_val, err, new_val; 585 + unsigned char value[2]; 586 + 587 + 588 + const int id = 6; 589 + const int validx = 1; 590 + const int val_len = 2; 591 + 592 + changed = 0; 593 + 594 + pval = (struct snd_ftu_eff_switch_priv_val *) 595 + kctl->private_value; 596 + cur_val = pval->cached_value; 597 + new_val = ucontrol->value.enumerated.item[0]; 598 + 599 + mixer = (struct usb_mixer_interface *) pval->mixer; 600 + if (snd_BUG_ON(!mixer)) 601 + return -EINVAL; 602 + 603 + chip = (struct snd_usb_audio *) mixer->chip; 604 + if (snd_BUG_ON(!chip)) 605 + return -EINVAL; 606 + 607 + if (!pval->is_cached) { 608 + /* Read current value */ 609 + err = snd_usb_ctl_msg(chip->dev, 610 + usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR, 611 + USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 612 + validx << 8, snd_usb_ctrl_intf(chip) | (id << 8), 613 + value, val_len); 614 + if (err < 0) 615 + return err; 616 + 617 + cur_val = value[0]; 618 + pval->cached_value = cur_val; 619 + pval->is_cached = 1; 620 + } 621 + /* update value if needed */ 622 + if (cur_val != new_val) { 623 + value[0] = new_val; 624 + value[1] = 0; 625 + err = snd_usb_ctl_msg(chip->dev, 626 + usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR, 627 + USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, 628 + validx << 8, snd_usb_ctrl_intf(chip) | (id << 8), 629 + value, val_len); 630 + if (err < 0) 631 + return err; 632 + 633 + pval->cached_value = new_val; 634 + pval->is_cached = 1; 635 + changed = 1; 636 + } 637 + 638 + return changed; 639 + } 640 + 641 + static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer) 642 + { 643 + static struct snd_kcontrol_new template = { 644 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 645 + .name = "Effect Program Switch", 646 + .index = 0, 647 + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 648 + .info = snd_ftu_eff_switch_info, 649 + .get = snd_ftu_eff_switch_get, 650 + .put = snd_ftu_eff_switch_put 651 + }; 652 + 653 + int err; 654 + struct snd_kcontrol *kctl; 655 + struct snd_ftu_eff_switch_priv_val *pval; 656 + 657 + pval = kzalloc(sizeof(*pval), GFP_KERNEL); 658 + if (!pval) 585 659 return -ENOMEM; 586 660 587 - cval->id = 5; 588 - cval->mixer = mixer; 589 - cval->val_type = USB_MIXER_S16; 590 - cval->channels = 1; 591 - cval->control = out + 1; 592 - cval->cmask = 1 << in; 661 + pval->cached_value = 0; 662 + pval->is_cached = 0; 663 + pval->mixer = mixer; 593 664 594 - kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval); 665 + template.private_value = (unsigned long) pval; 666 + kctl = snd_ctl_new1(&template, mixer->chip); 595 667 if (!kctl) { 596 - kfree(cval); 668 + kfree(pval); 597 669 return -ENOMEM; 598 670 } 599 671 600 - snprintf(kctl->id.name, sizeof(kctl->id.name), name); 601 - kctl->private_free = usb_mixer_elem_free; 602 - return snd_usb_mixer_add_control(mixer, kctl); 672 + err = snd_ctl_add(mixer->chip->card, kctl); 673 + if (err < 0) 674 + return err; 675 + 676 + return 0; 603 677 } 604 678 605 - static int snd_maudio_ftu_create_mixer(struct usb_mixer_interface *mixer) 679 + /* Create volume controls for FTU devices*/ 680 + static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer) 606 681 { 607 682 char name[64]; 683 + unsigned int control, cmask; 608 684 int in, out, err; 609 685 686 + const unsigned int id = 5; 687 + const int val_type = USB_MIXER_S16; 688 + 610 689 for (out = 0; out < 8; out++) { 690 + control = out + 1; 611 691 for (in = 0; in < 8; in++) { 692 + cmask = 1 << in; 612 693 snprintf(name, sizeof(name), 613 - "AIn%d - Out%d Capture Volume", in + 1, out + 1); 614 - err = snd_maudio_ftu_create_ctl(mixer, in, out, name); 694 + "AIn%d - Out%d Capture Volume", 695 + in + 1, out + 1); 696 + err = snd_create_std_mono_ctl(mixer, id, control, 697 + cmask, val_type, name, 698 + &snd_usb_mixer_vol_tlv); 615 699 if (err < 0) 616 700 return err; 617 701 } 618 - 619 702 for (in = 8; in < 16; in++) { 703 + cmask = 1 << in; 620 704 snprintf(name, sizeof(name), 621 - "DIn%d - Out%d Playback Volume", in - 7, out + 1); 622 - err = snd_maudio_ftu_create_ctl(mixer, in, out, name); 705 + "DIn%d - Out%d Playback Volume", 706 + in - 7, out + 1); 707 + err = snd_create_std_mono_ctl(mixer, id, control, 708 + cmask, val_type, name, 709 + &snd_usb_mixer_vol_tlv); 623 710 if (err < 0) 624 711 return err; 625 712 } 626 713 } 714 + 715 + return 0; 716 + } 717 + 718 + /* This control needs a volume quirk, see mixer.c */ 719 + static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer) 720 + { 721 + static const char name[] = "Effect Volume"; 722 + const unsigned int id = 6; 723 + const int val_type = USB_MIXER_U8; 724 + const unsigned int control = 2; 725 + const unsigned int cmask = 0; 726 + 727 + return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, 728 + name, snd_usb_mixer_vol_tlv); 729 + } 730 + 731 + /* This control needs a volume quirk, see mixer.c */ 732 + static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer) 733 + { 734 + static const char name[] = "Effect Duration"; 735 + const unsigned int id = 6; 736 + const int val_type = USB_MIXER_S16; 737 + const unsigned int control = 3; 738 + const unsigned int cmask = 0; 739 + 740 + return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, 741 + name, snd_usb_mixer_vol_tlv); 742 + } 743 + 744 + /* This control needs a volume quirk, see mixer.c */ 745 + static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer) 746 + { 747 + static const char name[] = "Effect Feedback Volume"; 748 + const unsigned int id = 6; 749 + const int val_type = USB_MIXER_U8; 750 + const unsigned int control = 4; 751 + const unsigned int cmask = 0; 752 + 753 + return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, 754 + name, NULL); 755 + } 756 + 757 + static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer) 758 + { 759 + unsigned int cmask; 760 + int err, ch; 761 + char name[48]; 762 + 763 + const unsigned int id = 7; 764 + const int val_type = USB_MIXER_S16; 765 + const unsigned int control = 7; 766 + 767 + for (ch = 0; ch < 4; ++ch) { 768 + cmask = 1 << ch; 769 + snprintf(name, sizeof(name), 770 + "Effect Return %d Volume", ch + 1); 771 + err = snd_create_std_mono_ctl(mixer, id, control, 772 + cmask, val_type, name, 773 + snd_usb_mixer_vol_tlv); 774 + if (err < 0) 775 + return err; 776 + } 777 + 778 + return 0; 779 + } 780 + 781 + static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer) 782 + { 783 + unsigned int cmask; 784 + int err, ch; 785 + char name[48]; 786 + 787 + const unsigned int id = 5; 788 + const int val_type = USB_MIXER_S16; 789 + const unsigned int control = 9; 790 + 791 + for (ch = 0; ch < 8; ++ch) { 792 + cmask = 1 << ch; 793 + snprintf(name, sizeof(name), 794 + "Effect Send AIn%d Volume", ch + 1); 795 + err = snd_create_std_mono_ctl(mixer, id, control, cmask, 796 + val_type, name, 797 + snd_usb_mixer_vol_tlv); 798 + if (err < 0) 799 + return err; 800 + } 801 + for (ch = 8; ch < 16; ++ch) { 802 + cmask = 1 << ch; 803 + snprintf(name, sizeof(name), 804 + "Effect Send DIn%d Volume", ch - 7); 805 + err = snd_create_std_mono_ctl(mixer, id, control, cmask, 806 + val_type, name, 807 + snd_usb_mixer_vol_tlv); 808 + if (err < 0) 809 + return err; 810 + } 811 + return 0; 812 + } 813 + 814 + static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer) 815 + { 816 + int err; 817 + 818 + err = snd_ftu_create_volume_ctls(mixer); 819 + if (err < 0) 820 + return err; 821 + 822 + err = snd_ftu_create_effect_switch(mixer); 823 + if (err < 0) 824 + return err; 825 + err = snd_ftu_create_effect_volume_ctl(mixer); 826 + if (err < 0) 827 + return err; 828 + 829 + err = snd_ftu_create_effect_duration_ctl(mixer); 830 + if (err < 0) 831 + return err; 832 + 833 + err = snd_ftu_create_effect_feedback_ctl(mixer); 834 + if (err < 0) 835 + return err; 836 + 837 + err = snd_ftu_create_effect_return_ctls(mixer); 838 + if (err < 0) 839 + return err; 840 + 841 + err = snd_ftu_create_effect_send_ctls(mixer); 842 + if (err < 0) 843 + return err; 844 + 845 + return 0; 846 + } 847 + 848 + 849 + /* 850 + * Create mixer for Electrix Ebox-44 851 + * 852 + * The mixer units from this device are corrupt, and even where they 853 + * are valid they presents mono controls as L and R channels of 854 + * stereo. So we create a good mixer in code. 855 + */ 856 + 857 + static int snd_ebox44_create_mixer(struct usb_mixer_interface *mixer) 858 + { 859 + int err; 860 + 861 + err = snd_create_std_mono_ctl(mixer, 4, 1, 0x0, USB_MIXER_INV_BOOLEAN, 862 + "Headphone Playback Switch", NULL); 863 + if (err < 0) 864 + return err; 865 + err = snd_create_std_mono_ctl(mixer, 4, 2, 0x1, USB_MIXER_S16, 866 + "Headphone A Mix Playback Volume", NULL); 867 + if (err < 0) 868 + return err; 869 + err = snd_create_std_mono_ctl(mixer, 4, 2, 0x2, USB_MIXER_S16, 870 + "Headphone B Mix Playback Volume", NULL); 871 + if (err < 0) 872 + return err; 873 + 874 + err = snd_create_std_mono_ctl(mixer, 7, 1, 0x0, USB_MIXER_INV_BOOLEAN, 875 + "Output Playback Switch", NULL); 876 + if (err < 0) 877 + return err; 878 + err = snd_create_std_mono_ctl(mixer, 7, 2, 0x1, USB_MIXER_S16, 879 + "Output A Playback Volume", NULL); 880 + if (err < 0) 881 + return err; 882 + err = snd_create_std_mono_ctl(mixer, 7, 2, 0x2, USB_MIXER_S16, 883 + "Output B Playback Volume", NULL); 884 + if (err < 0) 885 + return err; 886 + 887 + err = snd_create_std_mono_ctl(mixer, 10, 1, 0x0, USB_MIXER_INV_BOOLEAN, 888 + "Input Capture Switch", NULL); 889 + if (err < 0) 890 + return err; 891 + err = snd_create_std_mono_ctl(mixer, 10, 2, 0x1, USB_MIXER_S16, 892 + "Input A Capture Volume", NULL); 893 + if (err < 0) 894 + return err; 895 + err = snd_create_std_mono_ctl(mixer, 10, 2, 0x2, USB_MIXER_S16, 896 + "Input B Capture Volume", NULL); 897 + if (err < 0) 898 + return err; 627 899 628 900 return 0; 629 901 } ··· 1014 600 1015 601 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ 1016 602 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ 1017 - err = snd_maudio_ftu_create_mixer(mixer); 603 + err = snd_ftu_create_mixer(mixer); 1018 604 break; 1019 605 1020 606 case USB_ID(0x0b05, 0x1739): ··· 1032 618 err = snd_nativeinstruments_create_mixer(mixer, 1033 619 snd_nativeinstruments_ta10_mixers, 1034 620 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers)); 621 + break; 622 + 623 + case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */ 624 + err = snd_ebox44_create_mixer(mixer); 1035 625 break; 1036 626 } 1037 627
+376 -75
sound/usb/pcm.c
··· 16 16 17 17 #include <linux/init.h> 18 18 #include <linux/slab.h> 19 + #include <linux/ratelimit.h> 19 20 #include <linux/usb.h> 20 21 #include <linux/usb/audio.h> 21 22 #include <linux/usb/audio-v2.h> ··· 34 33 #include "pcm.h" 35 34 #include "clock.h" 36 35 #include "power.h" 36 + 37 + #define SUBSTREAM_FLAG_DATA_EP_STARTED 0 38 + #define SUBSTREAM_FLAG_SYNC_EP_STARTED 1 37 39 38 40 /* return the estimated delay based on USB frame counters */ 39 41 snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs, ··· 212 208 } 213 209 } 214 210 211 + static int start_endpoints(struct snd_usb_substream *subs) 212 + { 213 + int err; 214 + 215 + if (!subs->data_endpoint) 216 + return -EINVAL; 217 + 218 + if (!test_and_set_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags)) { 219 + struct snd_usb_endpoint *ep = subs->data_endpoint; 220 + 221 + snd_printdd(KERN_DEBUG "Starting data EP @%p\n", ep); 222 + 223 + ep->data_subs = subs; 224 + err = snd_usb_endpoint_start(ep); 225 + if (err < 0) { 226 + clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags); 227 + return err; 228 + } 229 + } 230 + 231 + if (subs->sync_endpoint && 232 + !test_and_set_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags)) { 233 + struct snd_usb_endpoint *ep = subs->sync_endpoint; 234 + 235 + snd_printdd(KERN_DEBUG "Starting sync EP @%p\n", ep); 236 + 237 + ep->sync_slave = subs->data_endpoint; 238 + err = snd_usb_endpoint_start(ep); 239 + if (err < 0) { 240 + clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags); 241 + return err; 242 + } 243 + } 244 + 245 + return 0; 246 + } 247 + 248 + static void stop_endpoints(struct snd_usb_substream *subs, 249 + int force, int can_sleep, int wait) 250 + { 251 + if (test_and_clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags)) 252 + snd_usb_endpoint_stop(subs->sync_endpoint, 253 + force, can_sleep, wait); 254 + 255 + if (test_and_clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags)) 256 + snd_usb_endpoint_stop(subs->data_endpoint, 257 + force, can_sleep, wait); 258 + } 259 + 260 + static int activate_endpoints(struct snd_usb_substream *subs) 261 + { 262 + if (subs->sync_endpoint) { 263 + int ret; 264 + 265 + ret = snd_usb_endpoint_activate(subs->sync_endpoint); 266 + if (ret < 0) 267 + return ret; 268 + } 269 + 270 + return snd_usb_endpoint_activate(subs->data_endpoint); 271 + } 272 + 273 + static int deactivate_endpoints(struct snd_usb_substream *subs) 274 + { 275 + int reta, retb; 276 + 277 + reta = snd_usb_endpoint_deactivate(subs->sync_endpoint); 278 + retb = snd_usb_endpoint_deactivate(subs->data_endpoint); 279 + 280 + if (reta < 0) 281 + return reta; 282 + 283 + if (retb < 0) 284 + return retb; 285 + 286 + return 0; 287 + } 288 + 215 289 /* 216 290 * find a matching format and set up the interface 217 291 */ ··· 301 219 struct usb_interface *iface; 302 220 unsigned int ep, attr; 303 221 int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK; 304 - int err; 222 + int err, implicit_fb = 0; 305 223 306 224 iface = usb_ifnum_to_if(dev, fmt->iface); 307 225 if (WARN_ON(!iface)) ··· 314 232 if (fmt == subs->cur_audiofmt) 315 233 return 0; 316 234 317 - /* close the old interface */ 318 - if (subs->interface >= 0 && subs->interface != fmt->iface) { 319 - if (usb_set_interface(subs->dev, subs->interface, 0) < 0) { 320 - snd_printk(KERN_ERR "%d:%d:%d: return to setting 0 failed\n", 321 - dev->devnum, fmt->iface, fmt->altsetting); 322 - return -EIO; 323 - } 324 - subs->interface = -1; 325 - subs->altset_idx = 0; 326 - } 327 - 328 - /* set interface */ 329 - if (subs->interface != fmt->iface || subs->altset_idx != fmt->altset_idx) { 330 - if (usb_set_interface(dev, fmt->iface, fmt->altsetting) < 0) { 331 - snd_printk(KERN_ERR "%d:%d:%d: usb_set_interface failed\n", 332 - dev->devnum, fmt->iface, fmt->altsetting); 333 - return -EIO; 334 - } 335 - snd_printdd(KERN_INFO "setting usb interface %d:%d\n", fmt->iface, fmt->altsetting); 336 - subs->interface = fmt->iface; 337 - subs->altset_idx = fmt->altset_idx; 338 - } 339 - 340 - /* create a data pipe */ 341 - ep = fmt->endpoint & USB_ENDPOINT_NUMBER_MASK; 342 - if (is_playback) 343 - subs->datapipe = usb_sndisocpipe(dev, ep); 344 - else 345 - subs->datapipe = usb_rcvisocpipe(dev, ep); 346 - subs->datainterval = fmt->datainterval; 347 - subs->syncpipe = subs->syncinterval = 0; 348 - subs->maxpacksize = fmt->maxpacksize; 349 - subs->syncmaxsize = 0; 350 - subs->fill_max = 0; 235 + subs->data_endpoint = snd_usb_add_endpoint(subs->stream->chip, 236 + alts, fmt->endpoint, subs->direction, 237 + SND_USB_ENDPOINT_TYPE_DATA); 238 + if (!subs->data_endpoint) 239 + return -EINVAL; 351 240 352 241 /* we need a sync pipe in async OUT or adaptive IN mode */ 353 242 /* check the number of EP, since some devices have broken ··· 326 273 * assume it as adaptive-out or sync-in. 327 274 */ 328 275 attr = fmt->ep_attr & USB_ENDPOINT_SYNCTYPE; 276 + 277 + switch (subs->stream->chip->usb_id) { 278 + case USB_ID(0x0763, 0x2080): /* M-Audio FastTrack Ultra */ 279 + case USB_ID(0x0763, 0x2081): 280 + if (is_playback) { 281 + implicit_fb = 1; 282 + ep = 0x81; 283 + iface = usb_ifnum_to_if(dev, 2); 284 + 285 + if (!iface || iface->num_altsetting == 0) 286 + return -EINVAL; 287 + 288 + alts = &iface->altsetting[1]; 289 + goto add_sync_ep; 290 + } 291 + } 292 + 329 293 if (((is_playback && attr == USB_ENDPOINT_SYNC_ASYNC) || 330 - (! is_playback && attr == USB_ENDPOINT_SYNC_ADAPTIVE)) && 294 + (!is_playback && attr == USB_ENDPOINT_SYNC_ADAPTIVE)) && 331 295 altsd->bNumEndpoints >= 2) { 332 296 /* check sync-pipe endpoint */ 333 297 /* ... and check descriptor size before accessing bSynchAddress ··· 352 282 the audio fields in the endpoint descriptors */ 353 283 if ((get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != 0x01 || 354 284 (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && 355 - get_endpoint(alts, 1)->bSynchAddress != 0)) { 285 + get_endpoint(alts, 1)->bSynchAddress != 0 && 286 + !implicit_fb)) { 356 287 snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n", 357 288 dev->devnum, fmt->iface, fmt->altsetting); 358 289 return -EINVAL; ··· 361 290 ep = get_endpoint(alts, 1)->bEndpointAddress; 362 291 if (get_endpoint(alts, 0)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && 363 292 (( is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress | USB_DIR_IN)) || 364 - (!is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress & ~USB_DIR_IN)))) { 293 + (!is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress & ~USB_DIR_IN)) || 294 + ( is_playback && !implicit_fb))) { 365 295 snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n", 366 296 dev->devnum, fmt->iface, fmt->altsetting); 367 297 return -EINVAL; 368 298 } 369 - ep &= USB_ENDPOINT_NUMBER_MASK; 370 - if (is_playback) 371 - subs->syncpipe = usb_rcvisocpipe(dev, ep); 372 - else 373 - subs->syncpipe = usb_sndisocpipe(dev, ep); 374 - if (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && 375 - get_endpoint(alts, 1)->bRefresh >= 1 && 376 - get_endpoint(alts, 1)->bRefresh <= 9) 377 - subs->syncinterval = get_endpoint(alts, 1)->bRefresh; 378 - else if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) 379 - subs->syncinterval = 1; 380 - else if (get_endpoint(alts, 1)->bInterval >= 1 && 381 - get_endpoint(alts, 1)->bInterval <= 16) 382 - subs->syncinterval = get_endpoint(alts, 1)->bInterval - 1; 383 - else 384 - subs->syncinterval = 3; 385 - subs->syncmaxsize = le16_to_cpu(get_endpoint(alts, 1)->wMaxPacketSize); 386 - } 387 299 388 - /* always fill max packet size */ 389 - if (fmt->attributes & UAC_EP_CS_ATTR_FILL_MAX) 390 - subs->fill_max = 1; 300 + implicit_fb = (get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_USAGE_MASK) 301 + == USB_ENDPOINT_USAGE_IMPLICIT_FB; 302 + 303 + add_sync_ep: 304 + subs->sync_endpoint = snd_usb_add_endpoint(subs->stream->chip, 305 + alts, ep, !subs->direction, 306 + implicit_fb ? 307 + SND_USB_ENDPOINT_TYPE_DATA : 308 + SND_USB_ENDPOINT_TYPE_SYNC); 309 + if (!subs->sync_endpoint) 310 + return -EINVAL; 311 + 312 + subs->data_endpoint->sync_master = subs->sync_endpoint; 313 + } 391 314 392 315 if ((err = snd_usb_init_pitch(subs->stream->chip, subs->interface, alts, fmt)) < 0) 393 316 return err; ··· 455 390 if (changed) { 456 391 mutex_lock(&subs->stream->chip->shutdown_mutex); 457 392 /* format changed */ 458 - snd_usb_release_substream_urbs(subs, 0); 459 - /* influenced: period_bytes, channels, rate, format, */ 460 - ret = snd_usb_init_substream_urbs(subs, params_period_bytes(hw_params), 461 - params_rate(hw_params), 462 - snd_pcm_format_physical_width(params_format(hw_params)) * 463 - params_channels(hw_params)); 393 + stop_endpoints(subs, 0, 0, 0); 394 + deactivate_endpoints(subs); 395 + 396 + ret = activate_endpoints(subs); 397 + if (ret < 0) 398 + goto unlock; 399 + 400 + ret = snd_usb_endpoint_set_params(subs->data_endpoint, hw_params, fmt, 401 + subs->sync_endpoint); 402 + if (ret < 0) 403 + goto unlock; 404 + 405 + if (subs->sync_endpoint) 406 + ret = snd_usb_endpoint_set_params(subs->sync_endpoint, 407 + hw_params, fmt, NULL); 408 + unlock: 464 409 mutex_unlock(&subs->stream->chip->shutdown_mutex); 410 + } 411 + 412 + if (ret == 0) { 413 + subs->interface = fmt->iface; 414 + subs->altset_idx = fmt->altset_idx; 465 415 } 466 416 467 417 return ret; ··· 495 415 subs->cur_rate = 0; 496 416 subs->period_bytes = 0; 497 417 mutex_lock(&subs->stream->chip->shutdown_mutex); 498 - snd_usb_release_substream_urbs(subs, 0); 418 + stop_endpoints(subs, 0, 1, 1); 499 419 mutex_unlock(&subs->stream->chip->shutdown_mutex); 500 420 return snd_pcm_lib_free_vmalloc_buffer(substream); 501 421 } ··· 515 435 return -ENXIO; 516 436 } 517 437 438 + if (snd_BUG_ON(!subs->data_endpoint)) 439 + return -EIO; 440 + 518 441 /* some unit conversions in runtime */ 519 - subs->maxframesize = bytes_to_frames(runtime, subs->maxpacksize); 520 - subs->curframesize = bytes_to_frames(runtime, subs->curpacksize); 442 + subs->data_endpoint->maxframesize = 443 + bytes_to_frames(runtime, subs->data_endpoint->maxpacksize); 444 + subs->data_endpoint->curframesize = 445 + bytes_to_frames(runtime, subs->data_endpoint->curpacksize); 521 446 522 447 /* reset the pointer */ 523 448 subs->hwptr_done = 0; 524 449 subs->transfer_done = 0; 525 - subs->phase = 0; 526 450 subs->last_delay = 0; 527 451 subs->last_frame_number = 0; 528 452 runtime->delay = 0; 529 453 530 - return snd_usb_substream_prepare(subs, runtime); 454 + /* for playback, submit the URBs now; otherwise, the first hwptr_done 455 + * updates for all URBs would happen at the same time when starting */ 456 + if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) 457 + return start_endpoints(subs); 458 + 459 + return 0; 531 460 } 532 461 533 462 static struct snd_pcm_hardware snd_usb_hardware = ··· 931 842 932 843 static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction) 933 844 { 845 + int ret; 934 846 struct snd_usb_stream *as = snd_pcm_substream_chip(substream); 935 847 struct snd_usb_substream *subs = &as->substream[direction]; 936 848 937 - if (!as->chip->shutdown && subs->interface >= 0) { 938 - usb_set_interface(subs->dev, subs->interface, 0); 939 - subs->interface = -1; 940 - } 849 + stop_endpoints(subs, 0, 0, 0); 850 + ret = deactivate_endpoints(subs); 941 851 subs->pcm_substream = NULL; 942 852 snd_usb_autosuspend(subs->stream->chip); 943 - return 0; 853 + 854 + return ret; 855 + } 856 + 857 + /* Since a URB can handle only a single linear buffer, we must use double 858 + * buffering when the data to be transferred overflows the buffer boundary. 859 + * To avoid inconsistencies when updating hwptr_done, we use double buffering 860 + * for all URBs. 861 + */ 862 + static void retire_capture_urb(struct snd_usb_substream *subs, 863 + struct urb *urb) 864 + { 865 + struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; 866 + unsigned int stride, frames, bytes, oldptr; 867 + int i, period_elapsed = 0; 868 + unsigned long flags; 869 + unsigned char *cp; 870 + 871 + stride = runtime->frame_bits >> 3; 872 + 873 + for (i = 0; i < urb->number_of_packets; i++) { 874 + cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset; 875 + if (urb->iso_frame_desc[i].status && printk_ratelimit()) { 876 + snd_printdd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status); 877 + // continue; 878 + } 879 + bytes = urb->iso_frame_desc[i].actual_length; 880 + frames = bytes / stride; 881 + if (!subs->txfr_quirk) 882 + bytes = frames * stride; 883 + if (bytes % (runtime->sample_bits >> 3) != 0) { 884 + #ifdef CONFIG_SND_DEBUG_VERBOSE 885 + int oldbytes = bytes; 886 + #endif 887 + bytes = frames * stride; 888 + snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n", 889 + oldbytes, bytes); 890 + } 891 + /* update the current pointer */ 892 + spin_lock_irqsave(&subs->lock, flags); 893 + oldptr = subs->hwptr_done; 894 + subs->hwptr_done += bytes; 895 + if (subs->hwptr_done >= runtime->buffer_size * stride) 896 + subs->hwptr_done -= runtime->buffer_size * stride; 897 + frames = (bytes + (oldptr % stride)) / stride; 898 + subs->transfer_done += frames; 899 + if (subs->transfer_done >= runtime->period_size) { 900 + subs->transfer_done -= runtime->period_size; 901 + period_elapsed = 1; 902 + } 903 + spin_unlock_irqrestore(&subs->lock, flags); 904 + /* copy a data chunk */ 905 + if (oldptr + bytes > runtime->buffer_size * stride) { 906 + unsigned int bytes1 = 907 + runtime->buffer_size * stride - oldptr; 908 + memcpy(runtime->dma_area + oldptr, cp, bytes1); 909 + memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1); 910 + } else { 911 + memcpy(runtime->dma_area + oldptr, cp, bytes); 912 + } 913 + } 914 + 915 + if (period_elapsed) 916 + snd_pcm_period_elapsed(subs->pcm_substream); 917 + } 918 + 919 + static void prepare_playback_urb(struct snd_usb_substream *subs, 920 + struct urb *urb) 921 + { 922 + struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; 923 + struct snd_urb_ctx *ctx = urb->context; 924 + unsigned int counts, frames, bytes; 925 + int i, stride, period_elapsed = 0; 926 + unsigned long flags; 927 + 928 + stride = runtime->frame_bits >> 3; 929 + 930 + frames = 0; 931 + urb->number_of_packets = 0; 932 + spin_lock_irqsave(&subs->lock, flags); 933 + for (i = 0; i < ctx->packets; i++) { 934 + counts = ctx->packet_size[i]; 935 + /* set up descriptor */ 936 + urb->iso_frame_desc[i].offset = frames * stride; 937 + urb->iso_frame_desc[i].length = counts * stride; 938 + frames += counts; 939 + urb->number_of_packets++; 940 + subs->transfer_done += counts; 941 + if (subs->transfer_done >= runtime->period_size) { 942 + subs->transfer_done -= runtime->period_size; 943 + period_elapsed = 1; 944 + if (subs->fmt_type == UAC_FORMAT_TYPE_II) { 945 + if (subs->transfer_done > 0) { 946 + /* FIXME: fill-max mode is not 947 + * supported yet */ 948 + frames -= subs->transfer_done; 949 + counts -= subs->transfer_done; 950 + urb->iso_frame_desc[i].length = 951 + counts * stride; 952 + subs->transfer_done = 0; 953 + } 954 + i++; 955 + if (i < ctx->packets) { 956 + /* add a transfer delimiter */ 957 + urb->iso_frame_desc[i].offset = 958 + frames * stride; 959 + urb->iso_frame_desc[i].length = 0; 960 + urb->number_of_packets++; 961 + } 962 + break; 963 + } 964 + } 965 + if (period_elapsed && 966 + !snd_usb_endpoint_implict_feedback_sink(subs->data_endpoint)) /* finish at the period boundary */ 967 + break; 968 + } 969 + bytes = frames * stride; 970 + if (subs->hwptr_done + bytes > runtime->buffer_size * stride) { 971 + /* err, the transferred area goes over buffer boundary. */ 972 + unsigned int bytes1 = 973 + runtime->buffer_size * stride - subs->hwptr_done; 974 + memcpy(urb->transfer_buffer, 975 + runtime->dma_area + subs->hwptr_done, bytes1); 976 + memcpy(urb->transfer_buffer + bytes1, 977 + runtime->dma_area, bytes - bytes1); 978 + } else { 979 + memcpy(urb->transfer_buffer, 980 + runtime->dma_area + subs->hwptr_done, bytes); 981 + } 982 + subs->hwptr_done += bytes; 983 + if (subs->hwptr_done >= runtime->buffer_size * stride) 984 + subs->hwptr_done -= runtime->buffer_size * stride; 985 + runtime->delay += frames; 986 + spin_unlock_irqrestore(&subs->lock, flags); 987 + urb->transfer_buffer_length = bytes; 988 + if (period_elapsed) 989 + snd_pcm_period_elapsed(subs->pcm_substream); 990 + } 991 + 992 + /* 993 + * process after playback data complete 994 + * - decrease the delay count again 995 + */ 996 + static void retire_playback_urb(struct snd_usb_substream *subs, 997 + struct urb *urb) 998 + { 999 + unsigned long flags; 1000 + struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; 1001 + int stride = runtime->frame_bits >> 3; 1002 + int processed = urb->transfer_buffer_length / stride; 1003 + 1004 + spin_lock_irqsave(&subs->lock, flags); 1005 + if (processed > runtime->delay) 1006 + runtime->delay = 0; 1007 + else 1008 + runtime->delay -= processed; 1009 + spin_unlock_irqrestore(&subs->lock, flags); 944 1010 } 945 1011 946 1012 static int snd_usb_playback_open(struct snd_pcm_substream *substream) ··· 1116 872 static int snd_usb_capture_close(struct snd_pcm_substream *substream) 1117 873 { 1118 874 return snd_usb_pcm_close(substream, SNDRV_PCM_STREAM_CAPTURE); 875 + } 876 + 877 + static int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, 878 + int cmd) 879 + { 880 + struct snd_usb_substream *subs = substream->runtime->private_data; 881 + 882 + switch (cmd) { 883 + case SNDRV_PCM_TRIGGER_START: 884 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 885 + subs->data_endpoint->prepare_data_urb = prepare_playback_urb; 886 + subs->data_endpoint->retire_data_urb = retire_playback_urb; 887 + subs->running = 1; 888 + return 0; 889 + case SNDRV_PCM_TRIGGER_STOP: 890 + stop_endpoints(subs, 0, 0, 0); 891 + subs->running = 0; 892 + return 0; 893 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 894 + subs->data_endpoint->prepare_data_urb = NULL; 895 + subs->data_endpoint->retire_data_urb = NULL; 896 + subs->running = 0; 897 + return 0; 898 + } 899 + 900 + return -EINVAL; 901 + } 902 + 903 + int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd) 904 + { 905 + int err; 906 + struct snd_usb_substream *subs = substream->runtime->private_data; 907 + 908 + switch (cmd) { 909 + case SNDRV_PCM_TRIGGER_START: 910 + err = start_endpoints(subs); 911 + if (err < 0) 912 + return err; 913 + 914 + subs->data_endpoint->retire_data_urb = retire_capture_urb; 915 + subs->running = 1; 916 + return 0; 917 + case SNDRV_PCM_TRIGGER_STOP: 918 + stop_endpoints(subs, 0, 0, 0); 919 + subs->running = 0; 920 + return 0; 921 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 922 + subs->data_endpoint->retire_data_urb = NULL; 923 + subs->running = 0; 924 + return 0; 925 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 926 + subs->data_endpoint->retire_data_urb = retire_capture_urb; 927 + subs->running = 1; 928 + return 0; 929 + } 930 + 931 + return -EINVAL; 1119 932 } 1120 933 1121 934 static struct snd_pcm_ops snd_usb_playback_ops = {
+22 -16
sound/usb/proc.c
··· 25 25 #include "usbaudio.h" 26 26 #include "helper.h" 27 27 #include "card.h" 28 + #include "endpoint.h" 28 29 #include "proc.h" 29 30 30 31 /* convert our full speed USB rate into sampling rate in Hz */ ··· 116 115 } 117 116 } 118 117 118 + static void proc_dump_ep_status(struct snd_usb_substream *subs, 119 + struct snd_usb_endpoint *ep, 120 + struct snd_info_buffer *buffer) 121 + { 122 + if (!ep) 123 + return; 124 + snd_iprintf(buffer, " Packet Size = %d\n", ep->curpacksize); 125 + snd_iprintf(buffer, " Momentary freq = %u Hz (%#x.%04x)\n", 126 + snd_usb_get_speed(subs->dev) == USB_SPEED_FULL 127 + ? get_full_speed_hz(ep->freqm) 128 + : get_high_speed_hz(ep->freqm), 129 + ep->freqm >> 16, ep->freqm & 0xffff); 130 + if (ep->freqshift != INT_MIN) { 131 + int res = 16 - ep->freqshift; 132 + snd_iprintf(buffer, " Feedback Format = %d.%d\n", 133 + (ep->syncmaxsize > 3 ? 32 : 24) - res, res); 134 + } 135 + } 136 + 119 137 static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer) 120 138 { 121 139 if (subs->running) { 122 - unsigned int i; 123 140 snd_iprintf(buffer, " Status: Running\n"); 124 141 snd_iprintf(buffer, " Interface = %d\n", subs->interface); 125 142 snd_iprintf(buffer, " Altset = %d\n", subs->altset_idx); 126 - snd_iprintf(buffer, " URBs = %d [ ", subs->nurbs); 127 - for (i = 0; i < subs->nurbs; i++) 128 - snd_iprintf(buffer, "%d ", subs->dataurb[i].packets); 129 - snd_iprintf(buffer, "]\n"); 130 - snd_iprintf(buffer, " Packet Size = %d\n", subs->curpacksize); 131 - snd_iprintf(buffer, " Momentary freq = %u Hz (%#x.%04x)\n", 132 - snd_usb_get_speed(subs->dev) == USB_SPEED_FULL 133 - ? get_full_speed_hz(subs->freqm) 134 - : get_high_speed_hz(subs->freqm), 135 - subs->freqm >> 16, subs->freqm & 0xffff); 136 - if (subs->freqshift != INT_MIN) 137 - snd_iprintf(buffer, " Feedback Format = %d.%d\n", 138 - (subs->syncmaxsize > 3 ? 32 : 24) 139 - - (16 - subs->freqshift), 140 - 16 - subs->freqshift); 143 + proc_dump_ep_status(subs, subs->data_endpoint, buffer); 144 + proc_dump_ep_status(subs, subs->sync_endpoint, buffer); 141 145 } else { 142 146 snd_iprintf(buffer, " Status: Stop\n"); 143 147 }
+28 -3
sound/usb/stream.c
··· 73 73 } 74 74 } 75 75 76 + /* 77 + * initialize the substream instance. 78 + */ 79 + 80 + static void snd_usb_init_substream(struct snd_usb_stream *as, 81 + int stream, 82 + struct audioformat *fp) 83 + { 84 + struct snd_usb_substream *subs = &as->substream[stream]; 85 + 86 + INIT_LIST_HEAD(&subs->fmt_list); 87 + spin_lock_init(&subs->lock); 88 + 89 + subs->stream = as; 90 + subs->direction = stream; 91 + subs->dev = as->chip->dev; 92 + subs->txfr_quirk = as->chip->txfr_quirk; 93 + 94 + snd_usb_set_pcm_ops(as->pcm, stream); 95 + 96 + list_add_tail(&fp->list, &subs->fmt_list); 97 + subs->formats |= fp->formats; 98 + subs->num_formats++; 99 + subs->fmt_type = fp->fmt_type; 100 + } 76 101 77 102 /* 78 103 * add this endpoint to the chip instance. ··· 119 94 if (as->fmt_type != fp->fmt_type) 120 95 continue; 121 96 subs = &as->substream[stream]; 122 - if (!subs->endpoint) 97 + if (!subs->data_endpoint) 123 98 continue; 124 - if (subs->endpoint == fp->endpoint) { 99 + if (subs->data_endpoint->ep_num == fp->endpoint) { 125 100 list_add_tail(&fp->list, &subs->fmt_list); 126 101 subs->num_formats++; 127 102 subs->formats |= fp->formats; ··· 134 109 if (as->fmt_type != fp->fmt_type) 135 110 continue; 136 111 subs = &as->substream[stream]; 137 - if (subs->endpoint) 112 + if (subs->data_endpoint) 138 113 continue; 139 114 err = snd_pcm_new_stream(as->pcm, stream, 1); 140 115 if (err < 0)
+2
sound/usb/usbaudio.h
··· 36 36 struct snd_card *card; 37 37 struct usb_interface *pm_intf; 38 38 u32 usb_id; 39 + struct mutex mutex; 39 40 struct mutex shutdown_mutex; 40 41 unsigned int shutdown:1; 41 42 unsigned int probing:1; ··· 47 46 int num_suspended_intf; 48 47 49 48 struct list_head pcm_list; /* list of pcm streams */ 49 + struct list_head ep_list; /* list of audio-related endpoints */ 50 50 int pcm_devs; 51 51 52 52 struct list_head midi_list; /* list of midi interfaces */