aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2012-05-21 06:51:35 -0400
committerTakashi Iwai <tiwai@suse.de>2012-05-21 06:51:35 -0400
commit382e6a859e6622de0aa62c01976ae8ebd90e986d (patch)
tree2501c554c231c5d0fcda7ff2e6e055bf23134d6f /sound
parent6de15b2a9330aeb5df9b66545f67c6c6ad2c045a (diff)
parent97f8d3b6503082416898f893a442a78f8819c42a (diff)
Merge branch 'topic/misc' into for-linus
Diffstat (limited to 'sound')
-rw-r--r--sound/atmel/ac97c.c2
-rw-r--r--sound/core/jack.c5
-rw-r--r--sound/core/pcm_lib.c18
-rw-r--r--sound/core/pcm_native.c12
-rw-r--r--sound/core/sound_oss.c6
-rw-r--r--sound/drivers/aloop.c62
-rw-r--r--sound/firewire/amdtp.c49
-rw-r--r--sound/firewire/amdtp.h29
-rw-r--r--sound/pci/Kconfig2
-rw-r--r--sound/pci/ad1889.c15
-rw-r--r--sound/pci/ali5451/ali5451.c15
-rw-r--r--sound/pci/als300.c15
-rw-r--r--sound/pci/als4000.c15
-rw-r--r--sound/pci/atiixp.c16
-rw-r--r--sound/pci/atiixp_modem.c16
-rw-r--r--sound/pci/au88x0/au88x0.c17
-rw-r--r--sound/pci/aw2/aw2-alsa.c23
-rw-r--r--sound/pci/azt3328.c23
-rw-r--r--sound/pci/bt87x.c19
-rw-r--r--sound/pci/ca0106/ca0106_main.c17
-rw-r--r--sound/pci/cmipci.c15
-rw-r--r--sound/pci/cs4281.c15
-rw-r--r--sound/pci/cs46xx/cs46xx.c15
-rw-r--r--sound/pci/cs5530.c16
-rw-r--r--sound/pci/cs5535audio/cs5535audio.c15
-rw-r--r--sound/pci/ctxfi/xfi.c13
-rw-r--r--sound/pci/echoaudio/echoaudio.c22
-rw-r--r--sound/pci/emu10k1/emu10k1.c15
-rw-r--r--sound/pci/emu10k1/emu10k1x.c17
-rw-r--r--sound/pci/ens1370.c15
-rw-r--r--sound/pci/es1938.c15
-rw-r--r--sound/pci/es1968.c15
-rw-r--r--sound/pci/fm801.c15
-rw-r--r--sound/pci/hda/hda_intel.c17
-rw-r--r--sound/pci/ice1712/ice1712.c15
-rw-r--r--sound/pci/ice1712/ice1724.c15
-rw-r--r--sound/pci/intel8x0.c16
-rw-r--r--sound/pci/intel8x0m.c16
-rw-r--r--sound/pci/korg1212/korg1212.c15
-rw-r--r--sound/pci/lola/lola.c15
-rw-r--r--sound/pci/lx6464es/lx6464es.c17
-rw-r--r--sound/pci/maestro3.c15
-rw-r--r--sound/pci/mixart/mixart.c15
-rw-r--r--sound/pci/nm256/nm256.c16
-rw-r--r--sound/pci/oxygen/oxygen.c21
-rw-r--r--sound/pci/oxygen/virtuoso.c13
-rw-r--r--sound/pci/oxygen/xonar_dg.c7
-rw-r--r--sound/pci/pcxhr/pcxhr.c15
-rw-r--r--sound/pci/riptide/riptide.c3
-rw-r--r--sound/pci/rme32.c15
-rw-r--r--sound/pci/rme96.c15
-rw-r--r--sound/pci/rme9652/hdsp.c15
-rw-r--r--sound/pci/rme9652/hdspm.c16
-rw-r--r--sound/pci/rme9652/rme9652.c15
-rw-r--r--sound/pci/sis7019.c13
-rw-r--r--sound/pci/sonicvibes.c15
-rw-r--r--sound/pci/trident/trident.c15
-rw-r--r--sound/pci/via82xx.c15
-rw-r--r--sound/pci/via82xx_modem.c15
-rw-r--r--sound/pci/vx222/vx222.c15
-rw-r--r--sound/pci/ymfpci/ymfpci.c15
-rw-r--r--sound/sh/sh_dac_audio.c4
-rw-r--r--sound/sound_core.c2
-rw-r--r--sound/usb/card.c10
-rw-r--r--sound/usb/card.h86
-rw-r--r--sound/usb/endpoint.c1609
-rw-r--r--sound/usb/endpoint.h32
-rw-r--r--sound/usb/mixer.c50
-rw-r--r--sound/usb/mixer.h3
-rw-r--r--sound/usb/mixer_maps.c13
-rw-r--r--sound/usb/mixer_quirks.c472
-rw-r--r--sound/usb/pcm.c453
-rw-r--r--sound/usb/proc.c38
-rw-r--r--sound/usb/stream.c31
-rw-r--r--sound/usb/usbaudio.h2
75 files changed, 2148 insertions, 1646 deletions
diff --git a/sound/atmel/ac97c.c b/sound/atmel/ac97c.c
index 115313ef54d6..f5ded640b395 100644
--- a/sound/atmel/ac97c.c
+++ b/sound/atmel/ac97c.c
@@ -991,6 +991,8 @@ static int __devinit atmel_ac97c_probe(struct platform_device *pdev)
991 gpio_direction_output(pdata->reset_pin, 1); 991 gpio_direction_output(pdata->reset_pin, 1);
992 chip->reset_pin = pdata->reset_pin; 992 chip->reset_pin = pdata->reset_pin;
993 } 993 }
994 } else {
995 chip->reset_pin = -EINVAL;
994 } 996 }
995 997
996 snd_card_set_dev(card, &pdev->dev); 998 snd_card_set_dev(card, &pdev->dev);
diff --git a/sound/core/jack.c b/sound/core/jack.c
index 471e1e3b0a99..a06b1651fcba 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -155,7 +155,7 @@ EXPORT_SYMBOL(snd_jack_new);
155 * @jack: The jack to configure 155 * @jack: The jack to configure
156 * @parent: The device to set as parent for the jack. 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 * function is only valid prior to registration of the jack. If no 159 * function is only valid prior to registration of the jack. If no
160 * parent is configured then the parent device will be the sound card. 160 * parent is configured then the parent device will be the sound card.
161 */ 161 */
@@ -179,6 +179,9 @@ EXPORT_SYMBOL(snd_jack_set_parent);
179 * mapping is provided but keys are enabled in the jack type then 179 * mapping is provided but keys are enabled in the jack type then
180 * BTN_n numeric buttons will be reported. 180 * BTN_n numeric buttons will be reported.
181 * 181 *
182 * If jacks are not reporting via the input API this call will have no
183 * effect.
184 *
182 * Note that this is intended to be use by simple devices with small 185 * Note that this is intended to be use by simple devices with small
183 * numbers of keys that can be reported. It is also possible to 186 * numbers of keys that can be reported. It is also possible to
184 * access the input device directly - devices with complex input 187 * access the input device directly - devices with complex input
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 4d18941178e6..faedb1481b24 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -1894,6 +1894,7 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
1894 struct snd_pcm_runtime *runtime = substream->runtime; 1894 struct snd_pcm_runtime *runtime = substream->runtime;
1895 snd_pcm_uframes_t xfer = 0; 1895 snd_pcm_uframes_t xfer = 0;
1896 snd_pcm_uframes_t offset = 0; 1896 snd_pcm_uframes_t offset = 0;
1897 snd_pcm_uframes_t avail;
1897 int err = 0; 1898 int err = 0;
1898 1899
1899 if (size == 0) 1900 if (size == 0)
@@ -1917,13 +1918,12 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
1917 } 1918 }
1918 1919
1919 runtime->twake = runtime->control->avail_min ? : 1; 1920 runtime->twake = runtime->control->avail_min ? : 1;
1921 if (runtime->status->state == SNDRV_PCM_STATE_RUNNING)
1922 snd_pcm_update_hw_ptr(substream);
1923 avail = snd_pcm_playback_avail(runtime);
1920 while (size > 0) { 1924 while (size > 0) {
1921 snd_pcm_uframes_t frames, appl_ptr, appl_ofs; 1925 snd_pcm_uframes_t frames, appl_ptr, appl_ofs;
1922 snd_pcm_uframes_t avail;
1923 snd_pcm_uframes_t cont; 1926 snd_pcm_uframes_t cont;
1924 if (runtime->status->state == SNDRV_PCM_STATE_RUNNING)
1925 snd_pcm_update_hw_ptr(substream);
1926 avail = snd_pcm_playback_avail(runtime);
1927 if (!avail) { 1927 if (!avail) {
1928 if (nonblock) { 1928 if (nonblock) {
1929 err = -EAGAIN; 1929 err = -EAGAIN;
@@ -1971,6 +1971,7 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
1971 offset += frames; 1971 offset += frames;
1972 size -= frames; 1972 size -= frames;
1973 xfer += frames; 1973 xfer += frames;
1974 avail -= frames;
1974 if (runtime->status->state == SNDRV_PCM_STATE_PREPARED && 1975 if (runtime->status->state == SNDRV_PCM_STATE_PREPARED &&
1975 snd_pcm_playback_hw_avail(runtime) >= (snd_pcm_sframes_t)runtime->start_threshold) { 1976 snd_pcm_playback_hw_avail(runtime) >= (snd_pcm_sframes_t)runtime->start_threshold) {
1976 err = snd_pcm_start(substream); 1977 err = snd_pcm_start(substream);
@@ -2111,6 +2112,7 @@ static snd_pcm_sframes_t snd_pcm_lib_read1(struct snd_pcm_substream *substream,
2111 struct snd_pcm_runtime *runtime = substream->runtime; 2112 struct snd_pcm_runtime *runtime = substream->runtime;
2112 snd_pcm_uframes_t xfer = 0; 2113 snd_pcm_uframes_t xfer = 0;
2113 snd_pcm_uframes_t offset = 0; 2114 snd_pcm_uframes_t offset = 0;
2115 snd_pcm_uframes_t avail;
2114 int err = 0; 2116 int err = 0;
2115 2117
2116 if (size == 0) 2118 if (size == 0)
@@ -2141,13 +2143,12 @@ static snd_pcm_sframes_t snd_pcm_lib_read1(struct snd_pcm_substream *substream,
2141 } 2143 }
2142 2144
2143 runtime->twake = runtime->control->avail_min ? : 1; 2145 runtime->twake = runtime->control->avail_min ? : 1;
2146 if (runtime->status->state == SNDRV_PCM_STATE_RUNNING)
2147 snd_pcm_update_hw_ptr(substream);
2148 avail = snd_pcm_capture_avail(runtime);
2144 while (size > 0) { 2149 while (size > 0) {
2145 snd_pcm_uframes_t frames, appl_ptr, appl_ofs; 2150 snd_pcm_uframes_t frames, appl_ptr, appl_ofs;
2146 snd_pcm_uframes_t avail;
2147 snd_pcm_uframes_t cont; 2151 snd_pcm_uframes_t cont;
2148 if (runtime->status->state == SNDRV_PCM_STATE_RUNNING)
2149 snd_pcm_update_hw_ptr(substream);
2150 avail = snd_pcm_capture_avail(runtime);
2151 if (!avail) { 2152 if (!avail) {
2152 if (runtime->status->state == 2153 if (runtime->status->state ==
2153 SNDRV_PCM_STATE_DRAINING) { 2154 SNDRV_PCM_STATE_DRAINING) {
@@ -2202,6 +2203,7 @@ static snd_pcm_sframes_t snd_pcm_lib_read1(struct snd_pcm_substream *substream,
2202 offset += frames; 2203 offset += frames;
2203 size -= frames; 2204 size -= frames;
2204 xfer += frames; 2205 xfer += frames;
2206 avail -= frames;
2205 } 2207 }
2206 _end_unlock: 2208 _end_unlock:
2207 runtime->twake = 0; 2209 runtime->twake = 0;
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 3fe99e644eb8..53b5ada8f7c3 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -1360,7 +1360,14 @@ static int snd_pcm_prepare(struct snd_pcm_substream *substream,
1360 1360
1361static int snd_pcm_pre_drain_init(struct snd_pcm_substream *substream, int state) 1361static 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 return 0; 1371 return 0;
1365} 1372}
1366 1373
@@ -1379,6 +1386,9 @@ static int snd_pcm_do_drain_init(struct snd_pcm_substream *substream, int state)
1379 case SNDRV_PCM_STATE_RUNNING: 1386 case SNDRV_PCM_STATE_RUNNING:
1380 runtime->status->state = SNDRV_PCM_STATE_DRAINING; 1387 runtime->status->state = SNDRV_PCM_STATE_DRAINING;
1381 break; 1388 break;
1389 case SNDRV_PCM_STATE_XRUN:
1390 runtime->status->state = SNDRV_PCM_STATE_SETUP;
1391 break;
1382 default: 1392 default:
1383 break; 1393 break;
1384 } 1394 }
diff --git a/sound/core/sound_oss.c b/sound/core/sound_oss.c
index c70092043061..e9528333e36d 100644
--- a/sound/core/sound_oss.c
+++ b/sound/core/sound_oss.c
@@ -35,7 +35,7 @@
35#include <linux/sound.h> 35#include <linux/sound.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37 37
38#define SNDRV_OSS_MINORS 128 38#define SNDRV_OSS_MINORS 256
39 39
40static struct snd_minor *snd_oss_minors[SNDRV_OSS_MINORS]; 40static struct snd_minor *snd_oss_minors[SNDRV_OSS_MINORS];
41static DEFINE_MUTEX(sound_oss_mutex); 41static DEFINE_MUTEX(sound_oss_mutex);
@@ -111,7 +111,7 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev,
111 int register1 = -1, register2 = -1; 111 int register1 = -1, register2 = -1;
112 struct device *carddev = snd_card_get_device_link(card); 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 return 0; /* ignore silently */ 115 return 0; /* ignore silently */
116 if (minor < 0) 116 if (minor < 0)
117 return minor; 117 return minor;
@@ -170,7 +170,7 @@ int snd_unregister_oss_device(int type, struct snd_card *card, int dev)
170 int track2 = -1; 170 int track2 = -1;
171 struct snd_minor *mptr; 171 struct snd_minor *mptr;
172 172
173 if (card && card->number >= 8) 173 if (card && card->number >= SNDRV_MINOR_OSS_DEVICES)
174 return 0; 174 return 0;
175 if (minor < 0) 175 if (minor < 0)
176 return minor; 176 return minor;
diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c
index ad079b63b8ba..8b5c36f4d303 100644
--- a/sound/drivers/aloop.c
+++ b/sound/drivers/aloop.c
@@ -117,6 +117,7 @@ struct loopback_pcm {
117 /* timer stuff */ 117 /* timer stuff */
118 unsigned int irq_pos; /* fractional IRQ position */ 118 unsigned int irq_pos; /* fractional IRQ position */
119 unsigned int period_size_frac; 119 unsigned int period_size_frac;
120 unsigned int last_drift;
120 unsigned long last_jiffies; 121 unsigned long last_jiffies;
121 struct timer_list timer; 122 struct timer_list timer;
122}; 123};
@@ -264,6 +265,7 @@ static int loopback_trigger(struct snd_pcm_substream *substream, int cmd)
264 return err; 265 return err;
265 dpcm->last_jiffies = jiffies; 266 dpcm->last_jiffies = jiffies;
266 dpcm->pcm_rate_shift = 0; 267 dpcm->pcm_rate_shift = 0;
268 dpcm->last_drift = 0;
267 spin_lock(&cable->lock); 269 spin_lock(&cable->lock);
268 cable->running |= stream; 270 cable->running |= stream;
269 cable->pause &= ~stream; 271 cable->pause &= ~stream;
@@ -444,34 +446,30 @@ static void copy_play_buf(struct loopback_pcm *play,
444 } 446 }
445} 447}
446 448
447#define BYTEPOS_UPDATE_POSONLY 0 449static inline unsigned int bytepos_delta(struct loopback_pcm *dpcm,
448#define BYTEPOS_UPDATE_CLEAR 1 450 unsigned int jiffies_delta)
449#define BYTEPOS_UPDATE_COPY 2
450
451static void loopback_bytepos_update(struct loopback_pcm *dpcm,
452 unsigned int delta,
453 unsigned int cmd)
454{ 451{
455 unsigned int count;
456 unsigned long last_pos; 452 unsigned long last_pos;
453 unsigned int delta;
457 454
458 last_pos = byte_pos(dpcm, dpcm->irq_pos); 455 last_pos = byte_pos(dpcm, dpcm->irq_pos);
459 dpcm->irq_pos += delta * dpcm->pcm_bps; 456 dpcm->irq_pos += jiffies_delta * dpcm->pcm_bps;
460 count = byte_pos(dpcm, dpcm->irq_pos) - last_pos; 457 delta = byte_pos(dpcm, dpcm->irq_pos) - last_pos;
461 if (!count) 458 if (delta >= dpcm->last_drift)
462 return; 459 delta -= dpcm->last_drift;
463 if (cmd == BYTEPOS_UPDATE_CLEAR) 460 dpcm->last_drift = 0;
464 clear_capture_buf(dpcm, count);
465 else if (cmd == BYTEPOS_UPDATE_COPY)
466 copy_play_buf(dpcm->cable->streams[SNDRV_PCM_STREAM_PLAYBACK],
467 dpcm->cable->streams[SNDRV_PCM_STREAM_CAPTURE],
468 count);
469 dpcm->buf_pos += count;
470 dpcm->buf_pos %= dpcm->pcm_buffer_size;
471 if (dpcm->irq_pos >= dpcm->period_size_frac) { 461 if (dpcm->irq_pos >= dpcm->period_size_frac) {
472 dpcm->irq_pos %= dpcm->period_size_frac; 462 dpcm->irq_pos %= dpcm->period_size_frac;
473 dpcm->period_update_pending = 1; 463 dpcm->period_update_pending = 1;
474 } 464 }
465 return delta;
466}
467
468static inline void bytepos_finish(struct loopback_pcm *dpcm,
469 unsigned int delta)
470{
471 dpcm->buf_pos += delta;
472 dpcm->buf_pos %= dpcm->pcm_buffer_size;
475} 473}
476 474
477static unsigned int loopback_pos_update(struct loopback_cable *cable) 475static unsigned int loopback_pos_update(struct loopback_cable *cable)
@@ -481,7 +479,7 @@ static unsigned int loopback_pos_update(struct loopback_cable *cable)
481 struct loopback_pcm *dpcm_capt = 479 struct loopback_pcm *dpcm_capt =
482 cable->streams[SNDRV_PCM_STREAM_CAPTURE]; 480 cable->streams[SNDRV_PCM_STREAM_CAPTURE];
483 unsigned long delta_play = 0, delta_capt = 0; 481 unsigned long delta_play = 0, delta_capt = 0;
484 unsigned int running; 482 unsigned int running, count1, count2;
485 unsigned long flags; 483 unsigned long flags;
486 484
487 spin_lock_irqsave(&cable->lock, flags); 485 spin_lock_irqsave(&cable->lock, flags);
@@ -500,12 +498,13 @@ static unsigned int loopback_pos_update(struct loopback_cable *cable)
500 goto unlock; 498 goto unlock;
501 499
502 if (delta_play > delta_capt) { 500 if (delta_play > delta_capt) {
503 loopback_bytepos_update(dpcm_play, delta_play - delta_capt, 501 count1 = bytepos_delta(dpcm_play, delta_play - delta_capt);
504 BYTEPOS_UPDATE_POSONLY); 502 bytepos_finish(dpcm_play, count1);
505 delta_play = delta_capt; 503 delta_play = delta_capt;
506 } else if (delta_play < delta_capt) { 504 } else if (delta_play < delta_capt) {
507 loopback_bytepos_update(dpcm_capt, delta_capt - delta_play, 505 count1 = bytepos_delta(dpcm_capt, delta_capt - delta_play);
508 BYTEPOS_UPDATE_CLEAR); 506 clear_capture_buf(dpcm_capt, count1);
507 bytepos_finish(dpcm_capt, count1);
509 delta_capt = delta_play; 508 delta_capt = delta_play;
510 } 509 }
511 510
@@ -513,8 +512,17 @@ static unsigned int loopback_pos_update(struct loopback_cable *cable)
513 goto unlock; 512 goto unlock;
514 513
515 /* note delta_capt == delta_play at this moment */ 514 /* note delta_capt == delta_play at this moment */
516 loopback_bytepos_update(dpcm_capt, delta_capt, BYTEPOS_UPDATE_COPY); 515 count1 = bytepos_delta(dpcm_play, delta_play);
517 loopback_bytepos_update(dpcm_play, delta_play, BYTEPOS_UPDATE_POSONLY); 516 count2 = bytepos_delta(dpcm_capt, delta_capt);
517 if (count1 < count2) {
518 dpcm_capt->last_drift = count2 - count1;
519 count1 = count2;
520 } else if (count1 > count2) {
521 dpcm_play->last_drift = count1 - count2;
522 }
523 copy_play_buf(dpcm_play, dpcm_capt, count1);
524 bytepos_finish(dpcm_play, count1);
525 bytepos_finish(dpcm_capt, count1);
518 unlock: 526 unlock:
519 spin_unlock_irqrestore(&cable->lock, flags); 527 spin_unlock_irqrestore(&cable->lock, flags);
520 return running; 528 return running;
diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
index 87657dd7714c..ea995af6d049 100644
--- a/sound/firewire/amdtp.c
+++ b/sound/firewire/amdtp.c
@@ -31,6 +31,8 @@
31#define INTERRUPT_INTERVAL 16 31#define INTERRUPT_INTERVAL 16
32#define QUEUE_LENGTH 48 32#define QUEUE_LENGTH 48
33 33
34static void pcm_period_tasklet(unsigned long data);
35
34/** 36/**
35 * amdtp_out_stream_init - initialize an AMDTP output stream structure 37 * amdtp_out_stream_init - initialize an AMDTP output stream structure
36 * @s: the AMDTP output stream to initialize 38 * @s: the AMDTP output stream to initialize
@@ -47,6 +49,7 @@ int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
47 s->flags = flags; 49 s->flags = flags;
48 s->context = ERR_PTR(-1); 50 s->context = ERR_PTR(-1);
49 mutex_init(&s->mutex); 51 mutex_init(&s->mutex);
52 tasklet_init(&s->period_tasklet, pcm_period_tasklet, (unsigned long)s);
50 s->packet_index = 0; 53 s->packet_index = 0;
51 54
52 return 0; 55 return 0;
@@ -164,6 +167,21 @@ void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
164} 167}
165EXPORT_SYMBOL(amdtp_out_stream_set_pcm_format); 168EXPORT_SYMBOL(amdtp_out_stream_set_pcm_format);
166 169
170/**
171 * amdtp_out_stream_pcm_prepare - prepare PCM device for running
172 * @s: the AMDTP output stream
173 *
174 * This function should be called from the PCM device's .prepare callback.
175 */
176void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
177{
178 tasklet_kill(&s->period_tasklet);
179 s->pcm_buffer_pointer = 0;
180 s->pcm_period_pointer = 0;
181 s->pointer_flush = true;
182}
183EXPORT_SYMBOL(amdtp_out_stream_pcm_prepare);
184
167static unsigned int calculate_data_blocks(struct amdtp_out_stream *s) 185static unsigned int calculate_data_blocks(struct amdtp_out_stream *s)
168{ 186{
169 unsigned int phase, data_blocks; 187 unsigned int phase, data_blocks;
@@ -376,11 +394,21 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
376 s->pcm_period_pointer += data_blocks; 394 s->pcm_period_pointer += data_blocks;
377 if (s->pcm_period_pointer >= pcm->runtime->period_size) { 395 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
378 s->pcm_period_pointer -= pcm->runtime->period_size; 396 s->pcm_period_pointer -= pcm->runtime->period_size;
379 snd_pcm_period_elapsed(pcm); 397 s->pointer_flush = false;
398 tasklet_hi_schedule(&s->period_tasklet);
380 } 399 }
381 } 400 }
382} 401}
383 402
403static void pcm_period_tasklet(unsigned long data)
404{
405 struct amdtp_out_stream *s = (void *)data;
406 struct snd_pcm_substream *pcm = ACCESS_ONCE(s->pcm);
407
408 if (pcm)
409 snd_pcm_period_elapsed(pcm);
410}
411
384static void out_packet_callback(struct fw_iso_context *context, u32 cycle, 412static void out_packet_callback(struct fw_iso_context *context, u32 cycle,
385 size_t header_length, void *header, void *data) 413 size_t header_length, void *header, void *data)
386{ 414{
@@ -506,6 +534,24 @@ err_unlock:
506EXPORT_SYMBOL(amdtp_out_stream_start); 534EXPORT_SYMBOL(amdtp_out_stream_start);
507 535
508/** 536/**
537 * amdtp_out_stream_pcm_pointer - get the PCM buffer position
538 * @s: the AMDTP output stream that transports the PCM data
539 *
540 * Returns the current buffer position, in frames.
541 */
542unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s)
543{
544 /* this optimization is allowed to be racy */
545 if (s->pointer_flush)
546 fw_iso_context_flush_completions(s->context);
547 else
548 s->pointer_flush = true;
549
550 return ACCESS_ONCE(s->pcm_buffer_pointer);
551}
552EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
553
554/**
509 * amdtp_out_stream_update - update the stream after a bus reset 555 * amdtp_out_stream_update - update the stream after a bus reset
510 * @s: the AMDTP output stream 556 * @s: the AMDTP output stream
511 */ 557 */
@@ -532,6 +578,7 @@ void amdtp_out_stream_stop(struct amdtp_out_stream *s)
532 return; 578 return;
533 } 579 }
534 580
581 tasklet_kill(&s->period_tasklet);
535 fw_iso_context_stop(s->context); 582 fw_iso_context_stop(s->context);
536 fw_iso_context_destroy(s->context); 583 fw_iso_context_destroy(s->context);
537 s->context = ERR_PTR(-1); 584 s->context = ERR_PTR(-1);
diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
index 537a9cb83581..b680c5ef01d6 100644
--- a/sound/firewire/amdtp.h
+++ b/sound/firewire/amdtp.h
@@ -1,6 +1,7 @@
1#ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED 1#ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
2#define SOUND_FIREWIRE_AMDTP_H_INCLUDED 2#define SOUND_FIREWIRE_AMDTP_H_INCLUDED
3 3
4#include <linux/interrupt.h>
4#include <linux/mutex.h> 5#include <linux/mutex.h>
5#include <linux/spinlock.h> 6#include <linux/spinlock.h>
6#include "packets-buffer.h" 7#include "packets-buffer.h"
@@ -55,6 +56,7 @@ struct amdtp_out_stream {
55 struct iso_packets_buffer buffer; 56 struct iso_packets_buffer buffer;
56 57
57 struct snd_pcm_substream *pcm; 58 struct snd_pcm_substream *pcm;
59 struct tasklet_struct period_tasklet;
58 60
59 int packet_index; 61 int packet_index;
60 unsigned int data_block_counter; 62 unsigned int data_block_counter;
@@ -66,6 +68,7 @@ struct amdtp_out_stream {
66 68
67 unsigned int pcm_buffer_pointer; 69 unsigned int pcm_buffer_pointer;
68 unsigned int pcm_period_pointer; 70 unsigned int pcm_period_pointer;
71 bool pointer_flush;
69}; 72};
70 73
71int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit, 74int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
@@ -81,6 +84,8 @@ void amdtp_out_stream_stop(struct amdtp_out_stream *s);
81 84
82void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s, 85void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
83 snd_pcm_format_t format); 86 snd_pcm_format_t format);
87void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);
88unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);
84void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s); 89void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);
85 90
86/** 91/**
@@ -123,18 +128,6 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
123} 128}
124 129
125/** 130/**
126 * amdtp_out_stream_pcm_prepare - prepare PCM device for running
127 * @s: the AMDTP output stream
128 *
129 * This function should be called from the PCM device's .prepare callback.
130 */
131static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
132{
133 s->pcm_buffer_pointer = 0;
134 s->pcm_period_pointer = 0;
135}
136
137/**
138 * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device 131 * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device
139 * @s: the AMDTP output stream 132 * @s: the AMDTP output stream
140 * @pcm: the PCM device to be started, or %NULL to stop the current device 133 * @pcm: the PCM device to be started, or %NULL to stop the current device
@@ -149,18 +142,6 @@ static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
149 ACCESS_ONCE(s->pcm) = pcm; 142 ACCESS_ONCE(s->pcm) = pcm;
150} 143}
151 144
152/**
153 * amdtp_out_stream_pcm_pointer - get the PCM buffer position
154 * @s: the AMDTP output stream that transports the PCM data
155 *
156 * Returns the current buffer position, in frames.
157 */
158static inline unsigned long
159amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s)
160{
161 return ACCESS_ONCE(s->pcm_buffer_pointer);
162}
163
164static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc) 145static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
165{ 146{
166 return sfc & 1; 147 return sfc & 1;
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 5ca0939e4223..ff3af6e77d61 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -228,7 +228,7 @@ config SND_OXYGEN
228 Say Y here to include support for sound cards based on the 228 Say Y here to include support for sound cards based on the
229 C-Media CMI8788 (Oxygen HD Audio) chip: 229 C-Media CMI8788 (Oxygen HD Audio) chip:
230 * Asound A-8788 230 * Asound A-8788
231 * Asus Xonar DG 231 * Asus Xonar DG/DGX
232 * AuzenTech X-Meridian 232 * AuzenTech X-Meridian
233 * AuzenTech X-Meridian 2G 233 * AuzenTech X-Meridian 2G
234 * Bgears b-Enspirer 234 * Bgears b-Enspirer
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c
index 9d91d61902b4..e672ff4df2da 100644
--- a/sound/pci/ad1889.c
+++ b/sound/pci/ad1889.c
@@ -1062,17 +1062,4 @@ static struct pci_driver ad1889_pci_driver = {
1062 .remove = __devexit_p(snd_ad1889_remove), 1062 .remove = __devexit_p(snd_ad1889_remove),
1063}; 1063};
1064 1064
1065static int __init 1065module_pci_driver(ad1889_pci_driver);
1066alsa_ad1889_init(void)
1067{
1068 return pci_register_driver(&ad1889_pci_driver);
1069}
1070
1071static void __exit
1072alsa_ad1889_fini(void)
1073{
1074 pci_unregister_driver(&ad1889_pci_driver);
1075}
1076
1077module_init(alsa_ad1889_init);
1078module_exit(alsa_ad1889_fini);
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index bdd6164e9c7e..9dfc27bf6cc6 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -2294,7 +2294,7 @@ static void __devexit snd_ali_remove(struct pci_dev *pci)
2294 pci_set_drvdata(pci, NULL); 2294 pci_set_drvdata(pci, NULL);
2295} 2295}
2296 2296
2297static struct pci_driver driver = { 2297static struct pci_driver ali5451_driver = {
2298 .name = KBUILD_MODNAME, 2298 .name = KBUILD_MODNAME,
2299 .id_table = snd_ali_ids, 2299 .id_table = snd_ali_ids,
2300 .probe = snd_ali_probe, 2300 .probe = snd_ali_probe,
@@ -2305,15 +2305,4 @@ static struct pci_driver driver = {
2305#endif 2305#endif
2306}; 2306};
2307 2307
2308static int __init alsa_card_ali_init(void) 2308module_pci_driver(ali5451_driver);
2309{
2310 return pci_register_driver(&driver);
2311}
2312
2313static void __exit alsa_card_ali_exit(void)
2314{
2315 pci_unregister_driver(&driver);
2316}
2317
2318module_init(alsa_card_ali_init)
2319module_exit(alsa_card_ali_exit)
diff --git a/sound/pci/als300.c b/sound/pci/als300.c
index 8196e229b2df..59d65388faf5 100644
--- a/sound/pci/als300.c
+++ b/sound/pci/als300.c
@@ -852,7 +852,7 @@ static int __devinit snd_als300_probe(struct pci_dev *pci,
852 return 0; 852 return 0;
853} 853}
854 854
855static struct pci_driver driver = { 855static struct pci_driver als300_driver = {
856 .name = KBUILD_MODNAME, 856 .name = KBUILD_MODNAME,
857 .id_table = snd_als300_ids, 857 .id_table = snd_als300_ids,
858 .probe = snd_als300_probe, 858 .probe = snd_als300_probe,
@@ -863,15 +863,4 @@ static struct pci_driver driver = {
863#endif 863#endif
864}; 864};
865 865
866static int __init alsa_card_als300_init(void) 866module_pci_driver(als300_driver);
867{
868 return pci_register_driver(&driver);
869}
870
871static void __exit alsa_card_als300_exit(void)
872{
873 pci_unregister_driver(&driver);
874}
875
876module_init(alsa_card_als300_init)
877module_exit(alsa_card_als300_exit)
diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c
index 3269b8011ea9..7d7f2598c748 100644
--- a/sound/pci/als4000.c
+++ b/sound/pci/als4000.c
@@ -1036,7 +1036,7 @@ static int snd_als4000_resume(struct pci_dev *pci)
1036#endif /* CONFIG_PM */ 1036#endif /* CONFIG_PM */
1037 1037
1038 1038
1039static struct pci_driver driver = { 1039static struct pci_driver als4000_driver = {
1040 .name = KBUILD_MODNAME, 1040 .name = KBUILD_MODNAME,
1041 .id_table = snd_als4000_ids, 1041 .id_table = snd_als4000_ids,
1042 .probe = snd_card_als4000_probe, 1042 .probe = snd_card_als4000_probe,
@@ -1047,15 +1047,4 @@ static struct pci_driver driver = {
1047#endif 1047#endif
1048}; 1048};
1049 1049
1050static int __init alsa_card_als4000_init(void) 1050module_pci_driver(als4000_driver);
1051{
1052 return pci_register_driver(&driver);
1053}
1054
1055static void __exit alsa_card_als4000_exit(void)
1056{
1057 pci_unregister_driver(&driver);
1058}
1059
1060module_init(alsa_card_als4000_init)
1061module_exit(alsa_card_als4000_exit)
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index 590682f115ef..156a94f8a123 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -1700,7 +1700,7 @@ static void __devexit snd_atiixp_remove(struct pci_dev *pci)
1700 pci_set_drvdata(pci, NULL); 1700 pci_set_drvdata(pci, NULL);
1701} 1701}
1702 1702
1703static struct pci_driver driver = { 1703static struct pci_driver atiixp_driver = {
1704 .name = KBUILD_MODNAME, 1704 .name = KBUILD_MODNAME,
1705 .id_table = snd_atiixp_ids, 1705 .id_table = snd_atiixp_ids,
1706 .probe = snd_atiixp_probe, 1706 .probe = snd_atiixp_probe,
@@ -1711,16 +1711,4 @@ static struct pci_driver driver = {
1711#endif 1711#endif
1712}; 1712};
1713 1713
1714 1714module_pci_driver(atiixp_driver);
1715static int __init alsa_card_atiixp_init(void)
1716{
1717 return pci_register_driver(&driver);
1718}
1719
1720static void __exit alsa_card_atiixp_exit(void)
1721{
1722 pci_unregister_driver(&driver);
1723}
1724
1725module_init(alsa_card_atiixp_init)
1726module_exit(alsa_card_atiixp_exit)
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c
index 524d35f31232..30a4fd96ce73 100644
--- a/sound/pci/atiixp_modem.c
+++ b/sound/pci/atiixp_modem.c
@@ -1331,7 +1331,7 @@ static void __devexit snd_atiixp_remove(struct pci_dev *pci)
1331 pci_set_drvdata(pci, NULL); 1331 pci_set_drvdata(pci, NULL);
1332} 1332}
1333 1333
1334static struct pci_driver driver = { 1334static struct pci_driver atiixp_modem_driver = {
1335 .name = KBUILD_MODNAME, 1335 .name = KBUILD_MODNAME,
1336 .id_table = snd_atiixp_ids, 1336 .id_table = snd_atiixp_ids,
1337 .probe = snd_atiixp_probe, 1337 .probe = snd_atiixp_probe,
@@ -1342,16 +1342,4 @@ static struct pci_driver driver = {
1342#endif 1342#endif
1343}; 1343};
1344 1344
1345 1345module_pci_driver(atiixp_modem_driver);
1346static int __init alsa_card_atiixp_init(void)
1347{
1348 return pci_register_driver(&driver);
1349}
1350
1351static void __exit alsa_card_atiixp_exit(void)
1352{
1353 pci_unregister_driver(&driver);
1354}
1355
1356module_init(alsa_card_atiixp_init)
1357module_exit(alsa_card_atiixp_exit)
diff --git a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c
index f13ad536b2d5..ffc376f9f4e4 100644
--- a/sound/pci/au88x0/au88x0.c
+++ b/sound/pci/au88x0/au88x0.c
@@ -375,24 +375,11 @@ static void __devexit snd_vortex_remove(struct pci_dev *pci)
375} 375}
376 376
377// pci_driver definition 377// pci_driver definition
378static struct pci_driver driver = { 378static struct pci_driver vortex_driver = {
379 .name = KBUILD_MODNAME, 379 .name = KBUILD_MODNAME,
380 .id_table = snd_vortex_ids, 380 .id_table = snd_vortex_ids,
381 .probe = snd_vortex_probe, 381 .probe = snd_vortex_probe,
382 .remove = __devexit_p(snd_vortex_remove), 382 .remove = __devexit_p(snd_vortex_remove),
383}; 383};
384 384
385// initialization of the module 385module_pci_driver(vortex_driver);
386static int __init alsa_card_vortex_init(void)
387{
388 return pci_register_driver(&driver);
389}
390
391// clean up the module
392static void __exit alsa_card_vortex_exit(void)
393{
394 pci_unregister_driver(&driver);
395}
396
397module_init(alsa_card_vortex_init)
398module_exit(alsa_card_vortex_exit)
diff --git a/sound/pci/aw2/aw2-alsa.c b/sound/pci/aw2/aw2-alsa.c
index 1c5231931462..0f804741825f 100644
--- a/sound/pci/aw2/aw2-alsa.c
+++ b/sound/pci/aw2/aw2-alsa.c
@@ -112,8 +112,6 @@ struct aw2 {
112/********************************* 112/*********************************
113 * FUNCTION DECLARATIONS 113 * FUNCTION DECLARATIONS
114 ********************************/ 114 ********************************/
115static int __init alsa_card_aw2_init(void);
116static void __exit alsa_card_aw2_exit(void);
117static int snd_aw2_dev_free(struct snd_device *device); 115static int snd_aw2_dev_free(struct snd_device *device);
118static int __devinit snd_aw2_create(struct snd_card *card, 116static int __devinit snd_aw2_create(struct snd_card *card,
119 struct pci_dev *pci, struct aw2 **rchip); 117 struct pci_dev *pci, struct aw2 **rchip);
@@ -171,13 +169,15 @@ static DEFINE_PCI_DEVICE_TABLE(snd_aw2_ids) = {
171MODULE_DEVICE_TABLE(pci, snd_aw2_ids); 169MODULE_DEVICE_TABLE(pci, snd_aw2_ids);
172 170
173/* pci_driver definition */ 171/* pci_driver definition */
174static struct pci_driver driver = { 172static struct pci_driver aw2_driver = {
175 .name = KBUILD_MODNAME, 173 .name = KBUILD_MODNAME,
176 .id_table = snd_aw2_ids, 174 .id_table = snd_aw2_ids,
177 .probe = snd_aw2_probe, 175 .probe = snd_aw2_probe,
178 .remove = __devexit_p(snd_aw2_remove), 176 .remove = __devexit_p(snd_aw2_remove),
179}; 177};
180 178
179module_pci_driver(aw2_driver);
180
181/* operators for playback PCM alsa interface */ 181/* operators for playback PCM alsa interface */
182static struct snd_pcm_ops snd_aw2_playback_ops = { 182static struct snd_pcm_ops snd_aw2_playback_ops = {
183 .open = snd_aw2_pcm_playback_open, 183 .open = snd_aw2_pcm_playback_open,
@@ -217,23 +217,6 @@ static struct snd_kcontrol_new aw2_control __devinitdata = {
217 * FUNCTION IMPLEMENTATIONS 217 * FUNCTION IMPLEMENTATIONS
218 ********************************/ 218 ********************************/
219 219
220/* initialization of the module */
221static 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 */
228static 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
234module_init(alsa_card_aw2_init);
235module_exit(alsa_card_aw2_exit);
236
237/* component-destructor */ 220/* component-destructor */
238static int snd_aw2_dev_free(struct snd_device *device) 221static int snd_aw2_dev_free(struct snd_device *device)
239{ 222{
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index 496f14c1a731..f0b4d7493af5 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -2862,7 +2862,7 @@ snd_azf3328_resume(struct pci_dev *pci)
2862#endif /* CONFIG_PM */ 2862#endif /* CONFIG_PM */
2863 2863
2864 2864
2865static struct pci_driver driver = { 2865static struct pci_driver azf3328_driver = {
2866 .name = KBUILD_MODNAME, 2866 .name = KBUILD_MODNAME,
2867 .id_table = snd_azf3328_ids, 2867 .id_table = snd_azf3328_ids,
2868 .probe = snd_azf3328_probe, 2868 .probe = snd_azf3328_probe,
@@ -2873,23 +2873,4 @@ static struct pci_driver driver = {
2873#endif 2873#endif
2874}; 2874};
2875 2875
2876static int __init 2876module_pci_driver(azf3328_driver);
2877alsa_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
2886static void __exit
2887alsa_card_azf3328_exit(void)
2888{
2889 snd_azf3328_dbgcallenter();
2890 pci_unregister_driver(&driver);
2891 snd_azf3328_dbgcallleave();
2892}
2893
2894module_init(alsa_card_azf3328_init)
2895module_exit(alsa_card_azf3328_exit)
diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c
index 62d6163fc9d9..b6a95eeca095 100644
--- a/sound/pci/bt87x.c
+++ b/sound/pci/bt87x.c
@@ -836,8 +836,6 @@ static struct {
836 {0x7063, 0x2000}, /* pcHDTV HD-2000 TV */ 836 {0x7063, 0x2000}, /* pcHDTV HD-2000 TV */
837}; 837};
838 838
839static struct pci_driver driver;
840
841/* return the id of the card, or a negative value if it's blacklisted */ 839/* return the id of the card, or a negative value if it's blacklisted */
842static int __devinit snd_bt87x_detect_card(struct pci_dev *pci) 840static int __devinit snd_bt87x_detect_card(struct pci_dev *pci)
843{ 841{
@@ -964,24 +962,11 @@ static DEFINE_PCI_DEVICE_TABLE(snd_bt87x_default_ids) = {
964 { } 962 { }
965}; 963};
966 964
967static struct pci_driver driver = { 965static struct pci_driver bt87x_driver = {
968 .name = KBUILD_MODNAME, 966 .name = KBUILD_MODNAME,
969 .id_table = snd_bt87x_ids, 967 .id_table = snd_bt87x_ids,
970 .probe = snd_bt87x_probe, 968 .probe = snd_bt87x_probe,
971 .remove = __devexit_p(snd_bt87x_remove), 969 .remove = __devexit_p(snd_bt87x_remove),
972}; 970};
973 971
974static int __init alsa_card_bt87x_init(void) 972module_pci_driver(bt87x_driver);
975{
976 if (load_all)
977 driver.id_table = snd_bt87x_default_ids;
978 return pci_register_driver(&driver);
979}
980
981static void __exit alsa_card_bt87x_exit(void)
982{
983 pci_unregister_driver(&driver);
984}
985
986module_init(alsa_card_bt87x_init)
987module_exit(alsa_card_bt87x_exit)
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index 08d6ebfe5a61..e76d68a7081f 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -1932,7 +1932,7 @@ static DEFINE_PCI_DEVICE_TABLE(snd_ca0106_ids) = {
1932MODULE_DEVICE_TABLE(pci, snd_ca0106_ids); 1932MODULE_DEVICE_TABLE(pci, snd_ca0106_ids);
1933 1933
1934// pci_driver definition 1934// pci_driver definition
1935static struct pci_driver driver = { 1935static struct pci_driver ca0106_driver = {
1936 .name = KBUILD_MODNAME, 1936 .name = KBUILD_MODNAME,
1937 .id_table = snd_ca0106_ids, 1937 .id_table = snd_ca0106_ids,
1938 .probe = snd_ca0106_probe, 1938 .probe = snd_ca0106_probe,
@@ -1943,17 +1943,4 @@ static struct pci_driver driver = {
1943#endif 1943#endif
1944}; 1944};
1945 1945
1946// initialization of the module 1946module_pci_driver(ca0106_driver);
1947static int __init alsa_card_ca0106_init(void)
1948{
1949 return pci_register_driver(&driver);
1950}
1951
1952// clean up the module
1953static void __exit alsa_card_ca0106_exit(void)
1954{
1955 pci_unregister_driver(&driver);
1956}
1957
1958module_init(alsa_card_ca0106_init)
1959module_exit(alsa_card_ca0106_exit)
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 19b06269adc2..3815bd4c6779 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -3398,7 +3398,7 @@ static int snd_cmipci_resume(struct pci_dev *pci)
3398} 3398}
3399#endif /* CONFIG_PM */ 3399#endif /* CONFIG_PM */
3400 3400
3401static struct pci_driver driver = { 3401static struct pci_driver cmipci_driver = {
3402 .name = KBUILD_MODNAME, 3402 .name = KBUILD_MODNAME,
3403 .id_table = snd_cmipci_ids, 3403 .id_table = snd_cmipci_ids,
3404 .probe = snd_cmipci_probe, 3404 .probe = snd_cmipci_probe,
@@ -3409,15 +3409,4 @@ static struct pci_driver driver = {
3409#endif 3409#endif
3410}; 3410};
3411 3411
3412static int __init alsa_card_cmipci_init(void) 3412module_pci_driver(cmipci_driver);
3413{
3414 return pci_register_driver(&driver);
3415}
3416
3417static void __exit alsa_card_cmipci_exit(void)
3418{
3419 pci_unregister_driver(&driver);
3420}
3421
3422module_init(alsa_card_cmipci_init)
3423module_exit(alsa_card_cmipci_exit)
diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c
index a9f368f60df6..33506ee569bd 100644
--- a/sound/pci/cs4281.c
+++ b/sound/pci/cs4281.c
@@ -2084,7 +2084,7 @@ static int cs4281_resume(struct pci_dev *pci)
2084} 2084}
2085#endif /* CONFIG_PM */ 2085#endif /* CONFIG_PM */
2086 2086
2087static struct pci_driver driver = { 2087static struct pci_driver cs4281_driver = {
2088 .name = KBUILD_MODNAME, 2088 .name = KBUILD_MODNAME,
2089 .id_table = snd_cs4281_ids, 2089 .id_table = snd_cs4281_ids,
2090 .probe = snd_cs4281_probe, 2090 .probe = snd_cs4281_probe,
@@ -2095,15 +2095,4 @@ static struct pci_driver driver = {
2095#endif 2095#endif
2096}; 2096};
2097 2097
2098static int __init alsa_card_cs4281_init(void) 2098module_pci_driver(cs4281_driver);
2099{
2100 return pci_register_driver(&driver);
2101}
2102
2103static void __exit alsa_card_cs4281_exit(void)
2104{
2105 pci_unregister_driver(&driver);
2106}
2107
2108module_init(alsa_card_cs4281_init)
2109module_exit(alsa_card_cs4281_exit)
diff --git a/sound/pci/cs46xx/cs46xx.c b/sound/pci/cs46xx/cs46xx.c
index 819d79d0586d..6cc7404e0e8f 100644
--- a/sound/pci/cs46xx/cs46xx.c
+++ b/sound/pci/cs46xx/cs46xx.c
@@ -161,7 +161,7 @@ static void __devexit snd_card_cs46xx_remove(struct pci_dev *pci)
161 pci_set_drvdata(pci, NULL); 161 pci_set_drvdata(pci, NULL);
162} 162}
163 163
164static struct pci_driver driver = { 164static struct pci_driver cs46xx_driver = {
165 .name = KBUILD_MODNAME, 165 .name = KBUILD_MODNAME,
166 .id_table = snd_cs46xx_ids, 166 .id_table = snd_cs46xx_ids,
167 .probe = snd_card_cs46xx_probe, 167 .probe = snd_card_cs46xx_probe,
@@ -172,15 +172,4 @@ static struct pci_driver driver = {
172#endif 172#endif
173}; 173};
174 174
175static int __init alsa_card_cs46xx_init(void) 175module_pci_driver(cs46xx_driver);
176{
177 return pci_register_driver(&driver);
178}
179
180static void __exit alsa_card_cs46xx_exit(void)
181{
182 pci_unregister_driver(&driver);
183}
184
185module_init(alsa_card_cs46xx_init)
186module_exit(alsa_card_cs46xx_exit)
diff --git a/sound/pci/cs5530.c b/sound/pci/cs5530.c
index c47cabff2bfa..f1e4229993af 100644
--- a/sound/pci/cs5530.c
+++ b/sound/pci/cs5530.c
@@ -291,23 +291,11 @@ static int __devinit snd_cs5530_probe(struct pci_dev *pci,
291 return 0; 291 return 0;
292} 292}
293 293
294static struct pci_driver driver = { 294static struct pci_driver cs5530_driver = {
295 .name = KBUILD_MODNAME, 295 .name = KBUILD_MODNAME,
296 .id_table = snd_cs5530_ids, 296 .id_table = snd_cs5530_ids,
297 .probe = snd_cs5530_probe, 297 .probe = snd_cs5530_probe,
298 .remove = __devexit_p(snd_cs5530_remove), 298 .remove = __devexit_p(snd_cs5530_remove),
299}; 299};
300 300
301static int __init alsa_card_cs5530_init(void) 301module_pci_driver(cs5530_driver);
302{
303 return pci_register_driver(&driver);
304}
305
306static void __exit alsa_card_cs5530_exit(void)
307{
308 pci_unregister_driver(&driver);
309}
310
311module_init(alsa_card_cs5530_init)
312module_exit(alsa_card_cs5530_exit)
313
diff --git a/sound/pci/cs5535audio/cs5535audio.c b/sound/pci/cs5535audio/cs5535audio.c
index a2fb2173e980..2c9697cf0a1a 100644
--- a/sound/pci/cs5535audio/cs5535audio.c
+++ b/sound/pci/cs5535audio/cs5535audio.c
@@ -394,7 +394,7 @@ static void __devexit snd_cs5535audio_remove(struct pci_dev *pci)
394 pci_set_drvdata(pci, NULL); 394 pci_set_drvdata(pci, NULL);
395} 395}
396 396
397static struct pci_driver driver = { 397static struct pci_driver cs5535audio_driver = {
398 .name = KBUILD_MODNAME, 398 .name = KBUILD_MODNAME,
399 .id_table = snd_cs5535audio_ids, 399 .id_table = snd_cs5535audio_ids,
400 .probe = snd_cs5535audio_probe, 400 .probe = snd_cs5535audio_probe,
@@ -405,18 +405,7 @@ static struct pci_driver driver = {
405#endif 405#endif
406}; 406};
407 407
408static int __init alsa_card_cs5535audio_init(void) 408module_pci_driver(cs5535audio_driver);
409{
410 return pci_register_driver(&driver);
411}
412
413static void __exit alsa_card_cs5535audio_exit(void)
414{
415 pci_unregister_driver(&driver);
416}
417
418module_init(alsa_card_cs5535audio_init)
419module_exit(alsa_card_cs5535audio_exit)
420 409
421MODULE_AUTHOR("Jaya Kumar"); 410MODULE_AUTHOR("Jaya Kumar");
422MODULE_LICENSE("GPL"); 411MODULE_LICENSE("GPL");
diff --git a/sound/pci/ctxfi/xfi.c b/sound/pci/ctxfi/xfi.c
index 15d95d2bacee..75aa2c338410 100644
--- a/sound/pci/ctxfi/xfi.c
+++ b/sound/pci/ctxfi/xfi.c
@@ -154,15 +154,4 @@ static struct pci_driver ct_driver = {
154#endif 154#endif
155}; 155};
156 156
157static int __init ct_card_init(void) 157module_pci_driver(ct_driver);
158{
159 return pci_register_driver(&ct_driver);
160}
161
162static void __exit ct_card_exit(void)
163{
164 pci_unregister_driver(&ct_driver);
165}
166
167module_init(ct_card_init)
168module_exit(ct_card_exit)
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index 595c11f904bb..0f8eda1dafdb 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -2328,7 +2328,7 @@ static void __devexit snd_echo_remove(struct pci_dev *pci)
2328******************************************************************************/ 2328******************************************************************************/
2329 2329
2330/* pci_driver definition */ 2330/* pci_driver definition */
2331static struct pci_driver driver = { 2331static struct pci_driver echo_driver = {
2332 .name = KBUILD_MODNAME, 2332 .name = KBUILD_MODNAME,
2333 .id_table = snd_echo_ids, 2333 .id_table = snd_echo_ids,
2334 .probe = snd_echo_probe, 2334 .probe = snd_echo_probe,
@@ -2339,22 +2339,4 @@ static struct pci_driver driver = {
2339#endif /* CONFIG_PM */ 2339#endif /* CONFIG_PM */
2340}; 2340};
2341 2341
2342 2342module_pci_driver(echo_driver);
2343
2344/* initialization of the module */
2345static int __init alsa_card_echo_init(void)
2346{
2347 return pci_register_driver(&driver);
2348}
2349
2350
2351
2352/* clean up the module */
2353static void __exit alsa_card_echo_exit(void)
2354{
2355 pci_unregister_driver(&driver);
2356}
2357
2358
2359module_init(alsa_card_echo_init)
2360module_exit(alsa_card_echo_exit)
diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c
index 790c65d980c8..7fdbbe4d9965 100644
--- a/sound/pci/emu10k1/emu10k1.c
+++ b/sound/pci/emu10k1/emu10k1.c
@@ -263,7 +263,7 @@ static int snd_emu10k1_resume(struct pci_dev *pci)
263} 263}
264#endif 264#endif
265 265
266static struct pci_driver driver = { 266static struct pci_driver emu10k1_driver = {
267 .name = KBUILD_MODNAME, 267 .name = KBUILD_MODNAME,
268 .id_table = snd_emu10k1_ids, 268 .id_table = snd_emu10k1_ids,
269 .probe = snd_card_emu10k1_probe, 269 .probe = snd_card_emu10k1_probe,
@@ -274,15 +274,4 @@ static struct pci_driver driver = {
274#endif 274#endif
275}; 275};
276 276
277static int __init alsa_card_emu10k1_init(void) 277module_pci_driver(emu10k1_driver);
278{
279 return pci_register_driver(&driver);
280}
281
282static void __exit alsa_card_emu10k1_exit(void)
283{
284 pci_unregister_driver(&driver);
285}
286
287module_init(alsa_card_emu10k1_init)
288module_exit(alsa_card_emu10k1_exit)
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index 47a651cb6e84..5c8978b2c4d9 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -1612,24 +1612,11 @@ static DEFINE_PCI_DEVICE_TABLE(snd_emu10k1x_ids) = {
1612MODULE_DEVICE_TABLE(pci, snd_emu10k1x_ids); 1612MODULE_DEVICE_TABLE(pci, snd_emu10k1x_ids);
1613 1613
1614// pci_driver definition 1614// pci_driver definition
1615static struct pci_driver driver = { 1615static struct pci_driver emu10k1x_driver = {
1616 .name = KBUILD_MODNAME, 1616 .name = KBUILD_MODNAME,
1617 .id_table = snd_emu10k1x_ids, 1617 .id_table = snd_emu10k1x_ids,
1618 .probe = snd_emu10k1x_probe, 1618 .probe = snd_emu10k1x_probe,
1619 .remove = __devexit_p(snd_emu10k1x_remove), 1619 .remove = __devexit_p(snd_emu10k1x_remove),
1620}; 1620};
1621 1621
1622// initialization of the module 1622module_pci_driver(emu10k1x_driver);
1623static int __init alsa_card_emu10k1x_init(void)
1624{
1625 return pci_register_driver(&driver);
1626}
1627
1628// clean up the module
1629static void __exit alsa_card_emu10k1x_exit(void)
1630{
1631 pci_unregister_driver(&driver);
1632}
1633
1634module_init(alsa_card_emu10k1x_init)
1635module_exit(alsa_card_emu10k1x_exit)
diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c
index 47a245e84190..3821c81d1c99 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -2488,7 +2488,7 @@ static void __devexit snd_audiopci_remove(struct pci_dev *pci)
2488 pci_set_drvdata(pci, NULL); 2488 pci_set_drvdata(pci, NULL);
2489} 2489}
2490 2490
2491static struct pci_driver driver = { 2491static struct pci_driver ens137x_driver = {
2492 .name = KBUILD_MODNAME, 2492 .name = KBUILD_MODNAME,
2493 .id_table = snd_audiopci_ids, 2493 .id_table = snd_audiopci_ids,
2494 .probe = snd_audiopci_probe, 2494 .probe = snd_audiopci_probe,
@@ -2499,15 +2499,4 @@ static struct pci_driver driver = {
2499#endif 2499#endif
2500}; 2500};
2501 2501
2502static int __init alsa_card_ens137x_init(void) 2502module_pci_driver(ens137x_driver);
2503{
2504 return pci_register_driver(&driver);
2505}
2506
2507static void __exit alsa_card_ens137x_exit(void)
2508{
2509 pci_unregister_driver(&driver);
2510}
2511
2512module_init(alsa_card_ens137x_init)
2513module_exit(alsa_card_ens137x_exit)
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 53eb76b41108..82c8d8c5c52a 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -1882,7 +1882,7 @@ static void __devexit snd_es1938_remove(struct pci_dev *pci)
1882 pci_set_drvdata(pci, NULL); 1882 pci_set_drvdata(pci, NULL);
1883} 1883}
1884 1884
1885static struct pci_driver driver = { 1885static struct pci_driver es1938_driver = {
1886 .name = KBUILD_MODNAME, 1886 .name = KBUILD_MODNAME,
1887 .id_table = snd_es1938_ids, 1887 .id_table = snd_es1938_ids,
1888 .probe = snd_es1938_probe, 1888 .probe = snd_es1938_probe,
@@ -1893,15 +1893,4 @@ static struct pci_driver driver = {
1893#endif 1893#endif
1894}; 1894};
1895 1895
1896static int __init alsa_card_es1938_init(void) 1896module_pci_driver(es1938_driver);
1897{
1898 return pci_register_driver(&driver);
1899}
1900
1901static void __exit alsa_card_es1938_exit(void)
1902{
1903 pci_unregister_driver(&driver);
1904}
1905
1906module_init(alsa_card_es1938_init)
1907module_exit(alsa_card_es1938_exit)
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index a8faae1c85e4..67f47d891959 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -2898,7 +2898,7 @@ static void __devexit snd_es1968_remove(struct pci_dev *pci)
2898 pci_set_drvdata(pci, NULL); 2898 pci_set_drvdata(pci, NULL);
2899} 2899}
2900 2900
2901static struct pci_driver driver = { 2901static struct pci_driver es1968_driver = {
2902 .name = KBUILD_MODNAME, 2902 .name = KBUILD_MODNAME,
2903 .id_table = snd_es1968_ids, 2903 .id_table = snd_es1968_ids,
2904 .probe = snd_es1968_probe, 2904 .probe = snd_es1968_probe,
@@ -2909,15 +2909,4 @@ static struct pci_driver driver = {
2909#endif 2909#endif
2910}; 2910};
2911 2911
2912static int __init alsa_card_es1968_init(void) 2912module_pci_driver(es1968_driver);
2913{
2914 return pci_register_driver(&driver);
2915}
2916
2917static void __exit alsa_card_es1968_exit(void)
2918{
2919 pci_unregister_driver(&driver);
2920}
2921
2922module_init(alsa_card_es1968_init)
2923module_exit(alsa_card_es1968_exit)
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index a416ea8af3e9..f69662322750 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -1416,7 +1416,7 @@ static int snd_fm801_resume(struct pci_dev *pci)
1416} 1416}
1417#endif 1417#endif
1418 1418
1419static struct pci_driver driver = { 1419static struct pci_driver fm801_driver = {
1420 .name = KBUILD_MODNAME, 1420 .name = KBUILD_MODNAME,
1421 .id_table = snd_fm801_ids, 1421 .id_table = snd_fm801_ids,
1422 .probe = snd_card_fm801_probe, 1422 .probe = snd_card_fm801_probe,
@@ -1427,15 +1427,4 @@ static struct pci_driver driver = {
1427#endif 1427#endif
1428}; 1428};
1429 1429
1430static int __init alsa_card_fm801_init(void) 1430module_pci_driver(fm801_driver);
1431{
1432 return pci_register_driver(&driver);
1433}
1434
1435static void __exit alsa_card_fm801_exit(void)
1436{
1437 pci_unregister_driver(&driver);
1438}
1439
1440module_init(alsa_card_fm801_init)
1441module_exit(alsa_card_fm801_exit)
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 7ee46aba6ea7..4ab8102f87ea 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -2566,6 +2566,8 @@ static struct snd_pci_quirk probe_mask_list[] __devinitdata = {
2566 /* forced codec slots */ 2566 /* forced codec slots */
2567 SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103), 2567 SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),
2568 SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103), 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
@@ -3154,7 +3156,7 @@ static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
3154MODULE_DEVICE_TABLE(pci, azx_ids); 3156MODULE_DEVICE_TABLE(pci, azx_ids);
3155 3157
3156/* pci_driver definition */ 3158/* pci_driver definition */
3157static struct pci_driver driver = { 3159static struct pci_driver azx_driver = {
3158 .name = KBUILD_MODNAME, 3160 .name = KBUILD_MODNAME,
3159 .id_table = azx_ids, 3161 .id_table = azx_ids,
3160 .probe = azx_probe, 3162 .probe = azx_probe,
@@ -3165,15 +3167,4 @@ static struct pci_driver driver = {
3165#endif 3167#endif
3166}; 3168};
3167 3169
3168static int __init alsa_card_azx_init(void) 3170module_pci_driver(azx_driver);
3169{
3170 return pci_register_driver(&driver);
3171}
3172
3173static void __exit alsa_card_azx_exit(void)
3174{
3175 pci_unregister_driver(&driver);
3176}
3177
3178module_init(alsa_card_azx_init)
3179module_exit(alsa_card_azx_exit)
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index 132a86e09d07..5be2e120a14e 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -2803,22 +2803,11 @@ static void __devexit snd_ice1712_remove(struct pci_dev *pci)
2803 pci_set_drvdata(pci, NULL); 2803 pci_set_drvdata(pci, NULL);
2804} 2804}
2805 2805
2806static struct pci_driver driver = { 2806static struct pci_driver ice1712_driver = {
2807 .name = KBUILD_MODNAME, 2807 .name = KBUILD_MODNAME,
2808 .id_table = snd_ice1712_ids, 2808 .id_table = snd_ice1712_ids,
2809 .probe = snd_ice1712_probe, 2809 .probe = snd_ice1712_probe,
2810 .remove = __devexit_p(snd_ice1712_remove), 2810 .remove = __devexit_p(snd_ice1712_remove),
2811}; 2811};
2812 2812
2813static int __init alsa_card_ice1712_init(void) 2813module_pci_driver(ice1712_driver);
2814{
2815 return pci_register_driver(&driver);
2816}
2817
2818static void __exit alsa_card_ice1712_exit(void)
2819{
2820 pci_unregister_driver(&driver);
2821}
2822
2823module_init(alsa_card_ice1712_init)
2824module_exit(alsa_card_ice1712_exit)
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index 812d10e43ae0..a01a00d1cf4d 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -2873,7 +2873,7 @@ static int snd_vt1724_resume(struct pci_dev *pci)
2873} 2873}
2874#endif 2874#endif
2875 2875
2876static struct pci_driver driver = { 2876static struct pci_driver vt1724_driver = {
2877 .name = KBUILD_MODNAME, 2877 .name = KBUILD_MODNAME,
2878 .id_table = snd_vt1724_ids, 2878 .id_table = snd_vt1724_ids,
2879 .probe = snd_vt1724_probe, 2879 .probe = snd_vt1724_probe,
@@ -2884,15 +2884,4 @@ static struct pci_driver driver = {
2884#endif 2884#endif
2885}; 2885};
2886 2886
2887static int __init alsa_card_ice1724_init(void) 2887module_pci_driver(vt1724_driver);
2888{
2889 return pci_register_driver(&driver);
2890}
2891
2892static void __exit alsa_card_ice1724_exit(void)
2893{
2894 pci_unregister_driver(&driver);
2895}
2896
2897module_init(alsa_card_ice1724_init)
2898module_exit(alsa_card_ice1724_exit)
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index e0a4263baa20..f4e2dd4da8cf 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -3338,7 +3338,7 @@ static void __devexit snd_intel8x0_remove(struct pci_dev *pci)
3338 pci_set_drvdata(pci, NULL); 3338 pci_set_drvdata(pci, NULL);
3339} 3339}
3340 3340
3341static struct pci_driver driver = { 3341static struct pci_driver intel8x0_driver = {
3342 .name = KBUILD_MODNAME, 3342 .name = KBUILD_MODNAME,
3343 .id_table = snd_intel8x0_ids, 3343 .id_table = snd_intel8x0_ids,
3344 .probe = snd_intel8x0_probe, 3344 .probe = snd_intel8x0_probe,
@@ -3349,16 +3349,4 @@ static struct pci_driver driver = {
3349#endif 3349#endif
3350}; 3350};
3351 3351
3352 3352module_pci_driver(intel8x0_driver);
3353static int __init alsa_card_intel8x0_init(void)
3354{
3355 return pci_register_driver(&driver);
3356}
3357
3358static void __exit alsa_card_intel8x0_exit(void)
3359{
3360 pci_unregister_driver(&driver);
3361}
3362
3363module_init(alsa_card_intel8x0_init)
3364module_exit(alsa_card_intel8x0_exit)
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
index d689913a61be..fc27a6a69e77 100644
--- a/sound/pci/intel8x0m.c
+++ b/sound/pci/intel8x0m.c
@@ -1324,7 +1324,7 @@ static void __devexit snd_intel8x0m_remove(struct pci_dev *pci)
1324 pci_set_drvdata(pci, NULL); 1324 pci_set_drvdata(pci, NULL);
1325} 1325}
1326 1326
1327static struct pci_driver driver = { 1327static struct pci_driver intel8x0m_driver = {
1328 .name = KBUILD_MODNAME, 1328 .name = KBUILD_MODNAME,
1329 .id_table = snd_intel8x0m_ids, 1329 .id_table = snd_intel8x0m_ids,
1330 .probe = snd_intel8x0m_probe, 1330 .probe = snd_intel8x0m_probe,
@@ -1335,16 +1335,4 @@ static struct pci_driver driver = {
1335#endif 1335#endif
1336}; 1336};
1337 1337
1338 1338module_pci_driver(intel8x0m_driver);
1339static int __init alsa_card_intel8x0m_init(void)
1340{
1341 return pci_register_driver(&driver);
1342}
1343
1344static void __exit alsa_card_intel8x0m_exit(void)
1345{
1346 pci_unregister_driver(&driver);
1347}
1348
1349module_init(alsa_card_intel8x0m_init)
1350module_exit(alsa_card_intel8x0m_exit)
diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
index 8fea45ab5882..e69ce5f9c31e 100644
--- a/sound/pci/korg1212/korg1212.c
+++ b/sound/pci/korg1212/korg1212.c
@@ -2476,22 +2476,11 @@ static void __devexit snd_korg1212_remove(struct pci_dev *pci)
2476 pci_set_drvdata(pci, NULL); 2476 pci_set_drvdata(pci, NULL);
2477} 2477}
2478 2478
2479static struct pci_driver driver = { 2479static struct pci_driver korg1212_driver = {
2480 .name = KBUILD_MODNAME, 2480 .name = KBUILD_MODNAME,
2481 .id_table = snd_korg1212_ids, 2481 .id_table = snd_korg1212_ids,
2482 .probe = snd_korg1212_probe, 2482 .probe = snd_korg1212_probe,
2483 .remove = __devexit_p(snd_korg1212_remove), 2483 .remove = __devexit_p(snd_korg1212_remove),
2484}; 2484};
2485 2485
2486static int __init alsa_card_korg1212_init(void) 2486module_pci_driver(korg1212_driver);
2487{
2488 return pci_register_driver(&driver);
2489}
2490
2491static void __exit alsa_card_korg1212_exit(void)
2492{
2493 pci_unregister_driver(&driver);
2494}
2495
2496module_init(alsa_card_korg1212_init)
2497module_exit(alsa_card_korg1212_exit)
diff --git a/sound/pci/lola/lola.c b/sound/pci/lola/lola.c
index 375982736858..ac15166bee68 100644
--- a/sound/pci/lola/lola.c
+++ b/sound/pci/lola/lola.c
@@ -770,22 +770,11 @@ static DEFINE_PCI_DEVICE_TABLE(lola_ids) = {
770MODULE_DEVICE_TABLE(pci, lola_ids); 770MODULE_DEVICE_TABLE(pci, lola_ids);
771 771
772/* pci_driver definition */ 772/* pci_driver definition */
773static struct pci_driver driver = { 773static struct pci_driver lola_driver = {
774 .name = KBUILD_MODNAME, 774 .name = KBUILD_MODNAME,
775 .id_table = lola_ids, 775 .id_table = lola_ids,
776 .probe = lola_probe, 776 .probe = lola_probe,
777 .remove = __devexit_p(lola_remove), 777 .remove = __devexit_p(lola_remove),
778}; 778};
779 779
780static int __init alsa_card_lola_init(void) 780module_pci_driver(lola_driver);
781{
782 return pci_register_driver(&driver);
783}
784
785static void __exit alsa_card_lola_exit(void)
786{
787 pci_unregister_driver(&driver);
788}
789
790module_init(alsa_card_lola_init)
791module_exit(alsa_card_lola_exit)
diff --git a/sound/pci/lx6464es/lx6464es.c b/sound/pci/lx6464es/lx6464es.c
index d94c0c292bd0..d1ab43706735 100644
--- a/sound/pci/lx6464es/lx6464es.c
+++ b/sound/pci/lx6464es/lx6464es.c
@@ -1141,24 +1141,11 @@ static void __devexit snd_lx6464es_remove(struct pci_dev *pci)
1141} 1141}
1142 1142
1143 1143
1144static struct pci_driver driver = { 1144static struct pci_driver lx6464es_driver = {
1145 .name = KBUILD_MODNAME, 1145 .name = KBUILD_MODNAME,
1146 .id_table = snd_lx6464es_ids, 1146 .id_table = snd_lx6464es_ids,
1147 .probe = snd_lx6464es_probe, 1147 .probe = snd_lx6464es_probe,
1148 .remove = __devexit_p(snd_lx6464es_remove), 1148 .remove = __devexit_p(snd_lx6464es_remove),
1149}; 1149};
1150 1150
1151 1151module_pci_driver(lx6464es_driver);
1152/* module initialization */
1153static int __init mod_init(void)
1154{
1155 return pci_register_driver(&driver);
1156}
1157
1158static void __exit mod_exit(void)
1159{
1160 pci_unregister_driver(&driver);
1161}
1162
1163module_init(mod_init);
1164module_exit(mod_exit);
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index 78229b0dad2b..deef21399586 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -2837,7 +2837,7 @@ static void __devexit snd_m3_remove(struct pci_dev *pci)
2837 pci_set_drvdata(pci, NULL); 2837 pci_set_drvdata(pci, NULL);
2838} 2838}
2839 2839
2840static struct pci_driver driver = { 2840static struct pci_driver m3_driver = {
2841 .name = KBUILD_MODNAME, 2841 .name = KBUILD_MODNAME,
2842 .id_table = snd_m3_ids, 2842 .id_table = snd_m3_ids,
2843 .probe = snd_m3_probe, 2843 .probe = snd_m3_probe,
@@ -2848,15 +2848,4 @@ static struct pci_driver driver = {
2848#endif 2848#endif
2849}; 2849};
2850 2850
2851static int __init alsa_card_m3_init(void) 2851module_pci_driver(m3_driver);
2852{
2853 return pci_register_driver(&driver);
2854}
2855
2856static void __exit alsa_card_m3_exit(void)
2857{
2858 pci_unregister_driver(&driver);
2859}
2860
2861module_init(alsa_card_m3_init)
2862module_exit(alsa_card_m3_exit)
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c
index 487837c01c9f..0762610c99c0 100644
--- a/sound/pci/mixart/mixart.c
+++ b/sound/pci/mixart/mixart.c
@@ -1380,22 +1380,11 @@ static void __devexit snd_mixart_remove(struct pci_dev *pci)
1380 pci_set_drvdata(pci, NULL); 1380 pci_set_drvdata(pci, NULL);
1381} 1381}
1382 1382
1383static struct pci_driver driver = { 1383static struct pci_driver mixart_driver = {
1384 .name = KBUILD_MODNAME, 1384 .name = KBUILD_MODNAME,
1385 .id_table = snd_mixart_ids, 1385 .id_table = snd_mixart_ids,
1386 .probe = snd_mixart_probe, 1386 .probe = snd_mixart_probe,
1387 .remove = __devexit_p(snd_mixart_remove), 1387 .remove = __devexit_p(snd_mixart_remove),
1388}; 1388};
1389 1389
1390static int __init alsa_card_mixart_init(void) 1390module_pci_driver(mixart_driver);
1391{
1392 return pci_register_driver(&driver);
1393}
1394
1395static void __exit alsa_card_mixart_exit(void)
1396{
1397 pci_unregister_driver(&driver);
1398}
1399
1400module_init(alsa_card_mixart_init)
1401module_exit(alsa_card_mixart_exit)
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index ade2c64bd606..8159b05ee94d 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -1742,7 +1742,7 @@ static void __devexit snd_nm256_remove(struct pci_dev *pci)
1742} 1742}
1743 1743
1744 1744
1745static struct pci_driver driver = { 1745static struct pci_driver nm256_driver = {
1746 .name = KBUILD_MODNAME, 1746 .name = KBUILD_MODNAME,
1747 .id_table = snd_nm256_ids, 1747 .id_table = snd_nm256_ids,
1748 .probe = snd_nm256_probe, 1748 .probe = snd_nm256_probe,
@@ -1753,16 +1753,4 @@ static struct pci_driver driver = {
1753#endif 1753#endif
1754}; 1754};
1755 1755
1756 1756module_pci_driver(nm256_driver);
1757static int __init alsa_card_nm256_init(void)
1758{
1759 return pci_register_driver(&driver);
1760}
1761
1762static void __exit alsa_card_nm256_exit(void)
1763{
1764 pci_unregister_driver(&driver);
1765}
1766
1767module_init(alsa_card_nm256_init)
1768module_exit(alsa_card_nm256_exit)
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c
index eab663eef117..610275bfbaeb 100644
--- a/sound/pci/oxygen/oxygen.c
+++ b/sound/pci/oxygen/oxygen.c
@@ -94,6 +94,7 @@ enum {
94 MODEL_2CH_OUTPUT, 94 MODEL_2CH_OUTPUT,
95 MODEL_HG2PCI, 95 MODEL_HG2PCI,
96 MODEL_XONAR_DG, 96 MODEL_XONAR_DG,
97 MODEL_XONAR_DGX,
97}; 98};
98 99
99static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = { 100static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = {
@@ -109,6 +110,8 @@ static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = {
109 { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF }, 110 { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF },
110 /* Asus Xonar DG */ 111 /* Asus Xonar DG */
111 { OXYGEN_PCI_SUBID(0x1043, 0x8467), .driver_data = MODEL_XONAR_DG }, 112 { OXYGEN_PCI_SUBID(0x1043, 0x8467), .driver_data = MODEL_XONAR_DG },
113 /* Asus Xonar DGX */
114 { OXYGEN_PCI_SUBID(0x1043, 0x8521), .driver_data = MODEL_XONAR_DGX },
112 /* PCI 2.0 HD Audio */ 115 /* PCI 2.0 HD Audio */
113 { OXYGEN_PCI_SUBID(0x13f6, 0x8782), .driver_data = MODEL_2CH_OUTPUT }, 116 { OXYGEN_PCI_SUBID(0x13f6, 0x8782), .driver_data = MODEL_2CH_OUTPUT },
114 /* Kuroutoshikou CMI8787-HG2PCI */ 117 /* Kuroutoshikou CMI8787-HG2PCI */
@@ -827,6 +830,11 @@ static int __devinit get_oxygen_model(struct oxygen *chip,
827 break; 830 break;
828 case MODEL_XONAR_DG: 831 case MODEL_XONAR_DG:
829 chip->model = model_xonar_dg; 832 chip->model = model_xonar_dg;
833 chip->model.shortname = "Xonar DG";
834 break;
835 case MODEL_XONAR_DGX:
836 chip->model = model_xonar_dg;
837 chip->model.shortname = "Xonar DGX";
830 break; 838 break;
831 } 839 }
832 if (id->driver_data == MODEL_MERIDIAN || 840 if (id->driver_data == MODEL_MERIDIAN ||
@@ -870,15 +878,4 @@ static struct pci_driver oxygen_driver = {
870#endif 878#endif
871}; 879};
872 880
873static int __init alsa_card_oxygen_init(void) 881module_pci_driver(oxygen_driver);
874{
875 return pci_register_driver(&oxygen_driver);
876}
877
878static void __exit alsa_card_oxygen_exit(void)
879{
880 pci_unregister_driver(&oxygen_driver);
881}
882
883module_init(alsa_card_oxygen_init)
884module_exit(alsa_card_oxygen_exit)
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c
index 3fdee4950174..19962c6d38c3 100644
--- a/sound/pci/oxygen/virtuoso.c
+++ b/sound/pci/oxygen/virtuoso.c
@@ -100,15 +100,4 @@ static struct pci_driver xonar_driver = {
100 .shutdown = oxygen_pci_shutdown, 100 .shutdown = oxygen_pci_shutdown,
101}; 101};
102 102
103static int __init alsa_card_xonar_init(void) 103module_pci_driver(xonar_driver);
104{
105 return pci_register_driver(&xonar_driver);
106}
107
108static void __exit alsa_card_xonar_exit(void)
109{
110 pci_unregister_driver(&xonar_driver);
111}
112
113module_init(alsa_card_xonar_init)
114module_exit(alsa_card_xonar_exit)
diff --git a/sound/pci/oxygen/xonar_dg.c b/sound/pci/oxygen/xonar_dg.c
index 793bdf03d7e0..77acd790ea47 100644
--- a/sound/pci/oxygen/xonar_dg.c
+++ b/sound/pci/oxygen/xonar_dg.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * card driver for the Xonar DG 2 * card driver for the Xonar DG/DGX
3 * 3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de> 4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * 5 *
@@ -17,8 +17,8 @@
17 */ 17 */
18 18
19/* 19/*
20 * Xonar DG 20 * Xonar DG/DGX
21 * -------- 21 * ------------
22 * 22 *
23 * CMI8788: 23 * CMI8788:
24 * 24 *
@@ -581,7 +581,6 @@ static void dump_cs4245_registers(struct oxygen *chip,
581} 581}
582 582
583struct oxygen_model model_xonar_dg = { 583struct oxygen_model model_xonar_dg = {
584 .shortname = "Xonar DG",
585 .longname = "C-Media Oxygen HD Audio", 584 .longname = "C-Media Oxygen HD Audio",
586 .chip = "CMI8786", 585 .chip = "CMI8786",
587 .init = dg_init, 586 .init = dg_init,
diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c
index fd1809ab73b4..0435f45e9513 100644
--- a/sound/pci/pcxhr/pcxhr.c
+++ b/sound/pci/pcxhr/pcxhr.c
@@ -1607,22 +1607,11 @@ static void __devexit pcxhr_remove(struct pci_dev *pci)
1607 pci_set_drvdata(pci, NULL); 1607 pci_set_drvdata(pci, NULL);
1608} 1608}
1609 1609
1610static struct pci_driver driver = { 1610static struct pci_driver pcxhr_driver = {
1611 .name = KBUILD_MODNAME, 1611 .name = KBUILD_MODNAME,
1612 .id_table = pcxhr_ids, 1612 .id_table = pcxhr_ids,
1613 .probe = pcxhr_probe, 1613 .probe = pcxhr_probe,
1614 .remove = __devexit_p(pcxhr_remove), 1614 .remove = __devexit_p(pcxhr_remove),
1615}; 1615};
1616 1616
1617static int __init pcxhr_module_init(void) 1617module_pci_driver(pcxhr_driver);
1618{
1619 return pci_register_driver(&driver);
1620}
1621
1622static void __exit pcxhr_module_exit(void)
1623{
1624 pci_unregister_driver(&driver);
1625}
1626
1627module_init(pcxhr_module_init)
1628module_exit(pcxhr_module_exit)
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index 0481d94aac9b..cbeb3f77350c 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -1837,8 +1837,7 @@ static int snd_riptide_free(struct snd_riptide *chip)
1837 } 1837 }
1838 if (chip->irq >= 0) 1838 if (chip->irq >= 0)
1839 free_irq(chip->irq, chip); 1839 free_irq(chip->irq, chip);
1840 if (chip->fw_entry) 1840 release_firmware(chip->fw_entry);
1841 release_firmware(chip->fw_entry);
1842 release_and_free_resource(chip->res_port); 1841 release_and_free_resource(chip->res_port);
1843 kfree(chip); 1842 kfree(chip);
1844 return 0; 1843 return 0;
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index b4819d5e41db..46b3629dda22 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -1984,22 +1984,11 @@ static void __devexit snd_rme32_remove(struct pci_dev *pci)
1984 pci_set_drvdata(pci, NULL); 1984 pci_set_drvdata(pci, NULL);
1985} 1985}
1986 1986
1987static struct pci_driver driver = { 1987static struct pci_driver rme32_driver = {
1988 .name = KBUILD_MODNAME, 1988 .name = KBUILD_MODNAME,
1989 .id_table = snd_rme32_ids, 1989 .id_table = snd_rme32_ids,
1990 .probe = snd_rme32_probe, 1990 .probe = snd_rme32_probe,
1991 .remove = __devexit_p(snd_rme32_remove), 1991 .remove = __devexit_p(snd_rme32_remove),
1992}; 1992};
1993 1993
1994static int __init alsa_card_rme32_init(void) 1994module_pci_driver(rme32_driver);
1995{
1996 return pci_register_driver(&driver);
1997}
1998
1999static void __exit alsa_card_rme32_exit(void)
2000{
2001 pci_unregister_driver(&driver);
2002}
2003
2004module_init(alsa_card_rme32_init)
2005module_exit(alsa_card_rme32_exit)
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index ba894158e76c..9b98dc406988 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -2395,22 +2395,11 @@ static void __devexit snd_rme96_remove(struct pci_dev *pci)
2395 pci_set_drvdata(pci, NULL); 2395 pci_set_drvdata(pci, NULL);
2396} 2396}
2397 2397
2398static struct pci_driver driver = { 2398static struct pci_driver rme96_driver = {
2399 .name = KBUILD_MODNAME, 2399 .name = KBUILD_MODNAME,
2400 .id_table = snd_rme96_ids, 2400 .id_table = snd_rme96_ids,
2401 .probe = snd_rme96_probe, 2401 .probe = snd_rme96_probe,
2402 .remove = __devexit_p(snd_rme96_remove), 2402 .remove = __devexit_p(snd_rme96_remove),
2403}; 2403};
2404 2404
2405static int __init alsa_card_rme96_init(void) 2405module_pci_driver(rme96_driver);
2406{
2407 return pci_register_driver(&driver);
2408}
2409
2410static void __exit alsa_card_rme96_exit(void)
2411{
2412 pci_unregister_driver(&driver);
2413}
2414
2415module_init(alsa_card_rme96_init)
2416module_exit(alsa_card_rme96_exit)
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 0b2aea2ce172..0d6930c4f4b7 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -5636,22 +5636,11 @@ static void __devexit snd_hdsp_remove(struct pci_dev *pci)
5636 pci_set_drvdata(pci, NULL); 5636 pci_set_drvdata(pci, NULL);
5637} 5637}
5638 5638
5639static struct pci_driver driver = { 5639static struct pci_driver hdsp_driver = {
5640 .name = KBUILD_MODNAME, 5640 .name = KBUILD_MODNAME,
5641 .id_table = snd_hdsp_ids, 5641 .id_table = snd_hdsp_ids,
5642 .probe = snd_hdsp_probe, 5642 .probe = snd_hdsp_probe,
5643 .remove = __devexit_p(snd_hdsp_remove), 5643 .remove = __devexit_p(snd_hdsp_remove),
5644}; 5644};
5645 5645
5646static int __init alsa_card_hdsp_init(void) 5646module_pci_driver(hdsp_driver);
5647{
5648 return pci_register_driver(&driver);
5649}
5650
5651static void __exit alsa_card_hdsp_exit(void)
5652{
5653 pci_unregister_driver(&driver);
5654}
5655
5656module_init(alsa_card_hdsp_init)
5657module_exit(alsa_card_hdsp_exit)
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index bc030a2088da..0a5027b94714 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -6918,23 +6918,11 @@ static void __devexit snd_hdspm_remove(struct pci_dev *pci)
6918 pci_set_drvdata(pci, NULL); 6918 pci_set_drvdata(pci, NULL);
6919} 6919}
6920 6920
6921static struct pci_driver driver = { 6921static struct pci_driver hdspm_driver = {
6922 .name = KBUILD_MODNAME, 6922 .name = KBUILD_MODNAME,
6923 .id_table = snd_hdspm_ids, 6923 .id_table = snd_hdspm_ids,
6924 .probe = snd_hdspm_probe, 6924 .probe = snd_hdspm_probe,
6925 .remove = __devexit_p(snd_hdspm_remove), 6925 .remove = __devexit_p(snd_hdspm_remove),
6926}; 6926};
6927 6927
6928 6928module_pci_driver(hdspm_driver);
6929static int __init alsa_card_hdspm_init(void)
6930{
6931 return pci_register_driver(&driver);
6932}
6933
6934static void __exit alsa_card_hdspm_exit(void)
6935{
6936 pci_unregister_driver(&driver);
6937}
6938
6939module_init(alsa_card_hdspm_init)
6940module_exit(alsa_card_hdspm_exit)
diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
index b737d1619cc7..a15fc100ab0c 100644
--- a/sound/pci/rme9652/rme9652.c
+++ b/sound/pci/rme9652/rme9652.c
@@ -2631,22 +2631,11 @@ static void __devexit snd_rme9652_remove(struct pci_dev *pci)
2631 pci_set_drvdata(pci, NULL); 2631 pci_set_drvdata(pci, NULL);
2632} 2632}
2633 2633
2634static struct pci_driver driver = { 2634static struct pci_driver rme9652_driver = {
2635 .name = KBUILD_MODNAME, 2635 .name = KBUILD_MODNAME,
2636 .id_table = snd_rme9652_ids, 2636 .id_table = snd_rme9652_ids,
2637 .probe = snd_rme9652_probe, 2637 .probe = snd_rme9652_probe,
2638 .remove = __devexit_p(snd_rme9652_remove), 2638 .remove = __devexit_p(snd_rme9652_remove),
2639}; 2639};
2640 2640
2641static int __init alsa_card_hammerfall_init(void) 2641module_pci_driver(rme9652_driver);
2642{
2643 return pci_register_driver(&driver);
2644}
2645
2646static void __exit alsa_card_hammerfall_exit(void)
2647{
2648 pci_unregister_driver(&driver);
2649}
2650
2651module_init(alsa_card_hammerfall_init)
2652module_exit(alsa_card_hammerfall_exit)
diff --git a/sound/pci/sis7019.c b/sound/pci/sis7019.c
index ff500a87f769..1552642765d6 100644
--- a/sound/pci/sis7019.c
+++ b/sound/pci/sis7019.c
@@ -1488,15 +1488,4 @@ static struct pci_driver sis7019_driver = {
1488#endif 1488#endif
1489}; 1489};
1490 1490
1491static int __init sis7019_init(void) 1491module_pci_driver(sis7019_driver);
1492{
1493 return pci_register_driver(&sis7019_driver);
1494}
1495
1496static void __exit sis7019_exit(void)
1497{
1498 pci_unregister_driver(&sis7019_driver);
1499}
1500
1501module_init(sis7019_init);
1502module_exit(sis7019_exit);
diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
index 54cc802050f7..baa9946bedf0 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -1530,22 +1530,11 @@ static void __devexit snd_sonic_remove(struct pci_dev *pci)
1530 pci_set_drvdata(pci, NULL); 1530 pci_set_drvdata(pci, NULL);
1531} 1531}
1532 1532
1533static struct pci_driver driver = { 1533static struct pci_driver sonicvibes_driver = {
1534 .name = KBUILD_MODNAME, 1534 .name = KBUILD_MODNAME,
1535 .id_table = snd_sonic_ids, 1535 .id_table = snd_sonic_ids,
1536 .probe = snd_sonic_probe, 1536 .probe = snd_sonic_probe,
1537 .remove = __devexit_p(snd_sonic_remove), 1537 .remove = __devexit_p(snd_sonic_remove),
1538}; 1538};
1539 1539
1540static int __init alsa_card_sonicvibes_init(void) 1540module_pci_driver(sonicvibes_driver);
1541{
1542 return pci_register_driver(&driver);
1543}
1544
1545static void __exit alsa_card_sonicvibes_exit(void)
1546{
1547 pci_unregister_driver(&driver);
1548}
1549
1550module_init(alsa_card_sonicvibes_init)
1551module_exit(alsa_card_sonicvibes_exit)
diff --git a/sound/pci/trident/trident.c b/sound/pci/trident/trident.c
index 5f1def7f45e5..611983ec7321 100644
--- a/sound/pci/trident/trident.c
+++ b/sound/pci/trident/trident.c
@@ -172,7 +172,7 @@ static void __devexit snd_trident_remove(struct pci_dev *pci)
172 pci_set_drvdata(pci, NULL); 172 pci_set_drvdata(pci, NULL);
173} 173}
174 174
175static struct pci_driver driver = { 175static struct pci_driver trident_driver = {
176 .name = KBUILD_MODNAME, 176 .name = KBUILD_MODNAME,
177 .id_table = snd_trident_ids, 177 .id_table = snd_trident_ids,
178 .probe = snd_trident_probe, 178 .probe = snd_trident_probe,
@@ -183,15 +183,4 @@ static struct pci_driver driver = {
183#endif 183#endif
184}; 184};
185 185
186static int __init alsa_card_trident_init(void) 186module_pci_driver(trident_driver);
187{
188 return pci_register_driver(&driver);
189}
190
191static void __exit alsa_card_trident_exit(void)
192{
193 pci_unregister_driver(&driver);
194}
195
196module_init(alsa_card_trident_init)
197module_exit(alsa_card_trident_exit)
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index 75630408c6db..b5afab48943e 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -2619,7 +2619,7 @@ static void __devexit snd_via82xx_remove(struct pci_dev *pci)
2619 pci_set_drvdata(pci, NULL); 2619 pci_set_drvdata(pci, NULL);
2620} 2620}
2621 2621
2622static struct pci_driver driver = { 2622static struct pci_driver via82xx_driver = {
2623 .name = KBUILD_MODNAME, 2623 .name = KBUILD_MODNAME,
2624 .id_table = snd_via82xx_ids, 2624 .id_table = snd_via82xx_ids,
2625 .probe = snd_via82xx_probe, 2625 .probe = snd_via82xx_probe,
@@ -2630,15 +2630,4 @@ static struct pci_driver driver = {
2630#endif 2630#endif
2631}; 2631};
2632 2632
2633static int __init alsa_card_via82xx_init(void) 2633module_pci_driver(via82xx_driver);
2634{
2635 return pci_register_driver(&driver);
2636}
2637
2638static void __exit alsa_card_via82xx_exit(void)
2639{
2640 pci_unregister_driver(&driver);
2641}
2642
2643module_init(alsa_card_via82xx_init)
2644module_exit(alsa_card_via82xx_exit)
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c
index 5efcbcac506a..59fd47ed0a31 100644
--- a/sound/pci/via82xx_modem.c
+++ b/sound/pci/via82xx_modem.c
@@ -1223,7 +1223,7 @@ static void __devexit snd_via82xx_remove(struct pci_dev *pci)
1223 pci_set_drvdata(pci, NULL); 1223 pci_set_drvdata(pci, NULL);
1224} 1224}
1225 1225
1226static struct pci_driver driver = { 1226static struct pci_driver via82xx_modem_driver = {
1227 .name = KBUILD_MODNAME, 1227 .name = KBUILD_MODNAME,
1228 .id_table = snd_via82xx_modem_ids, 1228 .id_table = snd_via82xx_modem_ids,
1229 .probe = snd_via82xx_probe, 1229 .probe = snd_via82xx_probe,
@@ -1234,15 +1234,4 @@ static struct pci_driver driver = {
1234#endif 1234#endif
1235}; 1235};
1236 1236
1237static int __init alsa_card_via82xx_init(void) 1237module_pci_driver(via82xx_modem_driver);
1238{
1239 return pci_register_driver(&driver);
1240}
1241
1242static void __exit alsa_card_via82xx_exit(void)
1243{
1244 pci_unregister_driver(&driver);
1245}
1246
1247module_init(alsa_card_via82xx_init)
1248module_exit(alsa_card_via82xx_exit)
diff --git a/sound/pci/vx222/vx222.c b/sound/pci/vx222/vx222.c
index 6a534bfe1274..1ea1f656a5dc 100644
--- a/sound/pci/vx222/vx222.c
+++ b/sound/pci/vx222/vx222.c
@@ -289,7 +289,7 @@ static int snd_vx222_resume(struct pci_dev *pci)
289} 289}
290#endif 290#endif
291 291
292static struct pci_driver driver = { 292static struct pci_driver vx222_driver = {
293 .name = KBUILD_MODNAME, 293 .name = KBUILD_MODNAME,
294 .id_table = snd_vx222_ids, 294 .id_table = snd_vx222_ids,
295 .probe = snd_vx222_probe, 295 .probe = snd_vx222_probe,
@@ -300,15 +300,4 @@ static struct pci_driver driver = {
300#endif 300#endif
301}; 301};
302 302
303static int __init alsa_card_vx222_init(void) 303module_pci_driver(vx222_driver);
304{
305 return pci_register_driver(&driver);
306}
307
308static void __exit alsa_card_vx222_exit(void)
309{
310 pci_unregister_driver(&driver);
311}
312
313module_init(alsa_card_vx222_init)
314module_exit(alsa_card_vx222_exit)
diff --git a/sound/pci/ymfpci/ymfpci.c b/sound/pci/ymfpci/ymfpci.c
index 94ab728f5ca8..9a1d01d653a7 100644
--- a/sound/pci/ymfpci/ymfpci.c
+++ b/sound/pci/ymfpci/ymfpci.c
@@ -350,7 +350,7 @@ static void __devexit snd_card_ymfpci_remove(struct pci_dev *pci)
350 pci_set_drvdata(pci, NULL); 350 pci_set_drvdata(pci, NULL);
351} 351}
352 352
353static struct pci_driver driver = { 353static struct pci_driver ymfpci_driver = {
354 .name = KBUILD_MODNAME, 354 .name = KBUILD_MODNAME,
355 .id_table = snd_ymfpci_ids, 355 .id_table = snd_ymfpci_ids,
356 .probe = snd_card_ymfpci_probe, 356 .probe = snd_card_ymfpci_probe,
@@ -361,15 +361,4 @@ static struct pci_driver driver = {
361#endif 361#endif
362}; 362};
363 363
364static int __init alsa_card_ymfpci_init(void) 364module_pci_driver(ymfpci_driver);
365{
366 return pci_register_driver(&driver);
367}
368
369static void __exit alsa_card_ymfpci_exit(void)
370{
371 pci_unregister_driver(&driver);
372}
373
374module_init(alsa_card_ymfpci_init)
375module_exit(alsa_card_ymfpci_exit)
diff --git a/sound/sh/sh_dac_audio.c b/sound/sh/sh_dac_audio.c
index b11f82b5718f..f8b01c77b298 100644
--- a/sound/sh/sh_dac_audio.c
+++ b/sound/sh/sh_dac_audio.c
@@ -433,7 +433,7 @@ probe_error:
433/* 433/*
434 * "driver" definition 434 * "driver" definition
435 */ 435 */
436static struct platform_driver driver = { 436static struct platform_driver sh_dac_driver = {
437 .probe = snd_sh_dac_probe, 437 .probe = snd_sh_dac_probe,
438 .remove = snd_sh_dac_remove, 438 .remove = snd_sh_dac_remove,
439 .driver = { 439 .driver = {
@@ -441,4 +441,4 @@ static struct platform_driver driver = {
441 }, 441 },
442}; 442};
443 443
444module_platform_driver(driver); 444module_platform_driver(sh_dac_driver);
diff --git a/sound/sound_core.c b/sound/sound_core.c
index c6e81fb928e9..fb9255cca214 100644
--- a/sound/sound_core.c
+++ b/sound/sound_core.c
@@ -361,7 +361,7 @@ int register_sound_special_device(const struct file_operations *fops, int unit,
361 struct device *dev) 361 struct device *dev)
362{ 362{
363 const int chain = unit % SOUND_STEP; 363 const int chain = unit % SOUND_STEP;
364 int max_unit = 128 + chain; 364 int max_unit = 256;
365 const char *name; 365 const char *name;
366 char _name[16]; 366 char _name[16];
367 367
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 4a7be7b98331..d5b5c3388e28 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -131,8 +131,9 @@ static void snd_usb_stream_disconnect(struct list_head *head)
131 subs = &as->substream[idx]; 131 subs = &as->substream[idx];
132 if (!subs->num_formats) 132 if (!subs->num_formats)
133 continue; 133 continue;
134 snd_usb_release_substream_urbs(subs, 1);
135 subs->interface = -1; 134 subs->interface = -1;
135 subs->data_endpoint = NULL;
136 subs->sync_endpoint = NULL;
136 } 137 }
137} 138}
138 139
@@ -276,6 +277,7 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
276 277
277static int snd_usb_audio_free(struct snd_usb_audio *chip) 278static int snd_usb_audio_free(struct snd_usb_audio *chip)
278{ 279{
280 mutex_destroy(&chip->mutex);
279 kfree(chip); 281 kfree(chip);
280 return 0; 282 return 0;
281} 283}
@@ -336,6 +338,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
336 return -ENOMEM; 338 return -ENOMEM;
337 } 339 }
338 340
341 mutex_init(&chip->mutex);
339 mutex_init(&chip->shutdown_mutex); 342 mutex_init(&chip->shutdown_mutex);
340 chip->index = idx; 343 chip->index = idx;
341 chip->dev = dev; 344 chip->dev = dev;
@@ -348,6 +351,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
348 chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), 351 chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
349 le16_to_cpu(dev->descriptor.idProduct)); 352 le16_to_cpu(dev->descriptor.idProduct));
350 INIT_LIST_HEAD(&chip->pcm_list); 353 INIT_LIST_HEAD(&chip->pcm_list);
354 INIT_LIST_HEAD(&chip->ep_list);
351 INIT_LIST_HEAD(&chip->midi_list); 355 INIT_LIST_HEAD(&chip->midi_list);
352 INIT_LIST_HEAD(&chip->mixer_list); 356 INIT_LIST_HEAD(&chip->mixer_list);
353 357
@@ -565,6 +569,10 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
565 list_for_each(p, &chip->pcm_list) { 569 list_for_each(p, &chip->pcm_list) {
566 snd_usb_stream_disconnect(p); 570 snd_usb_stream_disconnect(p);
567 } 571 }
572 /* release the endpoint resources */
573 list_for_each(p, &chip->ep_list) {
574 snd_usb_endpoint_free(p);
575 }
568 /* release the midi resources */ 576 /* release the midi resources */
569 list_for_each(p, &chip->midi_list) { 577 list_for_each(p, &chip->midi_list) {
570 snd_usbmidi_disconnect(p); 578 snd_usbmidi_disconnect(p);
diff --git a/sound/usb/card.h b/sound/usb/card.h
index da5fa1ac4eda..0d37238b8457 100644
--- a/sound/usb/card.h
+++ b/sound/usb/card.h
@@ -30,20 +30,71 @@ struct audioformat {
30}; 30};
31 31
32struct snd_usb_substream; 32struct snd_usb_substream;
33struct snd_usb_endpoint;
33 34
34struct snd_urb_ctx { 35struct snd_urb_ctx {
35 struct urb *urb; 36 struct urb *urb;
36 unsigned int buffer_size; /* size of data buffer, if data URB */ 37 unsigned int buffer_size; /* size of data buffer, if data URB */
37 struct snd_usb_substream *subs; 38 struct snd_usb_substream *subs;
39 struct snd_usb_endpoint *ep;
38 int index; /* index for urb array */ 40 int index; /* index for urb array */
39 int packets; /* number of packets per urb */ 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
42struct snd_urb_ops { 46struct snd_usb_endpoint {
43 int (*prepare)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u); 47 struct snd_usb_audio *chip;
44 int (*retire)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u); 48
45 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u); 49 int use_count;
46 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u); 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
49struct snd_usb_substream { 100struct snd_usb_substream {
@@ -57,21 +108,6 @@ struct snd_usb_substream {
57 unsigned int cur_rate; /* current rate (for hw_params callback) */ 108 unsigned int cur_rate; /* current rate (for hw_params callback) */
58 unsigned int period_bytes; /* current period bytes (for hw_params callback) */ 109 unsigned int period_bytes; /* current period bytes (for hw_params callback) */
59 unsigned int altset_idx; /* USB data format: index of alternate setting */ 110 unsigned int altset_idx; /* USB data format: index of alternate setting */
60 unsigned int datapipe; /* the data i/o pipe */
61 unsigned int syncpipe; /* 1 - async out or adaptive in */
62 unsigned int datainterval; /* log_2 of data packet interval */
63 unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */
64 unsigned int freqn; /* nominal sampling rate in fs/fps in Q16.16 format */
65 unsigned int freqm; /* momentary sampling rate in fs/fps in Q16.16 format */
66 int freqshift; /* how much to shift the feedback value to get Q16.16 */
67 unsigned int freqmax; /* maximum sampling rate, used for buffer management */
68 unsigned int phase; /* phase accumulator */
69 unsigned int maxpacksize; /* max packet size in bytes */
70 unsigned int maxframesize; /* max packet size in frames */
71 unsigned int curpacksize; /* current packet size in bytes (for capture) */
72 unsigned int curframesize; /* current packet size in frames (for capture) */
73 unsigned int syncmaxsize; /* sync endpoint packet size */
74 unsigned int fill_max: 1; /* fill max packet size always */
75 unsigned int txfr_quirk:1; /* allow sub-frame alignment */ 111 unsigned int txfr_quirk:1; /* allow sub-frame alignment */
76 unsigned int fmt_type; /* USB audio format type (1-3) */ 112 unsigned int fmt_type; /* USB audio format type (1-3) */
77 113
@@ -82,11 +118,10 @@ struct snd_usb_substream {
82 unsigned long active_mask; /* bitmask of active urbs */ 118 unsigned long active_mask; /* bitmask of active urbs */
83 unsigned long unlink_mask; /* bitmask of unlinked urbs */ 119 unsigned long unlink_mask; /* bitmask of unlinked urbs */
84 120
85 unsigned int nurbs; /* # urbs */ 121 /* data and sync endpoints for this stream */
86 struct snd_urb_ctx dataurb[MAX_URBS]; /* data urb table */ 122 struct snd_usb_endpoint *data_endpoint;
87 struct snd_urb_ctx syncurb[SYNC_URBS]; /* sync urb table */ 123 struct snd_usb_endpoint *sync_endpoint;
88 char *syncbuf; /* sync buffer for all sync URBs */ 124 unsigned long flags;
89 dma_addr_t sync_dma; /* DMA address of syncbuf */
90 125
91 u64 formats; /* format bitmasks (all or'ed) */ 126 u64 formats; /* format bitmasks (all or'ed) */
92 unsigned int num_formats; /* number of supported audio formats (list) */ 127 unsigned int num_formats; /* number of supported audio formats (list) */
@@ -94,7 +129,6 @@ struct snd_usb_substream {
94 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */ 129 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
95 spinlock_t lock; 130 spinlock_t lock;
96 131
97 struct snd_urb_ops ops; /* callbacks (must be filled at init) */
98 int last_frame_number; /* stored frame number */ 132 int last_frame_number; /* stored frame number */
99 int last_delay; /* stored delay */ 133 int last_delay; /* stored delay */
100}; 134};
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index 08dcce53720b..e6906901debb 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -20,9 +20,11 @@
20#include <linux/ratelimit.h> 20#include <linux/ratelimit.h>
21#include <linux/usb.h> 21#include <linux/usb.h>
22#include <linux/usb/audio.h> 22#include <linux/usb/audio.h>
23#include <linux/slab.h>
23 24
24#include <sound/core.h> 25#include <sound/core.h>
25#include <sound/pcm.h> 26#include <sound/pcm.h>
27#include <sound/pcm_params.h>
26 28
27#include "usbaudio.h" 29#include "usbaudio.h"
28#include "helper.h" 30#include "helper.h"
@@ -30,6 +32,36 @@
30#include "endpoint.h" 32#include "endpoint.h"
31#include "pcm.h" 33#include "pcm.h"
32 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 */
64
33/* 65/*
34 * convert a sampling rate into our full speed format (fs/1000 in Q16.16) 66 * convert a sampling rate into our full speed format (fs/1000 in Q16.16)
35 * this will overflow at approx 524 kHz 67 * this will overflow at approx 524 kHz
@@ -49,71 +81,415 @@ static inline unsigned get_usb_high_speed_rate(unsigned int rate)
49} 81}
50 82
51/* 83/*
52 * unlink active urbs. 84 * release a urb data
53 */ 85 */
54static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sleep) 86static void release_urb_ctx(struct snd_urb_ctx *u)
55{ 87{
56 struct snd_usb_audio *chip = subs->stream->chip; 88 if (u->buffer_size)
57 unsigned int i; 89 usb_free_coherent(u->ep->chip->dev, u->buffer_size,
58 int async; 90 u->urb->transfer_buffer,
91 u->urb->transfer_dma);
92 usb_free_urb(u->urb);
93 u->urb = NULL;
94}
95
96static const char *usb_error_string(int err)
97{
98 switch (err) {
99 case -ENODEV:
100 return "no device";
101 case -ENOENT:
102 return "endpoint not enabled";
103 case -EPIPE:
104 return "endpoint stalled";
105 case -ENOSPC:
106 return "not enough bandwidth";
107 case -ESHUTDOWN:
108 return "device disabled";
109 case -EHOSTUNREACH:
110 return "device suspended";
111 case -EINVAL:
112 case -EAGAIN:
113 case -EFBIG:
114 case -EMSGSIZE:
115 return "internal error";
116 default:
117 return "unknown error";
118 }
119}
120
121/**
122 * snd_usb_endpoint_implicit_feedback_sink: Report endpoint usage type
123 *
124 * @ep: The snd_usb_endpoint
125 *
126 * Determine whether an endpoint is driven by an implicit feedback
127 * data endpoint source.
128 */
129int snd_usb_endpoint_implict_feedback_sink(struct snd_usb_endpoint *ep)
130{
131 return ep->sync_master &&
132 ep->sync_master->type == SND_USB_ENDPOINT_TYPE_DATA &&
133 ep->type == SND_USB_ENDPOINT_TYPE_DATA &&
134 usb_pipeout(ep->pipe);
135}
59 136
60 subs->running = 0; 137/*
138 * For streaming based on information derived from sync endpoints,
139 * prepare_outbound_urb_sizes() will call next_packet_size() to
140 * determine the number of samples to be sent in the next packet.
141 *
142 * For implicit feedback, next_packet_size() is unused.
143 */
144static int next_packet_size(struct snd_usb_endpoint *ep)
145{
146 unsigned long flags;
147 int ret;
61 148
62 if (!force && subs->stream->chip->shutdown) /* to be sure... */ 149 if (ep->fill_max)
63 return -EBADFD; 150 return ep->maxframesize;
64 151
65 async = !can_sleep && chip->async_unlink; 152 spin_lock_irqsave(&ep->lock, flags);
153 ep->phase = (ep->phase & 0xffff)
154 + (ep->freqm << ep->datainterval);
155 ret = min(ep->phase >> 16, ep->maxframesize);
156 spin_unlock_irqrestore(&ep->lock, flags);
66 157
67 if (!async && in_interrupt()) 158 return ret;
68 return 0; 159}
69 160
70 for (i = 0; i < subs->nurbs; i++) { 161static void retire_outbound_urb(struct snd_usb_endpoint *ep,
71 if (test_bit(i, &subs->active_mask)) { 162 struct snd_urb_ctx *urb_ctx)
72 if (!test_and_set_bit(i, &subs->unlink_mask)) { 163{
73 struct urb *u = subs->dataurb[i].urb; 164 if (ep->retire_data_urb)
74 if (async) 165 ep->retire_data_urb(ep->data_subs, urb_ctx->urb);
75 usb_unlink_urb(u); 166}
76 else 167
77 usb_kill_urb(u); 168static void retire_inbound_urb(struct snd_usb_endpoint *ep,
169 struct snd_urb_ctx *urb_ctx)
170{
171 struct urb *urb = urb_ctx->urb;
172
173 if (ep->sync_slave)
174 snd_usb_handle_sync_urb(ep->sync_slave, ep, urb);
175
176 if (ep->retire_data_urb)
177 ep->retire_data_urb(ep->data_subs, urb);
178}
179
180static void prepare_outbound_urb_sizes(struct snd_usb_endpoint *ep,
181 struct snd_urb_ctx *ctx)
182{
183 int i;
184
185 for (i = 0; i < ctx->packets; ++i)
186 ctx->packet_size[i] = next_packet_size(ep);
187}
188
189/*
190 * Prepare a PLAYBACK urb for submission to the bus.
191 */
192static void prepare_outbound_urb(struct snd_usb_endpoint *ep,
193 struct snd_urb_ctx *ctx)
194{
195 int i;
196 struct urb *urb = ctx->urb;
197 unsigned char *cp = urb->transfer_buffer;
198
199 urb->dev = ep->chip->dev; /* we need to set this at each time */
200
201 switch (ep->type) {
202 case SND_USB_ENDPOINT_TYPE_DATA:
203 if (ep->prepare_data_urb) {
204 ep->prepare_data_urb(ep->data_subs, urb);
205 } else {
206 /* no data provider, so send silence */
207 unsigned int offs = 0;
208 for (i = 0; i < ctx->packets; ++i) {
209 int counts = ctx->packet_size[i];
210 urb->iso_frame_desc[i].offset = offs * ep->stride;
211 urb->iso_frame_desc[i].length = counts * ep->stride;
212 offs += counts;
78 } 213 }
214
215 urb->number_of_packets = ctx->packets;
216 urb->transfer_buffer_length = offs * ep->stride;
217 memset(urb->transfer_buffer, ep->silence_value,
218 offs * ep->stride);
79 } 219 }
220 break;
221
222 case SND_USB_ENDPOINT_TYPE_SYNC:
223 if (snd_usb_get_speed(ep->chip->dev) >= USB_SPEED_HIGH) {
224 /*
225 * fill the length and offset of each urb descriptor.
226 * the fixed 12.13 frequency is passed as 16.16 through the pipe.
227 */
228 urb->iso_frame_desc[0].length = 4;
229 urb->iso_frame_desc[0].offset = 0;
230 cp[0] = ep->freqn;
231 cp[1] = ep->freqn >> 8;
232 cp[2] = ep->freqn >> 16;
233 cp[3] = ep->freqn >> 24;
234 } else {
235 /*
236 * fill the length and offset of each urb descriptor.
237 * the fixed 10.14 frequency is passed through the pipe.
238 */
239 urb->iso_frame_desc[0].length = 3;
240 urb->iso_frame_desc[0].offset = 0;
241 cp[0] = ep->freqn >> 2;
242 cp[1] = ep->freqn >> 10;
243 cp[2] = ep->freqn >> 18;
244 }
245
246 break;
80 } 247 }
81 if (subs->syncpipe) { 248}
82 for (i = 0; i < SYNC_URBS; i++) { 249
83 if (test_bit(i+16, &subs->active_mask)) { 250/*
84 if (!test_and_set_bit(i+16, &subs->unlink_mask)) { 251 * Prepare a CAPTURE or SYNC urb for submission to the bus.
85 struct urb *u = subs->syncurb[i].urb; 252 */
86 if (async) 253static inline void prepare_inbound_urb(struct snd_usb_endpoint *ep,
87 usb_unlink_urb(u); 254 struct snd_urb_ctx *urb_ctx)
88 else 255{
89 usb_kill_urb(u); 256 int i, offs;
90 } 257 struct urb *urb = urb_ctx->urb;
91 } 258
259 urb->dev = ep->chip->dev; /* we need to set this at each time */
260
261 switch (ep->type) {
262 case SND_USB_ENDPOINT_TYPE_DATA:
263 offs = 0;
264 for (i = 0; i < urb_ctx->packets; i++) {
265 urb->iso_frame_desc[i].offset = offs;
266 urb->iso_frame_desc[i].length = ep->curpacksize;
267 offs += ep->curpacksize;
92 } 268 }
269
270 urb->transfer_buffer_length = offs;
271 urb->number_of_packets = urb_ctx->packets;
272 break;
273
274 case SND_USB_ENDPOINT_TYPE_SYNC:
275 urb->iso_frame_desc[0].length = min(4u, ep->syncmaxsize);
276 urb->iso_frame_desc[0].offset = 0;
277 break;
93 } 278 }
94 return 0;
95} 279}
96 280
281/*
282 * Send output urbs that have been prepared previously. URBs are dequeued
283 * from ep->ready_playback_urbs and in case there there aren't any available
284 * or there are no packets that have been prepared, this function does
285 * nothing.
286 *
287 * The reason why the functionality of sending and preparing URBs is separated
288 * is that host controllers don't guarantee the order in which they return
289 * inbound and outbound packets to their submitters.
290 *
291 * This function is only used for implicit feedback endpoints. For endpoints
292 * driven by dedicated sync endpoints, URBs are immediately re-submitted
293 * from their completion handler.
294 */
295static void queue_pending_output_urbs(struct snd_usb_endpoint *ep)
296{
297 while (test_bit(EP_FLAG_RUNNING, &ep->flags)) {
298
299 unsigned long flags;
300 struct snd_usb_packet_info *uninitialized_var(packet);
301 struct snd_urb_ctx *ctx = NULL;
302 struct urb *urb;
303 int err, i;
304
305 spin_lock_irqsave(&ep->lock, flags);
306 if (ep->next_packet_read_pos != ep->next_packet_write_pos) {
307 packet = ep->next_packet + ep->next_packet_read_pos;
308 ep->next_packet_read_pos++;
309 ep->next_packet_read_pos %= MAX_URBS;
310
311 /* take URB out of FIFO */
312 if (!list_empty(&ep->ready_playback_urbs))
313 ctx = list_first_entry(&ep->ready_playback_urbs,
314 struct snd_urb_ctx, ready_list);
315 }
316 spin_unlock_irqrestore(&ep->lock, flags);
317
318 if (ctx == NULL)
319 return;
320
321 list_del_init(&ctx->ready_list);
322 urb = ctx->urb;
323
324 /* copy over the length information */
325 for (i = 0; i < packet->packets; i++)
326 ctx->packet_size[i] = packet->packet_size[i];
327
328 /* call the data handler to fill in playback data */
329 prepare_outbound_urb(ep, ctx);
330
331 err = usb_submit_urb(ctx->urb, GFP_ATOMIC);
332 if (err < 0)
333 snd_printk(KERN_ERR "Unable to submit urb #%d: %d (urb %p)\n",
334 ctx->index, err, ctx->urb);
335 else
336 set_bit(ctx->index, &ep->active_mask);
337 }
338}
97 339
98/* 340/*
99 * release a urb data 341 * complete callback for urbs
100 */ 342 */
101static void release_urb_ctx(struct snd_urb_ctx *u) 343static void snd_complete_urb(struct urb *urb)
344{
345 struct snd_urb_ctx *ctx = urb->context;
346 struct snd_usb_endpoint *ep = ctx->ep;
347 int err;
348
349 if (unlikely(urb->status == -ENOENT || /* unlinked */
350 urb->status == -ENODEV || /* device removed */
351 urb->status == -ECONNRESET || /* unlinked */
352 urb->status == -ESHUTDOWN || /* device disabled */
353 ep->chip->shutdown)) /* device disconnected */
354 goto exit_clear;
355
356 if (usb_pipeout(ep->pipe)) {
357 retire_outbound_urb(ep, ctx);
358 /* can be stopped during retire callback */
359 if (unlikely(!test_bit(EP_FLAG_RUNNING, &ep->flags)))
360 goto exit_clear;
361
362 if (snd_usb_endpoint_implict_feedback_sink(ep)) {
363 unsigned long flags;
364
365 spin_lock_irqsave(&ep->lock, flags);
366 list_add_tail(&ctx->ready_list, &ep->ready_playback_urbs);
367 spin_unlock_irqrestore(&ep->lock, flags);
368 queue_pending_output_urbs(ep);
369
370 goto exit_clear;
371 }
372
373 prepare_outbound_urb_sizes(ep, ctx);
374 prepare_outbound_urb(ep, ctx);
375 } else {
376 retire_inbound_urb(ep, ctx);
377 /* can be stopped during retire callback */
378 if (unlikely(!test_bit(EP_FLAG_RUNNING, &ep->flags)))
379 goto exit_clear;
380
381 prepare_inbound_urb(ep, ctx);
382 }
383
384 err = usb_submit_urb(urb, GFP_ATOMIC);
385 if (err == 0)
386 return;
387
388 snd_printk(KERN_ERR "cannot submit urb (err = %d)\n", err);
389 //snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
390
391exit_clear:
392 clear_bit(ctx->index, &ep->active_mask);
393}
394
395/**
396 * snd_usb_add_endpoint: Add an endpoint to an USB audio chip
397 *
398 * @chip: The chip
399 * @alts: The USB host interface
400 * @ep_num: The number of the endpoint to use
401 * @direction: SNDRV_PCM_STREAM_PLAYBACK or SNDRV_PCM_STREAM_CAPTURE
402 * @type: SND_USB_ENDPOINT_TYPE_DATA or SND_USB_ENDPOINT_TYPE_SYNC
403 *
404 * If the requested endpoint has not been added to the given chip before,
405 * a new instance is created. Otherwise, a pointer to the previoulsy
406 * created instance is returned. In case of any error, NULL is returned.
407 *
408 * New endpoints will be added to chip->ep_list and must be freed by
409 * calling snd_usb_endpoint_free().
410 */
411struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
412 struct usb_host_interface *alts,
413 int ep_num, int direction, int type)
102{ 414{
103 if (u->urb) { 415 struct list_head *p;
104 if (u->buffer_size) 416 struct snd_usb_endpoint *ep;
105 usb_free_coherent(u->subs->dev, u->buffer_size, 417 int ret, is_playback = direction == SNDRV_PCM_STREAM_PLAYBACK;
106 u->urb->transfer_buffer, 418
107 u->urb->transfer_dma); 419 mutex_lock(&chip->mutex);
108 usb_free_urb(u->urb); 420
109 u->urb = NULL; 421 list_for_each(p, &chip->ep_list) {
422 ep = list_entry(p, struct snd_usb_endpoint, list);
423 if (ep->ep_num == ep_num &&
424 ep->iface == alts->desc.bInterfaceNumber &&
425 ep->alt_idx == alts->desc.bAlternateSetting) {
426 snd_printdd(KERN_DEBUG "Re-using EP %x in iface %d,%d @%p\n",
427 ep_num, ep->iface, ep->alt_idx, ep);
428 goto __exit_unlock;
429 }
430 }
431
432 snd_printdd(KERN_DEBUG "Creating new %s %s endpoint #%x\n",
433 is_playback ? "playback" : "capture",
434 type == SND_USB_ENDPOINT_TYPE_DATA ? "data" : "sync",
435 ep_num);
436
437 /* select the alt setting once so the endpoints become valid */
438 ret = usb_set_interface(chip->dev, alts->desc.bInterfaceNumber,
439 alts->desc.bAlternateSetting);
440 if (ret < 0) {
441 snd_printk(KERN_ERR "%s(): usb_set_interface() failed, ret = %d\n",
442 __func__, ret);
443 ep = NULL;
444 goto __exit_unlock;
110 } 445 }
446
447 ep = kzalloc(sizeof(*ep), GFP_KERNEL);
448 if (!ep)
449 goto __exit_unlock;
450
451 ep->chip = chip;
452 spin_lock_init(&ep->lock);
453 ep->type = type;
454 ep->ep_num = ep_num;
455 ep->iface = alts->desc.bInterfaceNumber;
456 ep->alt_idx = alts->desc.bAlternateSetting;
457 INIT_LIST_HEAD(&ep->ready_playback_urbs);
458 ep_num &= USB_ENDPOINT_NUMBER_MASK;
459
460 if (is_playback)
461 ep->pipe = usb_sndisocpipe(chip->dev, ep_num);
462 else
463 ep->pipe = usb_rcvisocpipe(chip->dev, ep_num);
464
465 if (type == SND_USB_ENDPOINT_TYPE_SYNC) {
466 if (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
467 get_endpoint(alts, 1)->bRefresh >= 1 &&
468 get_endpoint(alts, 1)->bRefresh <= 9)
469 ep->syncinterval = get_endpoint(alts, 1)->bRefresh;
470 else if (snd_usb_get_speed(chip->dev) == USB_SPEED_FULL)
471 ep->syncinterval = 1;
472 else if (get_endpoint(alts, 1)->bInterval >= 1 &&
473 get_endpoint(alts, 1)->bInterval <= 16)
474 ep->syncinterval = get_endpoint(alts, 1)->bInterval - 1;
475 else
476 ep->syncinterval = 3;
477
478 ep->syncmaxsize = le16_to_cpu(get_endpoint(alts, 1)->wMaxPacketSize);
479 }
480
481 list_add_tail(&ep->list, &chip->ep_list);
482
483__exit_unlock:
484 mutex_unlock(&chip->mutex);
485
486 return ep;
111} 487}
112 488
113/* 489/*
114 * wait until all urbs are processed. 490 * wait until all urbs are processed.
115 */ 491 */
116static int wait_clear_urbs(struct snd_usb_substream *subs) 492static int wait_clear_urbs(struct snd_usb_endpoint *ep)
117{ 493{
118 unsigned long end_time = jiffies + msecs_to_jiffies(1000); 494 unsigned long end_time = jiffies + msecs_to_jiffies(1000);
119 unsigned int i; 495 unsigned int i;
@@ -121,153 +497,148 @@ static int wait_clear_urbs(struct snd_usb_substream *subs)
121 497
122 do { 498 do {
123 alive = 0; 499 alive = 0;
124 for (i = 0; i < subs->nurbs; i++) { 500 for (i = 0; i < ep->nurbs; i++)
125 if (test_bit(i, &subs->active_mask)) 501 if (test_bit(i, &ep->active_mask))
126 alive++; 502 alive++;
127 } 503
128 if (subs->syncpipe) { 504 if (!alive)
129 for (i = 0; i < SYNC_URBS; i++) {
130 if (test_bit(i + 16, &subs->active_mask))
131 alive++;
132 }
133 }
134 if (! alive)
135 break; 505 break;
506
136 schedule_timeout_uninterruptible(1); 507 schedule_timeout_uninterruptible(1);
137 } while (time_before(jiffies, end_time)); 508 } while (time_before(jiffies, end_time));
509
138 if (alive) 510 if (alive)
139 snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive); 511 snd_printk(KERN_ERR "timeout: still %d active urbs on EP #%x\n",
512 alive, ep->ep_num);
513
140 return 0; 514 return 0;
141} 515}
142 516
143/* 517/*
144 * release a substream 518 * unlink active urbs.
145 */ 519 */
146void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force) 520static int deactivate_urbs(struct snd_usb_endpoint *ep, int force, int can_sleep)
147{ 521{
148 int i; 522 unsigned int i;
523 int async;
149 524
150 /* stop urbs (to be sure) */ 525 if (!force && ep->chip->shutdown) /* to be sure... */
151 deactivate_urbs(subs, force, 1); 526 return -EBADFD;
152 wait_clear_urbs(subs);
153
154 for (i = 0; i < MAX_URBS; i++)
155 release_urb_ctx(&subs->dataurb[i]);
156 for (i = 0; i < SYNC_URBS; i++)
157 release_urb_ctx(&subs->syncurb[i]);
158 usb_free_coherent(subs->dev, SYNC_URBS * 4,
159 subs->syncbuf, subs->sync_dma);
160 subs->syncbuf = NULL;
161 subs->nurbs = 0;
162}
163 527
164/* 528 async = !can_sleep && ep->chip->async_unlink;
165 * complete callback from data urb 529
166 */ 530 clear_bit(EP_FLAG_RUNNING, &ep->flags);
167static void snd_complete_urb(struct urb *urb) 531
168{ 532 INIT_LIST_HEAD(&ep->ready_playback_urbs);
169 struct snd_urb_ctx *ctx = urb->context; 533 ep->next_packet_read_pos = 0;
170 struct snd_usb_substream *subs = ctx->subs; 534 ep->next_packet_write_pos = 0;
171 struct snd_pcm_substream *substream = ctx->subs->pcm_substream; 535
172 int err = 0; 536 if (!async && in_interrupt())
173 537 return 0;
174 if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) || 538
175 !subs->running || /* can be stopped during retire callback */ 539 for (i = 0; i < ep->nurbs; i++) {
176 (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 || 540 if (test_bit(i, &ep->active_mask)) {
177 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 541 if (!test_and_set_bit(i, &ep->unlink_mask)) {
178 clear_bit(ctx->index, &subs->active_mask); 542 struct urb *u = ep->urb[i].urb;
179 if (err < 0) { 543 if (async)
180 snd_printd(KERN_ERR "cannot submit urb (err = %d)\n", err); 544 usb_unlink_urb(u);
181 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); 545 else
546 usb_kill_urb(u);
547 }
182 } 548 }
183 } 549 }
184}
185 550
551 return 0;
552}
186 553
187/* 554/*
188 * complete callback from sync urb 555 * release an endpoint's urbs
189 */ 556 */
190static void snd_complete_sync_urb(struct urb *urb) 557static void release_urbs(struct snd_usb_endpoint *ep, int force)
191{ 558{
192 struct snd_urb_ctx *ctx = urb->context; 559 int i;
193 struct snd_usb_substream *subs = ctx->subs;
194 struct snd_pcm_substream *substream = ctx->subs->pcm_substream;
195 int err = 0;
196
197 if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) ||
198 !subs->running || /* can be stopped during retire callback */
199 (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 ||
200 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
201 clear_bit(ctx->index + 16, &subs->active_mask);
202 if (err < 0) {
203 snd_printd(KERN_ERR "cannot submit sync urb (err = %d)\n", err);
204 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
205 }
206 }
207}
208 560
561 /* route incoming urbs to nirvana */
562 ep->retire_data_urb = NULL;
563 ep->prepare_data_urb = NULL;
564
565 /* stop urbs */
566 deactivate_urbs(ep, force, 1);
567 wait_clear_urbs(ep);
568
569 for (i = 0; i < ep->nurbs; i++)
570 release_urb_ctx(&ep->urb[i]);
571
572 if (ep->syncbuf)
573 usb_free_coherent(ep->chip->dev, SYNC_URBS * 4,
574 ep->syncbuf, ep->sync_dma);
575
576 ep->syncbuf = NULL;
577 ep->nurbs = 0;
578}
209 579
210/* 580/*
211 * initialize a substream for plaback/capture 581 * configure a data endpoint
212 */ 582 */
213int snd_usb_init_substream_urbs(struct snd_usb_substream *subs, 583static int data_ep_set_params(struct snd_usb_endpoint *ep,
214 unsigned int period_bytes, 584 struct snd_pcm_hw_params *hw_params,
215 unsigned int rate, 585 struct audioformat *fmt,
216 unsigned int frame_bits) 586 struct snd_usb_endpoint *sync_ep)
217{ 587{
218 unsigned int maxsize, i; 588 unsigned int maxsize, i, urb_packs, total_packs, packs_per_ms;
219 int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK; 589 int period_bytes = params_period_bytes(hw_params);
220 unsigned int urb_packs, total_packs, packs_per_ms; 590 int format = params_format(hw_params);
221 struct snd_usb_audio *chip = subs->stream->chip; 591 int is_playback = usb_pipeout(ep->pipe);
592 int frame_bits = snd_pcm_format_physical_width(params_format(hw_params)) *
593 params_channels(hw_params);
594
595 ep->datainterval = fmt->datainterval;
596 ep->stride = frame_bits >> 3;
597 ep->silence_value = format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0;
222 598
223 /* calculate the frequency in 16.16 format */
224 if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL)
225 subs->freqn = get_usb_full_speed_rate(rate);
226 else
227 subs->freqn = get_usb_high_speed_rate(rate);
228 subs->freqm = subs->freqn;
229 subs->freqshift = INT_MIN;
230 /* calculate max. frequency */ 599 /* calculate max. frequency */
231 if (subs->maxpacksize) { 600 if (ep->maxpacksize) {
232 /* whatever fits into a max. size packet */ 601 /* whatever fits into a max. size packet */
233 maxsize = subs->maxpacksize; 602 maxsize = ep->maxpacksize;
234 subs->freqmax = (maxsize / (frame_bits >> 3)) 603 ep->freqmax = (maxsize / (frame_bits >> 3))
235 << (16 - subs->datainterval); 604 << (16 - ep->datainterval);
236 } else { 605 } else {
237 /* no max. packet size: just take 25% higher than nominal */ 606 /* no max. packet size: just take 25% higher than nominal */
238 subs->freqmax = subs->freqn + (subs->freqn >> 2); 607 ep->freqmax = ep->freqn + (ep->freqn >> 2);
239 maxsize = ((subs->freqmax + 0xffff) * (frame_bits >> 3)) 608 maxsize = ((ep->freqmax + 0xffff) * (frame_bits >> 3))
240 >> (16 - subs->datainterval); 609 >> (16 - ep->datainterval);
241 } 610 }
242 subs->phase = 0;
243 611
244 if (subs->fill_max) 612 if (ep->fill_max)
245 subs->curpacksize = subs->maxpacksize; 613 ep->curpacksize = ep->maxpacksize;
246 else 614 else
247 subs->curpacksize = maxsize; 615 ep->curpacksize = maxsize;
248 616
249 if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL) 617 if (snd_usb_get_speed(ep->chip->dev) != USB_SPEED_FULL)
250 packs_per_ms = 8 >> subs->datainterval; 618 packs_per_ms = 8 >> ep->datainterval;
251 else 619 else
252 packs_per_ms = 1; 620 packs_per_ms = 1;
253 621
254 if (is_playback) { 622 if (is_playback && !snd_usb_endpoint_implict_feedback_sink(ep)) {
255 urb_packs = max(chip->nrpacks, 1); 623 urb_packs = max(ep->chip->nrpacks, 1);
256 urb_packs = min(urb_packs, (unsigned int)MAX_PACKS); 624 urb_packs = min(urb_packs, (unsigned int) MAX_PACKS);
257 } else 625 } else {
258 urb_packs = 1; 626 urb_packs = 1;
627 }
628
259 urb_packs *= packs_per_ms; 629 urb_packs *= packs_per_ms;
260 if (subs->syncpipe) 630
261 urb_packs = min(urb_packs, 1U << subs->syncinterval); 631 if (sync_ep && !snd_usb_endpoint_implict_feedback_sink(ep))
632 urb_packs = min(urb_packs, 1U << sync_ep->syncinterval);
262 633
263 /* decide how many packets to be used */ 634 /* decide how many packets to be used */
264 if (is_playback) { 635 if (is_playback && !snd_usb_endpoint_implict_feedback_sink(ep)) {
265 unsigned int minsize, maxpacks; 636 unsigned int minsize, maxpacks;
266 /* determine how small a packet can be */ 637 /* determine how small a packet can be */
267 minsize = (subs->freqn >> (16 - subs->datainterval)) 638 minsize = (ep->freqn >> (16 - ep->datainterval))
268 * (frame_bits >> 3); 639 * (frame_bits >> 3);
269 /* with sync from device, assume it can be 12% lower */ 640 /* with sync from device, assume it can be 12% lower */
270 if (subs->syncpipe) 641 if (sync_ep)
271 minsize -= minsize >> 3; 642 minsize -= minsize >> 3;
272 minsize = max(minsize, 1u); 643 minsize = max(minsize, 1u);
273 total_packs = (period_bytes + minsize - 1) / minsize; 644 total_packs = (period_bytes + minsize - 1) / minsize;
@@ -284,284 +655,472 @@ int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
284 urb_packs >>= 1; 655 urb_packs >>= 1;
285 total_packs = MAX_URBS * urb_packs; 656 total_packs = MAX_URBS * urb_packs;
286 } 657 }
287 subs->nurbs = (total_packs + urb_packs - 1) / urb_packs; 658
288 if (subs->nurbs > MAX_URBS) { 659 ep->nurbs = (total_packs + urb_packs - 1) / urb_packs;
660 if (ep->nurbs > MAX_URBS) {
289 /* too much... */ 661 /* too much... */
290 subs->nurbs = MAX_URBS; 662 ep->nurbs = MAX_URBS;
291 total_packs = MAX_URBS * urb_packs; 663 total_packs = MAX_URBS * urb_packs;
292 } else if (subs->nurbs < 2) { 664 } else if (ep->nurbs < 2) {
293 /* too little - we need at least two packets 665 /* too little - we need at least two packets
294 * to ensure contiguous playback/capture 666 * to ensure contiguous playback/capture
295 */ 667 */
296 subs->nurbs = 2; 668 ep->nurbs = 2;
297 } 669 }
298 670
299 /* allocate and initialize data urbs */ 671 /* allocate and initialize data urbs */
300 for (i = 0; i < subs->nurbs; i++) { 672 for (i = 0; i < ep->nurbs; i++) {
301 struct snd_urb_ctx *u = &subs->dataurb[i]; 673 struct snd_urb_ctx *u = &ep->urb[i];
302 u->index = i; 674 u->index = i;
303 u->subs = subs; 675 u->ep = ep;
304 u->packets = (i + 1) * total_packs / subs->nurbs 676 u->packets = (i + 1) * total_packs / ep->nurbs
305 - i * total_packs / subs->nurbs; 677 - i * total_packs / ep->nurbs;
306 u->buffer_size = maxsize * u->packets; 678 u->buffer_size = maxsize * u->packets;
307 if (subs->fmt_type == UAC_FORMAT_TYPE_II) 679
680 if (fmt->fmt_type == UAC_FORMAT_TYPE_II)
308 u->packets++; /* for transfer delimiter */ 681 u->packets++; /* for transfer delimiter */
309 u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); 682 u->urb = usb_alloc_urb(u->packets, GFP_KERNEL);
310 if (!u->urb) 683 if (!u->urb)
311 goto out_of_memory; 684 goto out_of_memory;
685
312 u->urb->transfer_buffer = 686 u->urb->transfer_buffer =
313 usb_alloc_coherent(subs->dev, u->buffer_size, 687 usb_alloc_coherent(ep->chip->dev, u->buffer_size,
314 GFP_KERNEL, &u->urb->transfer_dma); 688 GFP_KERNEL, &u->urb->transfer_dma);
315 if (!u->urb->transfer_buffer) 689 if (!u->urb->transfer_buffer)
316 goto out_of_memory; 690 goto out_of_memory;
317 u->urb->pipe = subs->datapipe; 691 u->urb->pipe = ep->pipe;
318 u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 692 u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
319 u->urb->interval = 1 << subs->datainterval; 693 u->urb->interval = 1 << ep->datainterval;
320 u->urb->context = u; 694 u->urb->context = u;
321 u->urb->complete = snd_complete_urb; 695 u->urb->complete = snd_complete_urb;
696 INIT_LIST_HEAD(&u->ready_list);
322 } 697 }
323 698
324 if (subs->syncpipe) {
325 /* allocate and initialize sync urbs */
326 subs->syncbuf = usb_alloc_coherent(subs->dev, SYNC_URBS * 4,
327 GFP_KERNEL, &subs->sync_dma);
328 if (!subs->syncbuf)
329 goto out_of_memory;
330 for (i = 0; i < SYNC_URBS; i++) {
331 struct snd_urb_ctx *u = &subs->syncurb[i];
332 u->index = i;
333 u->subs = subs;
334 u->packets = 1;
335 u->urb = usb_alloc_urb(1, GFP_KERNEL);
336 if (!u->urb)
337 goto out_of_memory;
338 u->urb->transfer_buffer = subs->syncbuf + i * 4;
339 u->urb->transfer_dma = subs->sync_dma + i * 4;
340 u->urb->transfer_buffer_length = 4;
341 u->urb->pipe = subs->syncpipe;
342 u->urb->transfer_flags = URB_ISO_ASAP |
343 URB_NO_TRANSFER_DMA_MAP;
344 u->urb->number_of_packets = 1;
345 u->urb->interval = 1 << subs->syncinterval;
346 u->urb->context = u;
347 u->urb->complete = snd_complete_sync_urb;
348 }
349 }
350 return 0; 699 return 0;
351 700
352out_of_memory: 701out_of_memory:
353 snd_usb_release_substream_urbs(subs, 0); 702 release_urbs(ep, 0);
354 return -ENOMEM; 703 return -ENOMEM;
355} 704}
356 705
357/* 706/*
358 * prepare urb for full speed capture sync pipe 707 * configure a sync endpoint
359 *
360 * fill the length and offset of each urb descriptor.
361 * the fixed 10.14 frequency is passed through the pipe.
362 */ 708 */
363static int prepare_capture_sync_urb(struct snd_usb_substream *subs, 709static int sync_ep_set_params(struct snd_usb_endpoint *ep,
364 struct snd_pcm_runtime *runtime, 710 struct snd_pcm_hw_params *hw_params,
365 struct urb *urb) 711 struct audioformat *fmt)
366{ 712{
367 unsigned char *cp = urb->transfer_buffer; 713 int i;
368 struct snd_urb_ctx *ctx = urb->context; 714
715 ep->syncbuf = usb_alloc_coherent(ep->chip->dev, SYNC_URBS * 4,
716 GFP_KERNEL, &ep->sync_dma);
717 if (!ep->syncbuf)
718 return -ENOMEM;
719
720 for (i = 0; i < SYNC_URBS; i++) {
721 struct snd_urb_ctx *u = &ep->urb[i];
722 u->index = i;
723 u->ep = ep;
724 u->packets = 1;
725 u->urb = usb_alloc_urb(1, GFP_KERNEL);
726 if (!u->urb)
727 goto out_of_memory;
728 u->urb->transfer_buffer = ep->syncbuf + i * 4;
729 u->urb->transfer_dma = ep->sync_dma + i * 4;
730 u->urb->transfer_buffer_length = 4;
731 u->urb->pipe = ep->pipe;
732 u->urb->transfer_flags = URB_ISO_ASAP |
733 URB_NO_TRANSFER_DMA_MAP;
734 u->urb->number_of_packets = 1;
735 u->urb->interval = 1 << ep->syncinterval;
736 u->urb->context = u;
737 u->urb->complete = snd_complete_urb;
738 }
739
740 ep->nurbs = SYNC_URBS;
369 741
370 urb->dev = ctx->subs->dev; /* we need to set this at each time */
371 urb->iso_frame_desc[0].length = 3;
372 urb->iso_frame_desc[0].offset = 0;
373 cp[0] = subs->freqn >> 2;
374 cp[1] = subs->freqn >> 10;
375 cp[2] = subs->freqn >> 18;
376 return 0; 742 return 0;
743
744out_of_memory:
745 release_urbs(ep, 0);
746 return -ENOMEM;
377} 747}
378 748
379/* 749/**
380 * prepare urb for high speed capture sync pipe 750 * snd_usb_endpoint_set_params: configure an snd_usb_endpoint
751 *
752 * @ep: the snd_usb_endpoint to configure
753 * @hw_params: the hardware parameters
754 * @fmt: the USB audio format information
755 * @sync_ep: the sync endpoint to use, if any
381 * 756 *
382 * fill the length and offset of each urb descriptor. 757 * Determine the number of URBs to be used on this endpoint.
383 * the fixed 12.13 frequency is passed as 16.16 through the pipe. 758 * An endpoint must be configured before it can be started.
759 * An endpoint that is already running can not be reconfigured.
384 */ 760 */
385static int prepare_capture_sync_urb_hs(struct snd_usb_substream *subs, 761int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
386 struct snd_pcm_runtime *runtime, 762 struct snd_pcm_hw_params *hw_params,
387 struct urb *urb) 763 struct audioformat *fmt,
764 struct snd_usb_endpoint *sync_ep)
388{ 765{
389 unsigned char *cp = urb->transfer_buffer; 766 int err;
390 struct snd_urb_ctx *ctx = urb->context;
391 767
392 urb->dev = ctx->subs->dev; /* we need to set this at each time */ 768 if (ep->use_count != 0) {
393 urb->iso_frame_desc[0].length = 4; 769 snd_printk(KERN_WARNING "Unable to change format on ep #%x: already in use\n",
394 urb->iso_frame_desc[0].offset = 0; 770 ep->ep_num);
395 cp[0] = subs->freqn; 771 return -EBUSY;
396 cp[1] = subs->freqn >> 8; 772 }
397 cp[2] = subs->freqn >> 16; 773
398 cp[3] = subs->freqn >> 24; 774 /* release old buffers, if any */
399 return 0; 775 release_urbs(ep, 0);
776
777 ep->datainterval = fmt->datainterval;
778 ep->maxpacksize = fmt->maxpacksize;
779 ep->fill_max = !!(fmt->attributes & UAC_EP_CS_ATTR_FILL_MAX);
780
781 if (snd_usb_get_speed(ep->chip->dev) == USB_SPEED_FULL)
782 ep->freqn = get_usb_full_speed_rate(params_rate(hw_params));
783 else
784 ep->freqn = get_usb_high_speed_rate(params_rate(hw_params));
785
786 /* calculate the frequency in 16.16 format */
787 ep->freqm = ep->freqn;
788 ep->freqshift = INT_MIN;
789
790 ep->phase = 0;
791
792 switch (ep->type) {
793 case SND_USB_ENDPOINT_TYPE_DATA:
794 err = data_ep_set_params(ep, hw_params, fmt, sync_ep);
795 break;
796 case SND_USB_ENDPOINT_TYPE_SYNC:
797 err = sync_ep_set_params(ep, hw_params, fmt);
798 break;
799 default:
800 err = -EINVAL;
801 }
802
803 snd_printdd(KERN_DEBUG "Setting params for ep #%x (type %d, %d urbs), ret=%d\n",
804 ep->ep_num, ep->type, ep->nurbs, err);
805
806 return err;
400} 807}
401 808
402/* 809/**
403 * process after capture sync complete 810 * snd_usb_endpoint_start: start an snd_usb_endpoint
404 * - nothing to do 811 *
812 * @ep: the endpoint to start
813 *
814 * A call to this function will increment the use count of the endpoint.
815 * In case it is not already running, the URBs for this endpoint will be
816 * submitted. Otherwise, this function does nothing.
817 *
818 * Must be balanced to calls of snd_usb_endpoint_stop().
819 *
820 * Returns an error if the URB submission failed, 0 in all other cases.
405 */ 821 */
406static int retire_capture_sync_urb(struct snd_usb_substream *subs, 822int snd_usb_endpoint_start(struct snd_usb_endpoint *ep)
407 struct snd_pcm_runtime *runtime,
408 struct urb *urb)
409{ 823{
824 int err;
825 unsigned int i;
826
827 if (ep->chip->shutdown)
828 return -EBADFD;
829
830 /* already running? */
831 if (++ep->use_count != 1)
832 return 0;
833
834 if (snd_BUG_ON(!test_bit(EP_FLAG_ACTIVATED, &ep->flags)))
835 return -EINVAL;
836
837 /* just to be sure */
838 deactivate_urbs(ep, 0, 1);
839 wait_clear_urbs(ep);
840
841 ep->active_mask = 0;
842 ep->unlink_mask = 0;
843 ep->phase = 0;
844
845 /*
846 * If this endpoint has a data endpoint as implicit feedback source,
847 * don't start the urbs here. Instead, mark them all as available,
848 * wait for the record urbs to return and queue the playback urbs
849 * from that context.
850 */
851
852 set_bit(EP_FLAG_RUNNING, &ep->flags);
853
854 if (snd_usb_endpoint_implict_feedback_sink(ep)) {
855 for (i = 0; i < ep->nurbs; i++) {
856 struct snd_urb_ctx *ctx = ep->urb + i;
857 list_add_tail(&ctx->ready_list, &ep->ready_playback_urbs);
858 }
859
860 return 0;
861 }
862
863 for (i = 0; i < ep->nurbs; i++) {
864 struct urb *urb = ep->urb[i].urb;
865
866 if (snd_BUG_ON(!urb))
867 goto __error;
868
869 if (usb_pipeout(ep->pipe)) {
870 prepare_outbound_urb_sizes(ep, urb->context);
871 prepare_outbound_urb(ep, urb->context);
872 } else {
873 prepare_inbound_urb(ep, urb->context);
874 }
875
876 err = usb_submit_urb(urb, GFP_ATOMIC);
877 if (err < 0) {
878 snd_printk(KERN_ERR "cannot submit urb %d, error %d: %s\n",
879 i, err, usb_error_string(err));
880 goto __error;
881 }
882 set_bit(i, &ep->active_mask);
883 }
884
410 return 0; 885 return 0;
886
887__error:
888 clear_bit(EP_FLAG_RUNNING, &ep->flags);
889 ep->use_count--;
890 deactivate_urbs(ep, 0, 0);
891 return -EPIPE;
411} 892}
412 893
413/* 894/**
414 * prepare urb for capture data pipe 895 * snd_usb_endpoint_stop: stop an snd_usb_endpoint
896 *
897 * @ep: the endpoint to stop (may be NULL)
415 * 898 *
416 * fill the offset and length of each descriptor. 899 * A call to this function will decrement the use count of the endpoint.
900 * In case the last user has requested the endpoint stop, the URBs will
901 * actually be deactivated.
417 * 902 *
418 * we use a temporary buffer to write the captured data. 903 * Must be balanced to calls of snd_usb_endpoint_start().
419 * since the length of written data is determined by host, we cannot
420 * write onto the pcm buffer directly... the data is thus copied
421 * later at complete callback to the global buffer.
422 */ 904 */
423static int prepare_capture_urb(struct snd_usb_substream *subs, 905void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep,
424 struct snd_pcm_runtime *runtime, 906 int force, int can_sleep, int wait)
425 struct urb *urb)
426{ 907{
427 int i, offs; 908 if (!ep)
428 struct snd_urb_ctx *ctx = urb->context; 909 return;
429 910
430 offs = 0; 911 if (snd_BUG_ON(ep->use_count == 0))
431 urb->dev = ctx->subs->dev; /* we need to set this at each time */ 912 return;
432 for (i = 0; i < ctx->packets; i++) { 913
433 urb->iso_frame_desc[i].offset = offs; 914 if (snd_BUG_ON(!test_bit(EP_FLAG_ACTIVATED, &ep->flags)))
434 urb->iso_frame_desc[i].length = subs->curpacksize; 915 return;
435 offs += subs->curpacksize; 916
917 if (--ep->use_count == 0) {
918 deactivate_urbs(ep, force, can_sleep);
919 ep->data_subs = NULL;
920 ep->sync_slave = NULL;
921 ep->retire_data_urb = NULL;
922 ep->prepare_data_urb = NULL;
923
924 if (wait)
925 wait_clear_urbs(ep);
436 } 926 }
437 urb->transfer_buffer_length = offs;
438 urb->number_of_packets = ctx->packets;
439 return 0;
440} 927}
441 928
442/* 929/**
443 * process after capture complete 930 * snd_usb_endpoint_activate: activate an snd_usb_endpoint
931 *
932 * @ep: the endpoint to activate
933 *
934 * If the endpoint is not currently in use, this functions will select the
935 * correct alternate interface setting for the interface of this endpoint.
444 * 936 *
445 * copy the data from each desctiptor to the pcm buffer, and 937 * In case of any active users, this functions does nothing.
446 * update the current position. 938 *
939 * Returns an error if usb_set_interface() failed, 0 in all other
940 * cases.
447 */ 941 */
448static int retire_capture_urb(struct snd_usb_substream *subs, 942int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep)
449 struct snd_pcm_runtime *runtime,
450 struct urb *urb)
451{ 943{
452 unsigned long flags; 944 if (ep->use_count != 0)
453 unsigned char *cp; 945 return 0;
454 int i;
455 unsigned int stride, frames, bytes, oldptr;
456 int period_elapsed = 0;
457 946
458 stride = runtime->frame_bits >> 3; 947 if (!ep->chip->shutdown &&
948 !test_and_set_bit(EP_FLAG_ACTIVATED, &ep->flags)) {
949 int ret;
459 950
460 for (i = 0; i < urb->number_of_packets; i++) { 951 ret = usb_set_interface(ep->chip->dev, ep->iface, ep->alt_idx);
461 cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset; 952 if (ret < 0) {
462 if (urb->iso_frame_desc[i].status && printk_ratelimit()) { 953 snd_printk(KERN_ERR "%s() usb_set_interface() failed, ret = %d\n",
463 snd_printdd("frame %d active: %d\n", i, urb->iso_frame_desc[i].status); 954 __func__, ret);
464 // continue; 955 clear_bit(EP_FLAG_ACTIVATED, &ep->flags);
465 } 956 return ret;
466 bytes = urb->iso_frame_desc[i].actual_length;
467 frames = bytes / stride;
468 if (!subs->txfr_quirk)
469 bytes = frames * stride;
470 if (bytes % (runtime->sample_bits >> 3) != 0) {
471#ifdef CONFIG_SND_DEBUG_VERBOSE
472 int oldbytes = bytes;
473#endif
474 bytes = frames * stride;
475 snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n",
476 oldbytes, bytes);
477 }
478 /* update the current pointer */
479 spin_lock_irqsave(&subs->lock, flags);
480 oldptr = subs->hwptr_done;
481 subs->hwptr_done += bytes;
482 if (subs->hwptr_done >= runtime->buffer_size * stride)
483 subs->hwptr_done -= runtime->buffer_size * stride;
484 frames = (bytes + (oldptr % stride)) / stride;
485 subs->transfer_done += frames;
486 if (subs->transfer_done >= runtime->period_size) {
487 subs->transfer_done -= runtime->period_size;
488 period_elapsed = 1;
489 }
490 spin_unlock_irqrestore(&subs->lock, flags);
491 /* copy a data chunk */
492 if (oldptr + bytes > runtime->buffer_size * stride) {
493 unsigned int bytes1 =
494 runtime->buffer_size * stride - oldptr;
495 memcpy(runtime->dma_area + oldptr, cp, bytes1);
496 memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1);
497 } else {
498 memcpy(runtime->dma_area + oldptr, cp, bytes);
499 } 957 }
958
959 return 0;
500 } 960 }
501 if (period_elapsed) 961
502 snd_pcm_period_elapsed(subs->pcm_substream); 962 return -EBUSY;
503 return 0;
504} 963}
505 964
506/* 965/**
507 * Process after capture complete when paused. Nothing to do. 966 * snd_usb_endpoint_deactivate: deactivate an snd_usb_endpoint
967 *
968 * @ep: the endpoint to deactivate
969 *
970 * If the endpoint is not currently in use, this functions will select the
971 * alternate interface setting 0 for the interface of this endpoint.
972 *
973 * In case of any active users, this functions does nothing.
974 *
975 * Returns an error if usb_set_interface() failed, 0 in all other
976 * cases.
508 */ 977 */
509static int retire_paused_capture_urb(struct snd_usb_substream *subs, 978int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep)
510 struct snd_pcm_runtime *runtime,
511 struct urb *urb)
512{ 979{
513 return 0; 980 if (!ep)
514} 981 return -EINVAL;
515 982
983 if (ep->use_count != 0)
984 return 0;
516 985
517/* 986 if (!ep->chip->shutdown &&
518 * prepare urb for playback sync pipe 987 test_and_clear_bit(EP_FLAG_ACTIVATED, &ep->flags)) {
988 int ret;
989
990 ret = usb_set_interface(ep->chip->dev, ep->iface, 0);
991 if (ret < 0) {
992 snd_printk(KERN_ERR "%s(): usb_set_interface() failed, ret = %d\n",
993 __func__, ret);
994 return ret;
995 }
996
997 return 0;
998 }
999
1000 return -EBUSY;
1001}
1002
1003/**
1004 * snd_usb_endpoint_free: Free the resources of an snd_usb_endpoint
1005 *
1006 * @ep: the list header of the endpoint to free
519 * 1007 *
520 * set up the offset and length to receive the current frequency. 1008 * This function does not care for the endpoint's use count but will tear
1009 * down all the streaming URBs immediately and free all resources.
521 */ 1010 */
522static int prepare_playback_sync_urb(struct snd_usb_substream *subs, 1011void snd_usb_endpoint_free(struct list_head *head)
523 struct snd_pcm_runtime *runtime,
524 struct urb *urb)
525{ 1012{
526 struct snd_urb_ctx *ctx = urb->context; 1013 struct snd_usb_endpoint *ep;
527 1014
528 urb->dev = ctx->subs->dev; /* we need to set this at each time */ 1015 ep = list_entry(head, struct snd_usb_endpoint, list);
529 urb->iso_frame_desc[0].length = min(4u, ctx->subs->syncmaxsize); 1016 release_urbs(ep, 1);
530 urb->iso_frame_desc[0].offset = 0; 1017 kfree(ep);
531 return 0;
532} 1018}
533 1019
534/* 1020/**
535 * process after playback sync complete 1021 * snd_usb_handle_sync_urb: parse an USB sync packet
536 * 1022 *
537 * Full speed devices report feedback values in 10.14 format as samples per 1023 * @ep: the endpoint to handle the packet
538 * frame, high speed devices in 16.16 format as samples per microframe. 1024 * @sender: the sending endpoint
539 * Because the Audio Class 1 spec was written before USB 2.0, many high speed 1025 * @urb: the received packet
540 * devices use a wrong interpretation, some others use an entirely different 1026 *
541 * format. Therefore, we cannot predict what format any particular device uses 1027 * This function is called from the context of an endpoint that received
542 * and must detect it automatically. 1028 * the packet and is used to let another endpoint object handle the payload.
543 */ 1029 */
544static int retire_playback_sync_urb(struct snd_usb_substream *subs, 1030void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep,
545 struct snd_pcm_runtime *runtime, 1031 struct snd_usb_endpoint *sender,
546 struct urb *urb) 1032 const struct urb *urb)
547{ 1033{
548 unsigned int f;
549 int shift; 1034 int shift;
1035 unsigned int f;
550 unsigned long flags; 1036 unsigned long flags;
551 1037
1038 snd_BUG_ON(ep == sender);
1039
1040 /*
1041 * In case the endpoint is operating in implicit feedback mode, prepare
1042 * a new outbound URB that has the same layout as the received packet
1043 * and add it to the list of pending urbs. queue_pending_output_urbs()
1044 * will take care of them later.
1045 */
1046 if (snd_usb_endpoint_implict_feedback_sink(ep) &&
1047 ep->use_count != 0) {
1048
1049 /* implicit feedback case */
1050 int i, bytes = 0;
1051 struct snd_urb_ctx *in_ctx;
1052 struct snd_usb_packet_info *out_packet;
1053
1054 in_ctx = urb->context;
1055
1056 /* Count overall packet size */
1057 for (i = 0; i < in_ctx->packets; i++)
1058 if (urb->iso_frame_desc[i].status == 0)
1059 bytes += urb->iso_frame_desc[i].actual_length;
1060
1061 /*
1062 * skip empty packets. At least M-Audio's Fast Track Ultra stops
1063 * streaming once it received a 0-byte OUT URB
1064 */
1065 if (bytes == 0)
1066 return;
1067
1068 spin_lock_irqsave(&ep->lock, flags);
1069 out_packet = ep->next_packet + ep->next_packet_write_pos;
1070
1071 /*
1072 * Iterate through the inbound packet and prepare the lengths
1073 * for the output packet. The OUT packet we are about to send
1074 * will have the same amount of payload bytes than the IN
1075 * packet we just received.
1076 */
1077
1078 out_packet->packets = in_ctx->packets;
1079 for (i = 0; i < in_ctx->packets; i++) {
1080 if (urb->iso_frame_desc[i].status == 0)
1081 out_packet->packet_size[i] =
1082 urb->iso_frame_desc[i].actual_length / ep->stride;
1083 else
1084 out_packet->packet_size[i] = 0;
1085 }
1086
1087 ep->next_packet_write_pos++;
1088 ep->next_packet_write_pos %= MAX_URBS;
1089 spin_unlock_irqrestore(&ep->lock, flags);
1090 queue_pending_output_urbs(ep);
1091
1092 return;
1093 }
1094
1095 /*
1096 * process after playback sync complete
1097 *
1098 * Full speed devices report feedback values in 10.14 format as samples
1099 * per frame, high speed devices in 16.16 format as samples per
1100 * microframe.
1101 *
1102 * Because the Audio Class 1 spec was written before USB 2.0, many high
1103 * speed devices use a wrong interpretation, some others use an
1104 * entirely different format.
1105 *
1106 * Therefore, we cannot predict what format any particular device uses
1107 * and must detect it automatically.
1108 */
1109
552 if (urb->iso_frame_desc[0].status != 0 || 1110 if (urb->iso_frame_desc[0].status != 0 ||
553 urb->iso_frame_desc[0].actual_length < 3) 1111 urb->iso_frame_desc[0].actual_length < 3)
554 return 0; 1112 return;
555 1113
556 f = le32_to_cpup(urb->transfer_buffer); 1114 f = le32_to_cpup(urb->transfer_buffer);
557 if (urb->iso_frame_desc[0].actual_length == 3) 1115 if (urb->iso_frame_desc[0].actual_length == 3)
558 f &= 0x00ffffff; 1116 f &= 0x00ffffff;
559 else 1117 else
560 f &= 0x0fffffff; 1118 f &= 0x0fffffff;
1119
561 if (f == 0) 1120 if (f == 0)
562 return 0; 1121 return;
563 1122
564 if (unlikely(subs->freqshift == INT_MIN)) { 1123 if (unlikely(ep->freqshift == INT_MIN)) {
565 /* 1124 /*
566 * The first time we see a feedback value, determine its format 1125 * The first time we see a feedback value, determine its format
567 * by shifting it left or right until it matches the nominal 1126 * by shifting it left or right until it matches the nominal
@@ -569,398 +1128,34 @@ static int retire_playback_sync_urb(struct snd_usb_substream *subs,
569 * differ from the nominal value more than +50% or -25%. 1128 * differ from the nominal value more than +50% or -25%.
570 */ 1129 */
571 shift = 0; 1130 shift = 0;
572 while (f < subs->freqn - subs->freqn / 4) { 1131 while (f < ep->freqn - ep->freqn / 4) {
573 f <<= 1; 1132 f <<= 1;
574 shift++; 1133 shift++;
575 } 1134 }
576 while (f > subs->freqn + subs->freqn / 2) { 1135 while (f > ep->freqn + ep->freqn / 2) {
577 f >>= 1; 1136 f >>= 1;
578 shift--; 1137 shift--;
579 } 1138 }
580 subs->freqshift = shift; 1139 ep->freqshift = shift;
581 } 1140 } else if (ep->freqshift >= 0)
582 else if (subs->freqshift >= 0) 1141 f <<= ep->freqshift;
583 f <<= subs->freqshift;
584 else 1142 else
585 f >>= -subs->freqshift; 1143 f >>= -ep->freqshift;
586 1144
587 if (likely(f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax)) { 1145 if (likely(f >= ep->freqn - ep->freqn / 8 && f <= ep->freqmax)) {
588 /* 1146 /*
589 * If the frequency looks valid, set it. 1147 * If the frequency looks valid, set it.
590 * This value is referred to in prepare_playback_urb(). 1148 * This value is referred to in prepare_playback_urb().
591 */ 1149 */
592 spin_lock_irqsave(&subs->lock, flags); 1150 spin_lock_irqsave(&ep->lock, flags);
593 subs->freqm = f; 1151 ep->freqm = f;
594 spin_unlock_irqrestore(&subs->lock, flags); 1152 spin_unlock_irqrestore(&ep->lock, flags);
595 } else { 1153 } else {
596 /* 1154 /*
597 * Out of range; maybe the shift value is wrong. 1155 * Out of range; maybe the shift value is wrong.
598 * Reset it so that we autodetect again the next time. 1156 * Reset it so that we autodetect again the next time.
599 */ 1157 */
600 subs->freqshift = INT_MIN; 1158 ep->freqshift = INT_MIN;
601 }
602
603 return 0;
604}
605
606/* determine the number of frames in the next packet */
607static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs)
608{
609 if (subs->fill_max)
610 return subs->maxframesize;
611 else {
612 subs->phase = (subs->phase & 0xffff)
613 + (subs->freqm << subs->datainterval);
614 return min(subs->phase >> 16, subs->maxframesize);
615 } 1159 }
616} 1160}
617 1161
618/*
619 * Prepare urb for streaming before playback starts or when paused.
620 *
621 * We don't have any data, so we send silence.
622 */
623static int prepare_nodata_playback_urb(struct snd_usb_substream *subs,
624 struct snd_pcm_runtime *runtime,
625 struct urb *urb)
626{
627 unsigned int i, offs, counts;
628 struct snd_urb_ctx *ctx = urb->context;
629 int stride = runtime->frame_bits >> 3;
630
631 offs = 0;
632 urb->dev = ctx->subs->dev;
633 for (i = 0; i < ctx->packets; ++i) {
634 counts = snd_usb_audio_next_packet_size(subs);
635 urb->iso_frame_desc[i].offset = offs * stride;
636 urb->iso_frame_desc[i].length = counts * stride;
637 offs += counts;
638 }
639 urb->number_of_packets = ctx->packets;
640 urb->transfer_buffer_length = offs * stride;
641 memset(urb->transfer_buffer,
642 runtime->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0,
643 offs * stride);
644 return 0;
645}
646
647/*
648 * prepare urb for playback data pipe
649 *
650 * Since a URB can handle only a single linear buffer, we must use double
651 * buffering when the data to be transferred overflows the buffer boundary.
652 * To avoid inconsistencies when updating hwptr_done, we use double buffering
653 * for all URBs.
654 */
655static int prepare_playback_urb(struct snd_usb_substream *subs,
656 struct snd_pcm_runtime *runtime,
657 struct urb *urb)
658{
659 int i, stride;
660 unsigned int counts, frames, bytes;
661 unsigned long flags;
662 int period_elapsed = 0;
663 struct snd_urb_ctx *ctx = urb->context;
664
665 stride = runtime->frame_bits >> 3;
666
667 frames = 0;
668 urb->dev = ctx->subs->dev; /* we need to set this at each time */
669 urb->number_of_packets = 0;
670 spin_lock_irqsave(&subs->lock, flags);
671 for (i = 0; i < ctx->packets; i++) {
672 counts = snd_usb_audio_next_packet_size(subs);
673 /* set up descriptor */
674 urb->iso_frame_desc[i].offset = frames * stride;
675 urb->iso_frame_desc[i].length = counts * stride;
676 frames += counts;
677 urb->number_of_packets++;
678 subs->transfer_done += counts;
679 if (subs->transfer_done >= runtime->period_size) {
680 subs->transfer_done -= runtime->period_size;
681 period_elapsed = 1;
682 if (subs->fmt_type == UAC_FORMAT_TYPE_II) {
683 if (subs->transfer_done > 0) {
684 /* FIXME: fill-max mode is not
685 * supported yet */
686 frames -= subs->transfer_done;
687 counts -= subs->transfer_done;
688 urb->iso_frame_desc[i].length =
689 counts * stride;
690 subs->transfer_done = 0;
691 }
692 i++;
693 if (i < ctx->packets) {
694 /* add a transfer delimiter */
695 urb->iso_frame_desc[i].offset =
696 frames * stride;
697 urb->iso_frame_desc[i].length = 0;
698 urb->number_of_packets++;
699 }
700 break;
701 }
702 }
703 if (period_elapsed) /* finish at the period boundary */
704 break;
705 }
706 bytes = frames * stride;
707 if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
708 /* err, the transferred area goes over buffer boundary. */
709 unsigned int bytes1 =
710 runtime->buffer_size * stride - subs->hwptr_done;
711 memcpy(urb->transfer_buffer,
712 runtime->dma_area + subs->hwptr_done, bytes1);
713 memcpy(urb->transfer_buffer + bytes1,
714 runtime->dma_area, bytes - bytes1);
715 } else {
716 memcpy(urb->transfer_buffer,
717 runtime->dma_area + subs->hwptr_done, bytes);
718 }
719 subs->hwptr_done += bytes;
720 if (subs->hwptr_done >= runtime->buffer_size * stride)
721 subs->hwptr_done -= runtime->buffer_size * stride;
722
723 /* update delay with exact number of samples queued */
724 runtime->delay = subs->last_delay;
725 runtime->delay += frames;
726 subs->last_delay = runtime->delay;
727
728 /* realign last_frame_number */
729 subs->last_frame_number = usb_get_current_frame_number(subs->dev);
730 subs->last_frame_number &= 0xFF; /* keep 8 LSBs */
731
732 spin_unlock_irqrestore(&subs->lock, flags);
733 urb->transfer_buffer_length = bytes;
734 if (period_elapsed)
735 snd_pcm_period_elapsed(subs->pcm_substream);
736 return 0;
737}
738
739/*
740 * process after playback data complete
741 * - decrease the delay count again
742 */
743static int retire_playback_urb(struct snd_usb_substream *subs,
744 struct snd_pcm_runtime *runtime,
745 struct urb *urb)
746{
747 unsigned long flags;
748 int stride = runtime->frame_bits >> 3;
749 int processed = urb->transfer_buffer_length / stride;
750 int est_delay;
751
752 spin_lock_irqsave(&subs->lock, flags);
753
754 est_delay = snd_usb_pcm_delay(subs, runtime->rate);
755 /* update delay with exact number of samples played */
756 if (processed > subs->last_delay)
757 subs->last_delay = 0;
758 else
759 subs->last_delay -= processed;
760 runtime->delay = subs->last_delay;
761
762 /*
763 * Report when delay estimate is off by more than 2ms.
764 * The error should be lower than 2ms since the estimate relies
765 * on two reads of a counter updated every ms.
766 */
767 if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2)
768 snd_printk(KERN_DEBUG "delay: estimated %d, actual %d\n",
769 est_delay, subs->last_delay);
770
771 spin_unlock_irqrestore(&subs->lock, flags);
772 return 0;
773}
774
775static const char *usb_error_string(int err)
776{
777 switch (err) {
778 case -ENODEV:
779 return "no device";
780 case -ENOENT:
781 return "endpoint not enabled";
782 case -EPIPE:
783 return "endpoint stalled";
784 case -ENOSPC:
785 return "not enough bandwidth";
786 case -ESHUTDOWN:
787 return "device disabled";
788 case -EHOSTUNREACH:
789 return "device suspended";
790 case -EINVAL:
791 case -EAGAIN:
792 case -EFBIG:
793 case -EMSGSIZE:
794 return "internal error";
795 default:
796 return "unknown error";
797 }
798}
799
800/*
801 * set up and start data/sync urbs
802 */
803static int start_urbs(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime)
804{
805 unsigned int i;
806 int err;
807
808 if (subs->stream->chip->shutdown)
809 return -EBADFD;
810
811 for (i = 0; i < subs->nurbs; i++) {
812 if (snd_BUG_ON(!subs->dataurb[i].urb))
813 return -EINVAL;
814 if (subs->ops.prepare(subs, runtime, subs->dataurb[i].urb) < 0) {
815 snd_printk(KERN_ERR "cannot prepare datapipe for urb %d\n", i);
816 goto __error;
817 }
818 }
819 if (subs->syncpipe) {
820 for (i = 0; i < SYNC_URBS; i++) {
821 if (snd_BUG_ON(!subs->syncurb[i].urb))
822 return -EINVAL;
823 if (subs->ops.prepare_sync(subs, runtime, subs->syncurb[i].urb) < 0) {
824 snd_printk(KERN_ERR "cannot prepare syncpipe for urb %d\n", i);
825 goto __error;
826 }
827 }
828 }
829
830 subs->active_mask = 0;
831 subs->unlink_mask = 0;
832 subs->running = 1;
833 for (i = 0; i < subs->nurbs; i++) {
834 err = usb_submit_urb(subs->dataurb[i].urb, GFP_ATOMIC);
835 if (err < 0) {
836 snd_printk(KERN_ERR "cannot submit datapipe "
837 "for urb %d, error %d: %s\n",
838 i, err, usb_error_string(err));
839 goto __error;
840 }
841 set_bit(i, &subs->active_mask);
842 }
843 if (subs->syncpipe) {
844 for (i = 0; i < SYNC_URBS; i++) {
845 err = usb_submit_urb(subs->syncurb[i].urb, GFP_ATOMIC);
846 if (err < 0) {
847 snd_printk(KERN_ERR "cannot submit syncpipe "
848 "for urb %d, error %d: %s\n",
849 i, err, usb_error_string(err));
850 goto __error;
851 }
852 set_bit(i + 16, &subs->active_mask);
853 }
854 }
855 return 0;
856
857 __error:
858 // snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN);
859 deactivate_urbs(subs, 0, 0);
860 return -EPIPE;
861}
862
863
864/*
865 */
866static struct snd_urb_ops audio_urb_ops[2] = {
867 {
868 .prepare = prepare_nodata_playback_urb,
869 .retire = retire_playback_urb,
870 .prepare_sync = prepare_playback_sync_urb,
871 .retire_sync = retire_playback_sync_urb,
872 },
873 {
874 .prepare = prepare_capture_urb,
875 .retire = retire_capture_urb,
876 .prepare_sync = prepare_capture_sync_urb,
877 .retire_sync = retire_capture_sync_urb,
878 },
879};
880
881/*
882 * initialize the substream instance.
883 */
884
885void snd_usb_init_substream(struct snd_usb_stream *as,
886 int stream, struct audioformat *fp)
887{
888 struct snd_usb_substream *subs = &as->substream[stream];
889
890 INIT_LIST_HEAD(&subs->fmt_list);
891 spin_lock_init(&subs->lock);
892
893 subs->stream = as;
894 subs->direction = stream;
895 subs->dev = as->chip->dev;
896 subs->txfr_quirk = as->chip->txfr_quirk;
897 subs->ops = audio_urb_ops[stream];
898 if (snd_usb_get_speed(subs->dev) >= USB_SPEED_HIGH)
899 subs->ops.prepare_sync = prepare_capture_sync_urb_hs;
900
901 snd_usb_set_pcm_ops(as->pcm, stream);
902
903 list_add_tail(&fp->list, &subs->fmt_list);
904 subs->formats |= fp->formats;
905 subs->endpoint = fp->endpoint;
906 subs->num_formats++;
907 subs->fmt_type = fp->fmt_type;
908}
909
910int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd)
911{
912 struct snd_usb_substream *subs = substream->runtime->private_data;
913
914 switch (cmd) {
915 case SNDRV_PCM_TRIGGER_START:
916 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
917 subs->ops.prepare = prepare_playback_urb;
918 return 0;
919 case SNDRV_PCM_TRIGGER_STOP:
920 return deactivate_urbs(subs, 0, 0);
921 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
922 subs->ops.prepare = prepare_nodata_playback_urb;
923 return 0;
924 }
925
926 return -EINVAL;
927}
928
929int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd)
930{
931 struct snd_usb_substream *subs = substream->runtime->private_data;
932
933 switch (cmd) {
934 case SNDRV_PCM_TRIGGER_START:
935 subs->ops.retire = retire_capture_urb;
936 return start_urbs(subs, substream->runtime);
937 case SNDRV_PCM_TRIGGER_STOP:
938 return deactivate_urbs(subs, 0, 0);
939 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
940 subs->ops.retire = retire_paused_capture_urb;
941 return 0;
942 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
943 subs->ops.retire = retire_capture_urb;
944 return 0;
945 }
946
947 return -EINVAL;
948}
949
950int snd_usb_substream_prepare(struct snd_usb_substream *subs,
951 struct snd_pcm_runtime *runtime)
952{
953 /* clear urbs (to be sure) */
954 deactivate_urbs(subs, 0, 1);
955 wait_clear_urbs(subs);
956
957 /* for playback, submit the URBs now; otherwise, the first hwptr_done
958 * updates for all URBs would happen at the same time when starting */
959 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
960 subs->ops.prepare = prepare_nodata_playback_urb;
961 return start_urbs(subs, runtime);
962 }
963
964 return 0;
965}
966
diff --git a/sound/usb/endpoint.h b/sound/usb/endpoint.h
index 88eb63a636eb..ee2723fb174f 100644
--- a/sound/usb/endpoint.h
+++ b/sound/usb/endpoint.h
@@ -1,21 +1,29 @@
1#ifndef __USBAUDIO_ENDPOINT_H 1#ifndef __USBAUDIO_ENDPOINT_H
2#define __USBAUDIO_ENDPOINT_H 2#define __USBAUDIO_ENDPOINT_H
3 3
4void snd_usb_init_substream(struct snd_usb_stream *as, 4#define SND_USB_ENDPOINT_TYPE_DATA 0
5 int stream, 5#define SND_USB_ENDPOINT_TYPE_SYNC 1
6 struct audioformat *fp);
7 6
8int snd_usb_init_substream_urbs(struct snd_usb_substream *subs, 7struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
9 unsigned int period_bytes, 8 struct usb_host_interface *alts,
10 unsigned int rate, 9 int ep_num, int direction, int type);
11 unsigned int frame_bits);
12 10
13void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force); 11int 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
15int snd_usb_substream_prepare(struct snd_usb_substream *subs, 16int snd_usb_endpoint_start(struct snd_usb_endpoint *ep);
16 struct snd_pcm_runtime *runtime); 17void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep,
18 int force, int can_sleep, int wait);
19int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep);
20int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep);
21void snd_usb_endpoint_free(struct list_head *head);
17 22
18int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd); 23int snd_usb_endpoint_implict_feedback_sink(struct snd_usb_endpoint *ep);
19int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd); 24
25void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep,
26 struct snd_usb_endpoint *sender,
27 const struct urb *urb);
20 28
21#endif /* __USBAUDIO_ENDPOINT_H */ 29#endif /* __USBAUDIO_ENDPOINT_H */
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index ab23869c01bb..4f40ba823163 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -486,7 +486,7 @@ static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
486/* 486/*
487 * TLV callback for mixer volume controls 487 * TLV callback for mixer volume controls
488 */ 488 */
489static int mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, 489int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
490 unsigned int size, unsigned int __user *_tlv) 490 unsigned int size, unsigned int __user *_tlv)
491{ 491{
492 struct usb_mixer_elem_info *cval = kcontrol->private_data; 492 struct usb_mixer_elem_info *cval = kcontrol->private_data;
@@ -770,6 +770,26 @@ static void volume_control_quirks(struct usb_mixer_elem_info *cval,
770 struct snd_kcontrol *kctl) 770 struct snd_kcontrol *kctl)
771{ 771{
772 switch (cval->mixer->chip->usb_id) { 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 case USB_ID(0x0471, 0x0101): 793 case USB_ID(0x0471, 0x0101):
774 case USB_ID(0x0471, 0x0104): 794 case USB_ID(0x0471, 0x0104):
775 case USB_ID(0x0471, 0x0105): 795 case USB_ID(0x0471, 0x0105):
@@ -1121,9 +1141,6 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1121 len = snd_usb_copy_string_desc(state, nameid, 1141 len = snd_usb_copy_string_desc(state, nameid,
1122 kctl->id.name, sizeof(kctl->id.name)); 1142 kctl->id.name, sizeof(kctl->id.name));
1123 1143
1124 /* get min/max values */
1125 get_min_max_with_quirks(cval, 0, kctl);
1126
1127 switch (control) { 1144 switch (control) {
1128 case UAC_FU_MUTE: 1145 case UAC_FU_MUTE:
1129 case UAC_FU_VOLUME: 1146 case UAC_FU_VOLUME:
@@ -1155,17 +1172,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1155 } 1172 }
1156 append_ctl_name(kctl, control == UAC_FU_MUTE ? 1173 append_ctl_name(kctl, control == UAC_FU_MUTE ?
1157 " Switch" : " Volume"); 1174 " Switch" : " Volume");
1158 if (control == UAC_FU_VOLUME) {
1159 check_mapped_dB(map, cval);
1160 if (cval->dBmin < cval->dBmax || !cval->initialized) {
1161 kctl->tlv.c = mixer_vol_tlv;
1162 kctl->vd[0].access |=
1163 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
1164 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1165 }
1166 }
1167 break; 1175 break;
1168
1169 default: 1176 default:
1170 if (! len) 1177 if (! len)
1171 strlcpy(kctl->id.name, audio_feature_info[control-1].name, 1178 strlcpy(kctl->id.name, audio_feature_info[control-1].name,
@@ -1173,6 +1180,19 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1173 break; 1180 break;
1174 } 1181 }
1175 1182
1183 /* get min/max values */
1184 get_min_max_with_quirks(cval, 0, kctl);
1185
1186 if (control == UAC_FU_VOLUME) {
1187 check_mapped_dB(map, cval);
1188 if (cval->dBmin < cval->dBmax || !cval->initialized) {
1189 kctl->tlv.c = snd_usb_mixer_vol_tlv;
1190 kctl->vd[0].access |=
1191 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
1192 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1193 }
1194 }
1195
1176 range = (cval->max - cval->min) / cval->res; 1196 range = (cval->max - cval->min) / cval->res;
1177 /* Are there devices with volume range more than 255? I use a bit more 1197 /* Are there devices with volume range more than 255? I use a bit more
1178 * to be sure. 384 is a resolution magic number found on Logitech 1198 * to be sure. 384 is a resolution magic number found on Logitech
@@ -1388,7 +1408,7 @@ static int parse_audio_mixer_unit(struct mixer_build *state, int unitid, void *r
1388 for (pin = 0; pin < input_pins; pin++) { 1408 for (pin = 0; pin < input_pins; pin++) {
1389 err = parse_audio_unit(state, desc->baSourceID[pin]); 1409 err = parse_audio_unit(state, desc->baSourceID[pin]);
1390 if (err < 0) 1410 if (err < 0)
1391 return err; 1411 continue;
1392 err = check_input_term(state, desc->baSourceID[pin], &iterm); 1412 err = check_input_term(state, desc->baSourceID[pin], &iterm);
1393 if (err < 0) 1413 if (err < 0)
1394 return err; 1414 return err;
diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
index 81b2d8a32fb0..a7f3d45a8acf 100644
--- a/sound/usb/mixer.h
+++ b/sound/usb/mixer.h
@@ -68,4 +68,7 @@ int snd_usb_mixer_activate(struct usb_mixer_interface *mixer);
68int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer, 68int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer,
69 struct snd_kcontrol *kctl); 69 struct snd_kcontrol *kctl);
70 70
71int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
72 unsigned int size, unsigned int __user *_tlv);
73
71#endif /* __USBMIXER_H */ 74#endif /* __USBMIXER_H */
diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c
index f1324c423835..41daaa24c25f 100644
--- a/sound/usb/mixer_maps.c
+++ b/sound/usb/mixer_maps.c
@@ -288,6 +288,15 @@ static struct usbmix_name_map scratch_live_map[] = {
288 { 0 } /* terminator */ 288 { 0 } /* terminator */
289}; 289};
290 290
291static 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/* "Gamesurround Muse Pocket LT" looks same like "Sound Blaster MP3+" 300/* "Gamesurround Muse Pocket LT" looks same like "Sound Blaster MP3+"
292 * most importand difference is SU[8], it should be set to "Capture Source" 301 * most importand difference is SU[8], it should be set to "Capture Source"
293 * to make alsamixer and PA working properly. 302 * to make alsamixer and PA working properly.
@@ -371,6 +380,10 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
371 .map = scratch_live_map, 380 .map = scratch_live_map,
372 .ignore_ctl_error = 1, 381 .ignore_ctl_error = 1,
373 }, 382 },
383 {
384 .id = USB_ID(0x200c, 0x1018),
385 .map = ebox44_map,
386 },
374 { 0 } /* terminator */ 387 { 0 } /* terminator */
375}; 388};
376 389
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index ab125ee0b0f0..41f4b6911920 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -42,6 +42,77 @@
42 42
43extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl; 43extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl;
44 44
45/* private_free callback */
46static 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 */
59static 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 * Sound Blaster remote control configuration 117 * Sound Blaster remote control configuration
47 * 118 *
@@ -495,60 +566,218 @@ static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
495} 566}
496 567
497/* M-Audio FastTrack Ultra quirks */ 568/* M-Audio FastTrack Ultra quirks */
569/* FTU Effect switch */
570struct snd_ftu_eff_switch_priv_val {
571 struct usb_mixer_interface *mixer;
572 int cached_value;
573 int is_cached;
574};
498 575
499/* private_free callback */ 576static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
500static void usb_mixer_elem_free(struct snd_kcontrol *kctl) 577 struct snd_ctl_elem_info *uinfo)
501{ 578{
502 kfree(kctl->private_data); 579 static const char *texts[8] = {"Room 1",
503 kctl->private_data = NULL; 580 "Room 2",
581 "Room 3",
582 "Hall 1",
583 "Hall 2",
584 "Plate",
585 "Delay",
586 "Echo"
587 };
588
589 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
590 uinfo->count = 1;
591 uinfo->value.enumerated.items = 8;
592 if (uinfo->value.enumerated.item > 7)
593 uinfo->value.enumerated.item = 7;
594 strcpy(uinfo->value.enumerated.name,
595 texts[uinfo->value.enumerated.item]);
596
597 return 0;
504} 598}
505 599
506static int snd_maudio_ftu_create_ctl(struct usb_mixer_interface *mixer, 600static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
507 int in, int out, const char *name) 601 struct snd_ctl_elem_value *ucontrol)
508{ 602{
509 struct usb_mixer_elem_info *cval; 603 struct snd_usb_audio *chip;
604 struct usb_mixer_interface *mixer;
605 struct snd_ftu_eff_switch_priv_val *pval;
606 int err;
607 unsigned char value[2];
608
609 const int id = 6;
610 const int validx = 1;
611 const int val_len = 2;
612
613 value[0] = 0x00;
614 value[1] = 0x00;
615
616 pval = (struct snd_ftu_eff_switch_priv_val *)
617 kctl->private_value;
618
619 if (pval->is_cached) {
620 ucontrol->value.enumerated.item[0] = pval->cached_value;
621 return 0;
622 }
623
624 mixer = (struct usb_mixer_interface *) pval->mixer;
625 if (snd_BUG_ON(!mixer))
626 return -EINVAL;
627
628 chip = (struct snd_usb_audio *) mixer->chip;
629 if (snd_BUG_ON(!chip))
630 return -EINVAL;
631
632
633 err = snd_usb_ctl_msg(chip->dev,
634 usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
635 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
636 validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
637 value, val_len);
638 if (err < 0)
639 return err;
640
641 ucontrol->value.enumerated.item[0] = value[0];
642 pval->cached_value = value[0];
643 pval->is_cached = 1;
644
645 return 0;
646}
647
648static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
649 struct snd_ctl_elem_value *ucontrol)
650{
651 struct snd_usb_audio *chip;
652 struct snd_ftu_eff_switch_priv_val *pval;
653
654 struct usb_mixer_interface *mixer;
655 int changed, cur_val, err, new_val;
656 unsigned char value[2];
657
658
659 const int id = 6;
660 const int validx = 1;
661 const int val_len = 2;
662
663 changed = 0;
664
665 pval = (struct snd_ftu_eff_switch_priv_val *)
666 kctl->private_value;
667 cur_val = pval->cached_value;
668 new_val = ucontrol->value.enumerated.item[0];
669
670 mixer = (struct usb_mixer_interface *) pval->mixer;
671 if (snd_BUG_ON(!mixer))
672 return -EINVAL;
673
674 chip = (struct snd_usb_audio *) mixer->chip;
675 if (snd_BUG_ON(!chip))
676 return -EINVAL;
677
678 if (!pval->is_cached) {
679 /* Read current value */
680 err = snd_usb_ctl_msg(chip->dev,
681 usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR,
682 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
683 validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
684 value, val_len);
685 if (err < 0)
686 return err;
687
688 cur_val = value[0];
689 pval->cached_value = cur_val;
690 pval->is_cached = 1;
691 }
692 /* update value if needed */
693 if (cur_val != new_val) {
694 value[0] = new_val;
695 value[1] = 0;
696 err = snd_usb_ctl_msg(chip->dev,
697 usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR,
698 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
699 validx << 8, snd_usb_ctrl_intf(chip) | (id << 8),
700 value, val_len);
701 if (err < 0)
702 return err;
703
704 pval->cached_value = new_val;
705 pval->is_cached = 1;
706 changed = 1;
707 }
708
709 return changed;
710}
711
712static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer)
713{
714 static struct snd_kcontrol_new template = {
715 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
716 .name = "Effect Program Switch",
717 .index = 0,
718 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
719 .info = snd_ftu_eff_switch_info,
720 .get = snd_ftu_eff_switch_get,
721 .put = snd_ftu_eff_switch_put
722 };
723
724 int err;
510 struct snd_kcontrol *kctl; 725 struct snd_kcontrol *kctl;
726 struct snd_ftu_eff_switch_priv_val *pval;
511 727
512 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 728 pval = kzalloc(sizeof(*pval), GFP_KERNEL);
513 if (!cval) 729 if (!pval)
514 return -ENOMEM; 730 return -ENOMEM;
515 731
516 cval->id = 5; 732 pval->cached_value = 0;
517 cval->mixer = mixer; 733 pval->is_cached = 0;
518 cval->val_type = USB_MIXER_S16; 734 pval->mixer = mixer;
519 cval->channels = 1;
520 cval->control = out + 1;
521 cval->cmask = 1 << in;
522 735
523 kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval); 736 template.private_value = (unsigned long) pval;
737 kctl = snd_ctl_new1(&template, mixer->chip);
524 if (!kctl) { 738 if (!kctl) {
525 kfree(cval); 739 kfree(pval);
526 return -ENOMEM; 740 return -ENOMEM;
527 } 741 }
528 742
529 snprintf(kctl->id.name, sizeof(kctl->id.name), name); 743 err = snd_ctl_add(mixer->chip->card, kctl);
530 kctl->private_free = usb_mixer_elem_free; 744 if (err < 0)
531 return snd_usb_mixer_add_control(mixer, kctl); 745 return err;
746
747 return 0;
532} 748}
533 749
534static int snd_maudio_ftu_create_mixer(struct usb_mixer_interface *mixer) 750/* Create volume controls for FTU devices*/
751static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
535{ 752{
536 char name[64]; 753 char name[64];
754 unsigned int control, cmask;
537 int in, out, err; 755 int in, out, err;
538 756
757 const unsigned int id = 5;
758 const int val_type = USB_MIXER_S16;
759
539 for (out = 0; out < 8; out++) { 760 for (out = 0; out < 8; out++) {
761 control = out + 1;
540 for (in = 0; in < 8; in++) { 762 for (in = 0; in < 8; in++) {
763 cmask = 1 << in;
541 snprintf(name, sizeof(name), 764 snprintf(name, sizeof(name),
542 "AIn%d - Out%d Capture Volume", in + 1, out + 1); 765 "AIn%d - Out%d Capture Volume",
543 err = snd_maudio_ftu_create_ctl(mixer, in, out, name); 766 in + 1, out + 1);
767 err = snd_create_std_mono_ctl(mixer, id, control,
768 cmask, val_type, name,
769 &snd_usb_mixer_vol_tlv);
544 if (err < 0) 770 if (err < 0)
545 return err; 771 return err;
546 } 772 }
547
548 for (in = 8; in < 16; in++) { 773 for (in = 8; in < 16; in++) {
774 cmask = 1 << in;
549 snprintf(name, sizeof(name), 775 snprintf(name, sizeof(name),
550 "DIn%d - Out%d Playback Volume", in - 7, out + 1); 776 "DIn%d - Out%d Playback Volume",
551 err = snd_maudio_ftu_create_ctl(mixer, in, out, name); 777 in - 7, out + 1);
778 err = snd_create_std_mono_ctl(mixer, id, control,
779 cmask, val_type, name,
780 &snd_usb_mixer_vol_tlv);
552 if (err < 0) 781 if (err < 0)
553 return err; 782 return err;
554 } 783 }
@@ -557,6 +786,191 @@ static int snd_maudio_ftu_create_mixer(struct usb_mixer_interface *mixer)
557 return 0; 786 return 0;
558} 787}
559 788
789/* This control needs a volume quirk, see mixer.c */
790static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer)
791{
792 static const char name[] = "Effect Volume";
793 const unsigned int id = 6;
794 const int val_type = USB_MIXER_U8;
795 const unsigned int control = 2;
796 const unsigned int cmask = 0;
797
798 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
799 name, snd_usb_mixer_vol_tlv);
800}
801
802/* This control needs a volume quirk, see mixer.c */
803static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer)
804{
805 static const char name[] = "Effect Duration";
806 const unsigned int id = 6;
807 const int val_type = USB_MIXER_S16;
808 const unsigned int control = 3;
809 const unsigned int cmask = 0;
810
811 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
812 name, snd_usb_mixer_vol_tlv);
813}
814
815/* This control needs a volume quirk, see mixer.c */
816static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer)
817{
818 static const char name[] = "Effect Feedback Volume";
819 const unsigned int id = 6;
820 const int val_type = USB_MIXER_U8;
821 const unsigned int control = 4;
822 const unsigned int cmask = 0;
823
824 return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type,
825 name, NULL);
826}
827
828static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
829{
830 unsigned int cmask;
831 int err, ch;
832 char name[48];
833
834 const unsigned int id = 7;
835 const int val_type = USB_MIXER_S16;
836 const unsigned int control = 7;
837
838 for (ch = 0; ch < 4; ++ch) {
839 cmask = 1 << ch;
840 snprintf(name, sizeof(name),
841 "Effect Return %d Volume", ch + 1);
842 err = snd_create_std_mono_ctl(mixer, id, control,
843 cmask, val_type, name,
844 snd_usb_mixer_vol_tlv);
845 if (err < 0)
846 return err;
847 }
848
849 return 0;
850}
851
852static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
853{
854 unsigned int cmask;
855 int err, ch;
856 char name[48];
857
858 const unsigned int id = 5;
859 const int val_type = USB_MIXER_S16;
860 const unsigned int control = 9;
861
862 for (ch = 0; ch < 8; ++ch) {
863 cmask = 1 << ch;
864 snprintf(name, sizeof(name),
865 "Effect Send AIn%d Volume", ch + 1);
866 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
867 val_type, name,
868 snd_usb_mixer_vol_tlv);
869 if (err < 0)
870 return err;
871 }
872 for (ch = 8; ch < 16; ++ch) {
873 cmask = 1 << ch;
874 snprintf(name, sizeof(name),
875 "Effect Send DIn%d Volume", ch - 7);
876 err = snd_create_std_mono_ctl(mixer, id, control, cmask,
877 val_type, name,
878 snd_usb_mixer_vol_tlv);
879 if (err < 0)
880 return err;
881 }
882 return 0;
883}
884
885static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer)
886{
887 int err;
888
889 err = snd_ftu_create_volume_ctls(mixer);
890 if (err < 0)
891 return err;
892
893 err = snd_ftu_create_effect_switch(mixer);
894 if (err < 0)
895 return err;
896 err = snd_ftu_create_effect_volume_ctl(mixer);
897 if (err < 0)
898 return err;
899
900 err = snd_ftu_create_effect_duration_ctl(mixer);
901 if (err < 0)
902 return err;
903
904 err = snd_ftu_create_effect_feedback_ctl(mixer);
905 if (err < 0)
906 return err;
907
908 err = snd_ftu_create_effect_return_ctls(mixer);
909 if (err < 0)
910 return err;
911
912 err = snd_ftu_create_effect_send_ctls(mixer);
913 if (err < 0)
914 return err;
915
916 return 0;
917}
918
919
920/*
921 * Create mixer for Electrix Ebox-44
922 *
923 * The mixer units from this device are corrupt, and even where they
924 * are valid they presents mono controls as L and R channels of
925 * stereo. So we create a good mixer in code.
926 */
927
928static int snd_ebox44_create_mixer(struct usb_mixer_interface *mixer)
929{
930 int err;
931
932 err = snd_create_std_mono_ctl(mixer, 4, 1, 0x0, USB_MIXER_INV_BOOLEAN,
933 "Headphone Playback Switch", NULL);
934 if (err < 0)
935 return err;
936 err = snd_create_std_mono_ctl(mixer, 4, 2, 0x1, USB_MIXER_S16,
937 "Headphone A Mix Playback Volume", NULL);
938 if (err < 0)
939 return err;
940 err = snd_create_std_mono_ctl(mixer, 4, 2, 0x2, USB_MIXER_S16,
941 "Headphone B Mix Playback Volume", NULL);
942 if (err < 0)
943 return err;
944
945 err = snd_create_std_mono_ctl(mixer, 7, 1, 0x0, USB_MIXER_INV_BOOLEAN,
946 "Output Playback Switch", NULL);
947 if (err < 0)
948 return err;
949 err = snd_create_std_mono_ctl(mixer, 7, 2, 0x1, USB_MIXER_S16,
950 "Output A Playback Volume", NULL);
951 if (err < 0)
952 return err;
953 err = snd_create_std_mono_ctl(mixer, 7, 2, 0x2, USB_MIXER_S16,
954 "Output B Playback Volume", NULL);
955 if (err < 0)
956 return err;
957
958 err = snd_create_std_mono_ctl(mixer, 10, 1, 0x0, USB_MIXER_INV_BOOLEAN,
959 "Input Capture Switch", NULL);
960 if (err < 0)
961 return err;
962 err = snd_create_std_mono_ctl(mixer, 10, 2, 0x1, USB_MIXER_S16,
963 "Input A Capture Volume", NULL);
964 if (err < 0)
965 return err;
966 err = snd_create_std_mono_ctl(mixer, 10, 2, 0x2, USB_MIXER_S16,
967 "Input B Capture Volume", NULL);
968 if (err < 0)
969 return err;
970
971 return 0;
972}
973
560void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, 974void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
561 unsigned char samplerate_id) 975 unsigned char samplerate_id)
562{ 976{
@@ -600,7 +1014,7 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
600 1014
601 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ 1015 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
602 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ 1016 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
603 err = snd_maudio_ftu_create_mixer(mixer); 1017 err = snd_ftu_create_mixer(mixer);
604 break; 1018 break;
605 1019
606 case USB_ID(0x0b05, 0x1739): 1020 case USB_ID(0x0b05, 0x1739):
@@ -619,6 +1033,10 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
619 snd_nativeinstruments_ta10_mixers, 1033 snd_nativeinstruments_ta10_mixers,
620 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers)); 1034 ARRAY_SIZE(snd_nativeinstruments_ta10_mixers));
621 break; 1035 break;
1036
1037 case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */
1038 err = snd_ebox44_create_mixer(mixer);
1039 break;
622 } 1040 }
623 1041
624 return err; 1042 return err;
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 0eed6115c2d4..24839d932648 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -16,6 +16,7 @@
16 16
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/ratelimit.h>
19#include <linux/usb.h> 20#include <linux/usb.h>
20#include <linux/usb/audio.h> 21#include <linux/usb/audio.h>
21#include <linux/usb/audio-v2.h> 22#include <linux/usb/audio-v2.h>
@@ -34,6 +35,9 @@
34#include "clock.h" 35#include "clock.h"
35#include "power.h" 36#include "power.h"
36 37
38#define SUBSTREAM_FLAG_DATA_EP_STARTED 0
39#define SUBSTREAM_FLAG_SYNC_EP_STARTED 1
40
37/* return the estimated delay based on USB frame counters */ 41/* return the estimated delay based on USB frame counters */
38snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs, 42snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs,
39 unsigned int rate) 43 unsigned int rate)
@@ -208,6 +212,84 @@ int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface,
208 } 212 }
209} 213}
210 214
215static int start_endpoints(struct snd_usb_substream *subs)
216{
217 int err;
218
219 if (!subs->data_endpoint)
220 return -EINVAL;
221
222 if (!test_and_set_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags)) {
223 struct snd_usb_endpoint *ep = subs->data_endpoint;
224
225 snd_printdd(KERN_DEBUG "Starting data EP @%p\n", ep);
226
227 ep->data_subs = subs;
228 err = snd_usb_endpoint_start(ep);
229 if (err < 0) {
230 clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags);
231 return err;
232 }
233 }
234
235 if (subs->sync_endpoint &&
236 !test_and_set_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags)) {
237 struct snd_usb_endpoint *ep = subs->sync_endpoint;
238
239 snd_printdd(KERN_DEBUG "Starting sync EP @%p\n", ep);
240
241 ep->sync_slave = subs->data_endpoint;
242 err = snd_usb_endpoint_start(ep);
243 if (err < 0) {
244 clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags);
245 return err;
246 }
247 }
248
249 return 0;
250}
251
252static void stop_endpoints(struct snd_usb_substream *subs,
253 int force, int can_sleep, int wait)
254{
255 if (test_and_clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags))
256 snd_usb_endpoint_stop(subs->sync_endpoint,
257 force, can_sleep, wait);
258
259 if (test_and_clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags))
260 snd_usb_endpoint_stop(subs->data_endpoint,
261 force, can_sleep, wait);
262}
263
264static int activate_endpoints(struct snd_usb_substream *subs)
265{
266 if (subs->sync_endpoint) {
267 int ret;
268
269 ret = snd_usb_endpoint_activate(subs->sync_endpoint);
270 if (ret < 0)
271 return ret;
272 }
273
274 return snd_usb_endpoint_activate(subs->data_endpoint);
275}
276
277static int deactivate_endpoints(struct snd_usb_substream *subs)
278{
279 int reta, retb;
280
281 reta = snd_usb_endpoint_deactivate(subs->sync_endpoint);
282 retb = snd_usb_endpoint_deactivate(subs->data_endpoint);
283
284 if (reta < 0)
285 return reta;
286
287 if (retb < 0)
288 return retb;
289
290 return 0;
291}
292
211/* 293/*
212 * find a matching format and set up the interface 294 * find a matching format and set up the interface
213 */ 295 */
@@ -219,7 +301,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
219 struct usb_interface *iface; 301 struct usb_interface *iface;
220 unsigned int ep, attr; 302 unsigned int ep, attr;
221 int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK; 303 int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
222 int err; 304 int err, implicit_fb = 0;
223 305
224 iface = usb_ifnum_to_if(dev, fmt->iface); 306 iface = usb_ifnum_to_if(dev, fmt->iface);
225 if (WARN_ON(!iface)) 307 if (WARN_ON(!iface))
@@ -232,40 +314,11 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
232 if (fmt == subs->cur_audiofmt) 314 if (fmt == subs->cur_audiofmt)
233 return 0; 315 return 0;
234 316
235 /* close the old interface */ 317 subs->data_endpoint = snd_usb_add_endpoint(subs->stream->chip,
236 if (subs->interface >= 0 && subs->interface != fmt->iface) { 318 alts, fmt->endpoint, subs->direction,
237 if (usb_set_interface(subs->dev, subs->interface, 0) < 0) { 319 SND_USB_ENDPOINT_TYPE_DATA);
238 snd_printk(KERN_ERR "%d:%d:%d: return to setting 0 failed\n", 320 if (!subs->data_endpoint)
239 dev->devnum, fmt->iface, fmt->altsetting); 321 return -EINVAL;
240 return -EIO;
241 }
242 subs->interface = -1;
243 subs->altset_idx = 0;
244 }
245
246 /* set interface */
247 if (subs->interface != fmt->iface || subs->altset_idx != fmt->altset_idx) {
248 if (usb_set_interface(dev, fmt->iface, fmt->altsetting) < 0) {
249 snd_printk(KERN_ERR "%d:%d:%d: usb_set_interface failed\n",
250 dev->devnum, fmt->iface, fmt->altsetting);
251 return -EIO;
252 }
253 snd_printdd(KERN_INFO "setting usb interface %d:%d\n", fmt->iface, fmt->altsetting);
254 subs->interface = fmt->iface;
255 subs->altset_idx = fmt->altset_idx;
256 }
257
258 /* create a data pipe */
259 ep = fmt->endpoint & USB_ENDPOINT_NUMBER_MASK;
260 if (is_playback)
261 subs->datapipe = usb_sndisocpipe(dev, ep);
262 else
263 subs->datapipe = usb_rcvisocpipe(dev, ep);
264 subs->datainterval = fmt->datainterval;
265 subs->syncpipe = subs->syncinterval = 0;
266 subs->maxpacksize = fmt->maxpacksize;
267 subs->syncmaxsize = 0;
268 subs->fill_max = 0;
269 322
270 /* we need a sync pipe in async OUT or adaptive IN mode */ 323 /* we need a sync pipe in async OUT or adaptive IN mode */
271 /* check the number of EP, since some devices have broken 324 /* check the number of EP, since some devices have broken
@@ -273,8 +326,25 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
273 * assume it as adaptive-out or sync-in. 326 * assume it as adaptive-out or sync-in.
274 */ 327 */
275 attr = fmt->ep_attr & USB_ENDPOINT_SYNCTYPE; 328 attr = fmt->ep_attr & USB_ENDPOINT_SYNCTYPE;
329
330 switch (subs->stream->chip->usb_id) {
331 case USB_ID(0x0763, 0x2080): /* M-Audio FastTrack Ultra */
332 case USB_ID(0x0763, 0x2081):
333 if (is_playback) {
334 implicit_fb = 1;
335 ep = 0x81;
336 iface = usb_ifnum_to_if(dev, 2);
337
338 if (!iface || iface->num_altsetting == 0)
339 return -EINVAL;
340
341 alts = &iface->altsetting[1];
342 goto add_sync_ep;
343 }
344 }
345
276 if (((is_playback && attr == USB_ENDPOINT_SYNC_ASYNC) || 346 if (((is_playback && attr == USB_ENDPOINT_SYNC_ASYNC) ||
277 (! is_playback && attr == USB_ENDPOINT_SYNC_ADAPTIVE)) && 347 (!is_playback && attr == USB_ENDPOINT_SYNC_ADAPTIVE)) &&
278 altsd->bNumEndpoints >= 2) { 348 altsd->bNumEndpoints >= 2) {
279 /* check sync-pipe endpoint */ 349 /* check sync-pipe endpoint */
280 /* ... and check descriptor size before accessing bSynchAddress 350 /* ... and check descriptor size before accessing bSynchAddress
@@ -282,7 +352,8 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
282 the audio fields in the endpoint descriptors */ 352 the audio fields in the endpoint descriptors */
283 if ((get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != 0x01 || 353 if ((get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != 0x01 ||
284 (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && 354 (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
285 get_endpoint(alts, 1)->bSynchAddress != 0)) { 355 get_endpoint(alts, 1)->bSynchAddress != 0 &&
356 !implicit_fb)) {
286 snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n", 357 snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n",
287 dev->devnum, fmt->iface, fmt->altsetting); 358 dev->devnum, fmt->iface, fmt->altsetting);
288 return -EINVAL; 359 return -EINVAL;
@@ -290,33 +361,27 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
290 ep = get_endpoint(alts, 1)->bEndpointAddress; 361 ep = get_endpoint(alts, 1)->bEndpointAddress;
291 if (get_endpoint(alts, 0)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && 362 if (get_endpoint(alts, 0)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
292 (( is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress | USB_DIR_IN)) || 363 (( 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)))) { 364 (!is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress & ~USB_DIR_IN)) ||
365 ( is_playback && !implicit_fb))) {
294 snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n", 366 snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n",
295 dev->devnum, fmt->iface, fmt->altsetting); 367 dev->devnum, fmt->iface, fmt->altsetting);
296 return -EINVAL; 368 return -EINVAL;
297 } 369 }
298 ep &= USB_ENDPOINT_NUMBER_MASK; 370
299 if (is_playback) 371 implicit_fb = (get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_USAGE_MASK)
300 subs->syncpipe = usb_rcvisocpipe(dev, ep); 372 == USB_ENDPOINT_USAGE_IMPLICIT_FB;
301 else 373
302 subs->syncpipe = usb_sndisocpipe(dev, ep); 374add_sync_ep:
303 if (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && 375 subs->sync_endpoint = snd_usb_add_endpoint(subs->stream->chip,
304 get_endpoint(alts, 1)->bRefresh >= 1 && 376 alts, ep, !subs->direction,
305 get_endpoint(alts, 1)->bRefresh <= 9) 377 implicit_fb ?
306 subs->syncinterval = get_endpoint(alts, 1)->bRefresh; 378 SND_USB_ENDPOINT_TYPE_DATA :
307 else if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) 379 SND_USB_ENDPOINT_TYPE_SYNC);
308 subs->syncinterval = 1; 380 if (!subs->sync_endpoint)
309 else if (get_endpoint(alts, 1)->bInterval >= 1 && 381 return -EINVAL;
310 get_endpoint(alts, 1)->bInterval <= 16) 382
311 subs->syncinterval = get_endpoint(alts, 1)->bInterval - 1; 383 subs->data_endpoint->sync_master = subs->sync_endpoint;
312 else 384 }
313 subs->syncinterval = 3;
314 subs->syncmaxsize = le16_to_cpu(get_endpoint(alts, 1)->wMaxPacketSize);
315 }
316
317 /* always fill max packet size */
318 if (fmt->attributes & UAC_EP_CS_ATTR_FILL_MAX)
319 subs->fill_max = 1;
320 385
321 if ((err = snd_usb_init_pitch(subs->stream->chip, subs->interface, alts, fmt)) < 0) 386 if ((err = snd_usb_init_pitch(subs->stream->chip, subs->interface, alts, fmt)) < 0)
322 return err; 387 return err;
@@ -390,15 +455,30 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
390 if (changed) { 455 if (changed) {
391 mutex_lock(&subs->stream->chip->shutdown_mutex); 456 mutex_lock(&subs->stream->chip->shutdown_mutex);
392 /* format changed */ 457 /* format changed */
393 snd_usb_release_substream_urbs(subs, 0); 458 stop_endpoints(subs, 0, 0, 0);
394 /* influenced: period_bytes, channels, rate, format, */ 459 deactivate_endpoints(subs);
395 ret = snd_usb_init_substream_urbs(subs, params_period_bytes(hw_params), 460
396 params_rate(hw_params), 461 ret = activate_endpoints(subs);
397 snd_pcm_format_physical_width(params_format(hw_params)) * 462 if (ret < 0)
398 params_channels(hw_params)); 463 goto unlock;
464
465 ret = snd_usb_endpoint_set_params(subs->data_endpoint, hw_params, fmt,
466 subs->sync_endpoint);
467 if (ret < 0)
468 goto unlock;
469
470 if (subs->sync_endpoint)
471 ret = snd_usb_endpoint_set_params(subs->sync_endpoint,
472 hw_params, fmt, NULL);
473unlock:
399 mutex_unlock(&subs->stream->chip->shutdown_mutex); 474 mutex_unlock(&subs->stream->chip->shutdown_mutex);
400 } 475 }
401 476
477 if (ret == 0) {
478 subs->interface = fmt->iface;
479 subs->altset_idx = fmt->altset_idx;
480 }
481
402 return ret; 482 return ret;
403} 483}
404 484
@@ -415,7 +495,7 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
415 subs->cur_rate = 0; 495 subs->cur_rate = 0;
416 subs->period_bytes = 0; 496 subs->period_bytes = 0;
417 mutex_lock(&subs->stream->chip->shutdown_mutex); 497 mutex_lock(&subs->stream->chip->shutdown_mutex);
418 snd_usb_release_substream_urbs(subs, 0); 498 stop_endpoints(subs, 0, 1, 1);
419 mutex_unlock(&subs->stream->chip->shutdown_mutex); 499 mutex_unlock(&subs->stream->chip->shutdown_mutex);
420 return snd_pcm_lib_free_vmalloc_buffer(substream); 500 return snd_pcm_lib_free_vmalloc_buffer(substream);
421} 501}
@@ -435,19 +515,28 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
435 return -ENXIO; 515 return -ENXIO;
436 } 516 }
437 517
518 if (snd_BUG_ON(!subs->data_endpoint))
519 return -EIO;
520
438 /* some unit conversions in runtime */ 521 /* some unit conversions in runtime */
439 subs->maxframesize = bytes_to_frames(runtime, subs->maxpacksize); 522 subs->data_endpoint->maxframesize =
440 subs->curframesize = bytes_to_frames(runtime, subs->curpacksize); 523 bytes_to_frames(runtime, subs->data_endpoint->maxpacksize);
524 subs->data_endpoint->curframesize =
525 bytes_to_frames(runtime, subs->data_endpoint->curpacksize);
441 526
442 /* reset the pointer */ 527 /* reset the pointer */
443 subs->hwptr_done = 0; 528 subs->hwptr_done = 0;
444 subs->transfer_done = 0; 529 subs->transfer_done = 0;
445 subs->phase = 0;
446 subs->last_delay = 0; 530 subs->last_delay = 0;
447 subs->last_frame_number = 0; 531 subs->last_frame_number = 0;
448 runtime->delay = 0; 532 runtime->delay = 0;
449 533
450 return snd_usb_substream_prepare(subs, runtime); 534 /* for playback, submit the URBs now; otherwise, the first hwptr_done
535 * updates for all URBs would happen at the same time when starting */
536 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK)
537 return start_endpoints(subs);
538
539 return 0;
451} 540}
452 541
453static struct snd_pcm_hardware snd_usb_hardware = 542static struct snd_pcm_hardware snd_usb_hardware =
@@ -842,16 +931,171 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction)
842 931
843static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction) 932static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
844{ 933{
934 int ret;
845 struct snd_usb_stream *as = snd_pcm_substream_chip(substream); 935 struct snd_usb_stream *as = snd_pcm_substream_chip(substream);
846 struct snd_usb_substream *subs = &as->substream[direction]; 936 struct snd_usb_substream *subs = &as->substream[direction];
847 937
848 if (!as->chip->shutdown && subs->interface >= 0) { 938 stop_endpoints(subs, 0, 0, 0);
849 usb_set_interface(subs->dev, subs->interface, 0); 939 ret = deactivate_endpoints(subs);
850 subs->interface = -1;
851 }
852 subs->pcm_substream = NULL; 940 subs->pcm_substream = NULL;
853 snd_usb_autosuspend(subs->stream->chip); 941 snd_usb_autosuspend(subs->stream->chip);
854 return 0; 942
943 return ret;
944}
945
946/* Since a URB can handle only a single linear buffer, we must use double
947 * buffering when the data to be transferred overflows the buffer boundary.
948 * To avoid inconsistencies when updating hwptr_done, we use double buffering
949 * for all URBs.
950 */
951static void retire_capture_urb(struct snd_usb_substream *subs,
952 struct urb *urb)
953{
954 struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime;
955 unsigned int stride, frames, bytes, oldptr;
956 int i, period_elapsed = 0;
957 unsigned long flags;
958 unsigned char *cp;
959
960 stride = runtime->frame_bits >> 3;
961
962 for (i = 0; i < urb->number_of_packets; i++) {
963 cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset;
964 if (urb->iso_frame_desc[i].status && printk_ratelimit()) {
965 snd_printdd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status);
966 // continue;
967 }
968 bytes = urb->iso_frame_desc[i].actual_length;
969 frames = bytes / stride;
970 if (!subs->txfr_quirk)
971 bytes = frames * stride;
972 if (bytes % (runtime->sample_bits >> 3) != 0) {
973#ifdef CONFIG_SND_DEBUG_VERBOSE
974 int oldbytes = bytes;
975#endif
976 bytes = frames * stride;
977 snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n",
978 oldbytes, bytes);
979 }
980 /* update the current pointer */
981 spin_lock_irqsave(&subs->lock, flags);
982 oldptr = subs->hwptr_done;
983 subs->hwptr_done += bytes;
984 if (subs->hwptr_done >= runtime->buffer_size * stride)
985 subs->hwptr_done -= runtime->buffer_size * stride;
986 frames = (bytes + (oldptr % stride)) / stride;
987 subs->transfer_done += frames;
988 if (subs->transfer_done >= runtime->period_size) {
989 subs->transfer_done -= runtime->period_size;
990 period_elapsed = 1;
991 }
992 spin_unlock_irqrestore(&subs->lock, flags);
993 /* copy a data chunk */
994 if (oldptr + bytes > runtime->buffer_size * stride) {
995 unsigned int bytes1 =
996 runtime->buffer_size * stride - oldptr;
997 memcpy(runtime->dma_area + oldptr, cp, bytes1);
998 memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1);
999 } else {
1000 memcpy(runtime->dma_area + oldptr, cp, bytes);
1001 }
1002 }
1003
1004 if (period_elapsed)
1005 snd_pcm_period_elapsed(subs->pcm_substream);
1006}
1007
1008static void prepare_playback_urb(struct snd_usb_substream *subs,
1009 struct urb *urb)
1010{
1011 struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime;
1012 struct snd_urb_ctx *ctx = urb->context;
1013 unsigned int counts, frames, bytes;
1014 int i, stride, period_elapsed = 0;
1015 unsigned long flags;
1016
1017 stride = runtime->frame_bits >> 3;
1018
1019 frames = 0;
1020 urb->number_of_packets = 0;
1021 spin_lock_irqsave(&subs->lock, flags);
1022 for (i = 0; i < ctx->packets; i++) {
1023 counts = ctx->packet_size[i];
1024 /* set up descriptor */
1025 urb->iso_frame_desc[i].offset = frames * stride;
1026 urb->iso_frame_desc[i].length = counts * stride;
1027 frames += counts;
1028 urb->number_of_packets++;
1029 subs->transfer_done += counts;
1030 if (subs->transfer_done >= runtime->period_size) {
1031 subs->transfer_done -= runtime->period_size;
1032 period_elapsed = 1;
1033 if (subs->fmt_type == UAC_FORMAT_TYPE_II) {
1034 if (subs->transfer_done > 0) {
1035 /* FIXME: fill-max mode is not
1036 * supported yet */
1037 frames -= subs->transfer_done;
1038 counts -= subs->transfer_done;
1039 urb->iso_frame_desc[i].length =
1040 counts * stride;
1041 subs->transfer_done = 0;
1042 }
1043 i++;
1044 if (i < ctx->packets) {
1045 /* add a transfer delimiter */
1046 urb->iso_frame_desc[i].offset =
1047 frames * stride;
1048 urb->iso_frame_desc[i].length = 0;
1049 urb->number_of_packets++;
1050 }
1051 break;
1052 }
1053 }
1054 if (period_elapsed &&
1055 !snd_usb_endpoint_implict_feedback_sink(subs->data_endpoint)) /* finish at the period boundary */
1056 break;
1057 }
1058 bytes = frames * stride;
1059 if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
1060 /* err, the transferred area goes over buffer boundary. */
1061 unsigned int bytes1 =
1062 runtime->buffer_size * stride - subs->hwptr_done;
1063 memcpy(urb->transfer_buffer,
1064 runtime->dma_area + subs->hwptr_done, bytes1);
1065 memcpy(urb->transfer_buffer + bytes1,
1066 runtime->dma_area, bytes - bytes1);
1067 } else {
1068 memcpy(urb->transfer_buffer,
1069 runtime->dma_area + subs->hwptr_done, bytes);
1070 }
1071 subs->hwptr_done += bytes;
1072 if (subs->hwptr_done >= runtime->buffer_size * stride)
1073 subs->hwptr_done -= runtime->buffer_size * stride;
1074 runtime->delay += frames;
1075 spin_unlock_irqrestore(&subs->lock, flags);
1076 urb->transfer_buffer_length = bytes;
1077 if (period_elapsed)
1078 snd_pcm_period_elapsed(subs->pcm_substream);
1079}
1080
1081/*
1082 * process after playback data complete
1083 * - decrease the delay count again
1084 */
1085static void retire_playback_urb(struct snd_usb_substream *subs,
1086 struct urb *urb)
1087{
1088 unsigned long flags;
1089 struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime;
1090 int stride = runtime->frame_bits >> 3;
1091 int processed = urb->transfer_buffer_length / stride;
1092
1093 spin_lock_irqsave(&subs->lock, flags);
1094 if (processed > runtime->delay)
1095 runtime->delay = 0;
1096 else
1097 runtime->delay -= processed;
1098 spin_unlock_irqrestore(&subs->lock, flags);
855} 1099}
856 1100
857static int snd_usb_playback_open(struct snd_pcm_substream *substream) 1101static int snd_usb_playback_open(struct snd_pcm_substream *substream)
@@ -874,6 +1118,63 @@ static int snd_usb_capture_close(struct snd_pcm_substream *substream)
874 return snd_usb_pcm_close(substream, SNDRV_PCM_STREAM_CAPTURE); 1118 return snd_usb_pcm_close(substream, SNDRV_PCM_STREAM_CAPTURE);
875} 1119}
876 1120
1121static int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream,
1122 int cmd)
1123{
1124 struct snd_usb_substream *subs = substream->runtime->private_data;
1125
1126 switch (cmd) {
1127 case SNDRV_PCM_TRIGGER_START:
1128 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1129 subs->data_endpoint->prepare_data_urb = prepare_playback_urb;
1130 subs->data_endpoint->retire_data_urb = retire_playback_urb;
1131 subs->running = 1;
1132 return 0;
1133 case SNDRV_PCM_TRIGGER_STOP:
1134 stop_endpoints(subs, 0, 0, 0);
1135 subs->running = 0;
1136 return 0;
1137 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1138 subs->data_endpoint->prepare_data_urb = NULL;
1139 subs->data_endpoint->retire_data_urb = NULL;
1140 subs->running = 0;
1141 return 0;
1142 }
1143
1144 return -EINVAL;
1145}
1146
1147int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd)
1148{
1149 int err;
1150 struct snd_usb_substream *subs = substream->runtime->private_data;
1151
1152 switch (cmd) {
1153 case SNDRV_PCM_TRIGGER_START:
1154 err = start_endpoints(subs);
1155 if (err < 0)
1156 return err;
1157
1158 subs->data_endpoint->retire_data_urb = retire_capture_urb;
1159 subs->running = 1;
1160 return 0;
1161 case SNDRV_PCM_TRIGGER_STOP:
1162 stop_endpoints(subs, 0, 0, 0);
1163 subs->running = 0;
1164 return 0;
1165 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1166 subs->data_endpoint->retire_data_urb = NULL;
1167 subs->running = 0;
1168 return 0;
1169 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1170 subs->data_endpoint->retire_data_urb = retire_capture_urb;
1171 subs->running = 1;
1172 return 0;
1173 }
1174
1175 return -EINVAL;
1176}
1177
877static struct snd_pcm_ops snd_usb_playback_ops = { 1178static struct snd_pcm_ops snd_usb_playback_ops = {
878 .open = snd_usb_playback_open, 1179 .open = snd_usb_playback_open,
879 .close = snd_usb_playback_close, 1180 .close = snd_usb_playback_close,
diff --git a/sound/usb/proc.c b/sound/usb/proc.c
index 961c9a250686..ebc1a5b5b3f1 100644
--- a/sound/usb/proc.c
+++ b/sound/usb/proc.c
@@ -25,6 +25,7 @@
25#include "usbaudio.h" 25#include "usbaudio.h"
26#include "helper.h" 26#include "helper.h"
27#include "card.h" 27#include "card.h"
28#include "endpoint.h"
28#include "proc.h" 29#include "proc.h"
29 30
30/* convert our full speed USB rate into sampling rate in Hz */ 31/* convert our full speed USB rate into sampling rate in Hz */
@@ -115,28 +116,33 @@ static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct s
115 } 116 }
116} 117}
117 118
119static void proc_dump_ep_status(struct snd_usb_substream *subs,
120 struct snd_usb_endpoint *ep,
121 struct snd_info_buffer *buffer)
122{
123 if (!ep)
124 return;
125 snd_iprintf(buffer, " Packet Size = %d\n", ep->curpacksize);
126 snd_iprintf(buffer, " Momentary freq = %u Hz (%#x.%04x)\n",
127 snd_usb_get_speed(subs->dev) == USB_SPEED_FULL
128 ? get_full_speed_hz(ep->freqm)
129 : get_high_speed_hz(ep->freqm),
130 ep->freqm >> 16, ep->freqm & 0xffff);
131 if (ep->freqshift != INT_MIN) {
132 int res = 16 - ep->freqshift;
133 snd_iprintf(buffer, " Feedback Format = %d.%d\n",
134 (ep->syncmaxsize > 3 ? 32 : 24) - res, res);
135 }
136}
137
118static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer) 138static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
119{ 139{
120 if (subs->running) { 140 if (subs->running) {
121 unsigned int i;
122 snd_iprintf(buffer, " Status: Running\n"); 141 snd_iprintf(buffer, " Status: Running\n");
123 snd_iprintf(buffer, " Interface = %d\n", subs->interface); 142 snd_iprintf(buffer, " Interface = %d\n", subs->interface);
124 snd_iprintf(buffer, " Altset = %d\n", subs->altset_idx); 143 snd_iprintf(buffer, " Altset = %d\n", subs->altset_idx);
125 snd_iprintf(buffer, " URBs = %d [ ", subs->nurbs); 144 proc_dump_ep_status(subs, subs->data_endpoint, buffer);
126 for (i = 0; i < subs->nurbs; i++) 145 proc_dump_ep_status(subs, subs->sync_endpoint, buffer);
127 snd_iprintf(buffer, "%d ", subs->dataurb[i].packets);
128 snd_iprintf(buffer, "]\n");
129 snd_iprintf(buffer, " Packet Size = %d\n", subs->curpacksize);
130 snd_iprintf(buffer, " Momentary freq = %u Hz (%#x.%04x)\n",
131 snd_usb_get_speed(subs->dev) == USB_SPEED_FULL
132 ? get_full_speed_hz(subs->freqm)
133 : get_high_speed_hz(subs->freqm),
134 subs->freqm >> 16, subs->freqm & 0xffff);
135 if (subs->freqshift != INT_MIN)
136 snd_iprintf(buffer, " Feedback Format = %d.%d\n",
137 (subs->syncmaxsize > 3 ? 32 : 24)
138 - (16 - subs->freqshift),
139 16 - subs->freqshift);
140 } else { 146 } else {
141 snd_iprintf(buffer, " Status: Stop\n"); 147 snd_iprintf(buffer, " Status: Stop\n");
142 } 148 }
diff --git a/sound/usb/stream.c b/sound/usb/stream.c
index 5ff8010b2d6f..6b7d7a2b7baa 100644
--- a/sound/usb/stream.c
+++ b/sound/usb/stream.c
@@ -73,6 +73,31 @@ static void snd_usb_audio_pcm_free(struct snd_pcm *pcm)
73 } 73 }
74} 74}
75 75
76/*
77 * initialize the substream instance.
78 */
79
80static 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 * add this endpoint to the chip instance. 103 * add this endpoint to the chip instance.
@@ -94,9 +119,9 @@ int snd_usb_add_audio_stream(struct snd_usb_audio *chip,
94 if (as->fmt_type != fp->fmt_type) 119 if (as->fmt_type != fp->fmt_type)
95 continue; 120 continue;
96 subs = &as->substream[stream]; 121 subs = &as->substream[stream];
97 if (!subs->endpoint) 122 if (!subs->data_endpoint)
98 continue; 123 continue;
99 if (subs->endpoint == fp->endpoint) { 124 if (subs->data_endpoint->ep_num == fp->endpoint) {
100 list_add_tail(&fp->list, &subs->fmt_list); 125 list_add_tail(&fp->list, &subs->fmt_list);
101 subs->num_formats++; 126 subs->num_formats++;
102 subs->formats |= fp->formats; 127 subs->formats |= fp->formats;
@@ -109,7 +134,7 @@ int snd_usb_add_audio_stream(struct snd_usb_audio *chip,
109 if (as->fmt_type != fp->fmt_type) 134 if (as->fmt_type != fp->fmt_type)
110 continue; 135 continue;
111 subs = &as->substream[stream]; 136 subs = &as->substream[stream];
112 if (subs->endpoint) 137 if (subs->data_endpoint)
113 continue; 138 continue;
114 err = snd_pcm_new_stream(as->pcm, stream, 1); 139 err = snd_pcm_new_stream(as->pcm, stream, 1);
115 if (err < 0) 140 if (err < 0)
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index 3e2b03577936..b8233ebe250f 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -36,6 +36,7 @@ struct snd_usb_audio {
36 struct snd_card *card; 36 struct snd_card *card;
37 struct usb_interface *pm_intf; 37 struct usb_interface *pm_intf;
38 u32 usb_id; 38 u32 usb_id;
39 struct mutex mutex;
39 struct mutex shutdown_mutex; 40 struct mutex shutdown_mutex;
40 unsigned int shutdown:1; 41 unsigned int shutdown:1;
41 unsigned int probing:1; 42 unsigned int probing:1;
@@ -46,6 +47,7 @@ struct snd_usb_audio {
46 int num_suspended_intf; 47 int num_suspended_intf;
47 48
48 struct list_head pcm_list; /* list of pcm streams */ 49 struct list_head pcm_list; /* list of pcm streams */
50 struct list_head ep_list; /* list of audio-related endpoints */
49 int pcm_devs; 51 int pcm_devs;
50 52
51 struct list_head midi_list; /* list of midi interfaces */ 53 struct list_head midi_list; /* list of midi interfaces */