aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb/usx2y/usx2yhwdeppcm.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/usb/usx2y/usx2yhwdeppcm.c')
-rw-r--r--sound/usb/usx2y/usx2yhwdeppcm.c206
1 files changed, 102 insertions, 104 deletions
diff --git a/sound/usb/usx2y/usx2yhwdeppcm.c b/sound/usb/usx2y/usx2yhwdeppcm.c
index c9136a98755f..796a7dcef09d 100644
--- a/sound/usb/usx2y/usx2yhwdeppcm.c
+++ b/sound/usb/usx2y/usx2yhwdeppcm.c
@@ -58,12 +58,12 @@
58#include <sound/hwdep.h> 58#include <sound/hwdep.h>
59 59
60 60
61static int usX2Y_usbpcm_urb_capt_retire(snd_usX2Y_substream_t *subs) 61static int usX2Y_usbpcm_urb_capt_retire(struct snd_usX2Y_substream *subs)
62{ 62{
63 struct urb *urb = subs->completed_urb; 63 struct urb *urb = subs->completed_urb;
64 snd_pcm_runtime_t *runtime = subs->pcm_substream->runtime; 64 struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime;
65 int i, lens = 0, hwptr_done = subs->hwptr_done; 65 int i, lens = 0, hwptr_done = subs->hwptr_done;
66 usX2Ydev_t *usX2Y = subs->usX2Y; 66 struct usX2Ydev *usX2Y = subs->usX2Y;
67 if (0 > usX2Y->hwdep_pcm_shm->capture_iso_start) { //FIXME 67 if (0 > usX2Y->hwdep_pcm_shm->capture_iso_start) { //FIXME
68 int head = usX2Y->hwdep_pcm_shm->captured_iso_head + 1; 68 int head = usX2Y->hwdep_pcm_shm->captured_iso_head + 1;
69 if (head >= ARRAY_SIZE(usX2Y->hwdep_pcm_shm->captured_iso)) 69 if (head >= ARRAY_SIZE(usX2Y->hwdep_pcm_shm->captured_iso))
@@ -90,7 +90,8 @@ static int usX2Y_usbpcm_urb_capt_retire(snd_usX2Y_substream_t *subs)
90 return 0; 90 return 0;
91} 91}
92 92
93static inline int usX2Y_iso_frames_per_buffer(snd_pcm_runtime_t *runtime, usX2Ydev_t * usX2Y) 93static inline int usX2Y_iso_frames_per_buffer(struct snd_pcm_runtime *runtime,
94 struct usX2Ydev * usX2Y)
94{ 95{
95 return (runtime->buffer_size * 1000) / usX2Y->rate + 1; //FIXME: so far only correct period_size == 2^x ? 96 return (runtime->buffer_size * 1000) / usX2Y->rate + 1; //FIXME: so far only correct period_size == 2^x ?
96} 97}
@@ -105,13 +106,13 @@ static inline int usX2Y_iso_frames_per_buffer(snd_pcm_runtime_t *runtime, usX2Yd
105 * it directly from the buffer. thus the data is once copied to 106 * it directly from the buffer. thus the data is once copied to
106 * a temporary buffer and urb points to that. 107 * a temporary buffer and urb points to that.
107 */ 108 */
108static int usX2Y_hwdep_urb_play_prepare(snd_usX2Y_substream_t *subs, 109static int usX2Y_hwdep_urb_play_prepare(struct snd_usX2Y_substream *subs,
109 struct urb *urb) 110 struct urb *urb)
110{ 111{
111 int count, counts, pack; 112 int count, counts, pack;
112 usX2Ydev_t *usX2Y = subs->usX2Y; 113 struct usX2Ydev *usX2Y = subs->usX2Y;
113 struct snd_usX2Y_hwdep_pcm_shm *shm = usX2Y->hwdep_pcm_shm; 114 struct snd_usX2Y_hwdep_pcm_shm *shm = usX2Y->hwdep_pcm_shm;
114 snd_pcm_runtime_t *runtime = subs->pcm_substream->runtime; 115 struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime;
115 116
116 if (0 > shm->playback_iso_start) { 117 if (0 > shm->playback_iso_start) {
117 shm->playback_iso_start = shm->captured_iso_head - 118 shm->playback_iso_start = shm->captured_iso_head -
@@ -144,13 +145,14 @@ static int usX2Y_hwdep_urb_play_prepare(snd_usX2Y_substream_t *subs,
144} 145}
145 146
146 147
147static inline void usX2Y_usbpcm_urb_capt_iso_advance(snd_usX2Y_substream_t *subs, struct urb *urb) 148static inline void usX2Y_usbpcm_urb_capt_iso_advance(struct snd_usX2Y_substream *subs,
149 struct urb *urb)
148{ 150{
149 int pack; 151 int pack;
150 for (pack = 0; pack < nr_of_packs(); ++pack) { 152 for (pack = 0; pack < nr_of_packs(); ++pack) {
151 struct usb_iso_packet_descriptor *desc = urb->iso_frame_desc + pack; 153 struct usb_iso_packet_descriptor *desc = urb->iso_frame_desc + pack;
152 if (NULL != subs) { 154 if (NULL != subs) {
153 snd_usX2Y_hwdep_pcm_shm_t *shm = subs->usX2Y->hwdep_pcm_shm; 155 struct snd_usX2Y_hwdep_pcm_shm *shm = subs->usX2Y->hwdep_pcm_shm;
154 int head = shm->captured_iso_head + 1; 156 int head = shm->captured_iso_head + 1;
155 if (head >= ARRAY_SIZE(shm->captured_iso)) 157 if (head >= ARRAY_SIZE(shm->captured_iso))
156 head = 0; 158 head = 0;
@@ -166,9 +168,10 @@ static inline void usX2Y_usbpcm_urb_capt_iso_advance(snd_usX2Y_substream_t *subs
166 } 168 }
167} 169}
168 170
169static inline int usX2Y_usbpcm_usbframe_complete(snd_usX2Y_substream_t *capsubs, 171static inline int usX2Y_usbpcm_usbframe_complete(struct snd_usX2Y_substream *capsubs,
170 snd_usX2Y_substream_t *capsubs2, 172 struct snd_usX2Y_substream *capsubs2,
171 snd_usX2Y_substream_t *playbacksubs, int frame) 173 struct snd_usX2Y_substream *playbacksubs,
174 int frame)
172{ 175{
173 int err, state; 176 int err, state;
174 struct urb *urb = playbacksubs->completed_urb; 177 struct urb *urb = playbacksubs->completed_urb;
@@ -177,10 +180,8 @@ static inline int usX2Y_usbpcm_usbframe_complete(snd_usX2Y_substream_t *capsubs,
177 if (NULL != urb) { 180 if (NULL != urb) {
178 if (state == state_RUNNING) 181 if (state == state_RUNNING)
179 usX2Y_urb_play_retire(playbacksubs, urb); 182 usX2Y_urb_play_retire(playbacksubs, urb);
180 else 183 else if (state >= state_PRERUNNING)
181 if (state >= state_PRERUNNING) { 184 atomic_inc(&playbacksubs->state);
182 atomic_inc(&playbacksubs->state);
183 }
184 } else { 185 } else {
185 switch (state) { 186 switch (state) {
186 case state_STARTING1: 187 case state_STARTING1:
@@ -207,10 +208,8 @@ static inline int usX2Y_usbpcm_usbframe_complete(snd_usX2Y_substream_t *capsubs,
207 if (state == state_RUNNING) { 208 if (state == state_RUNNING) {
208 if ((err = usX2Y_usbpcm_urb_capt_retire(capsubs))) 209 if ((err = usX2Y_usbpcm_urb_capt_retire(capsubs)))
209 return err; 210 return err;
210 } else { 211 } else if (state >= state_PRERUNNING)
211 if (state >= state_PRERUNNING) 212 atomic_inc(&capsubs->state);
212 atomic_inc(&capsubs->state);
213 }
214 usX2Y_usbpcm_urb_capt_iso_advance(capsubs, capsubs->completed_urb); 213 usX2Y_usbpcm_urb_capt_iso_advance(capsubs, capsubs->completed_urb);
215 if (NULL != capsubs2) 214 if (NULL != capsubs2)
216 usX2Y_usbpcm_urb_capt_iso_advance(NULL, capsubs2->completed_urb); 215 usX2Y_usbpcm_urb_capt_iso_advance(NULL, capsubs2->completed_urb);
@@ -229,12 +228,15 @@ static inline int usX2Y_usbpcm_usbframe_complete(snd_usX2Y_substream_t *capsubs,
229 228
230static void i_usX2Y_usbpcm_urb_complete(struct urb *urb, struct pt_regs *regs) 229static void i_usX2Y_usbpcm_urb_complete(struct urb *urb, struct pt_regs *regs)
231{ 230{
232 snd_usX2Y_substream_t *subs = (snd_usX2Y_substream_t*)urb->context; 231 struct snd_usX2Y_substream *subs = urb->context;
233 usX2Ydev_t *usX2Y = subs->usX2Y; 232 struct usX2Ydev *usX2Y = subs->usX2Y;
234 snd_usX2Y_substream_t *capsubs, *capsubs2, *playbacksubs; 233 struct snd_usX2Y_substream *capsubs, *capsubs2, *playbacksubs;
235 234
236 if (unlikely(atomic_read(&subs->state) < state_PREPARED)) { 235 if (unlikely(atomic_read(&subs->state) < state_PREPARED)) {
237 snd_printdd("hcd_frame=%i ep=%i%s status=%i start_frame=%i\n", usb_get_current_frame_number(usX2Y->chip.dev), subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", urb->status, urb->start_frame); 236 snd_printdd("hcd_frame=%i ep=%i%s status=%i start_frame=%i\n",
237 usb_get_current_frame_number(usX2Y->chip.dev),
238 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out",
239 urb->status, urb->start_frame);
238 return; 240 return;
239 } 241 }
240 if (unlikely(urb->status)) { 242 if (unlikely(urb->status)) {
@@ -268,7 +270,7 @@ static void i_usX2Y_usbpcm_urb_complete(struct urb *urb, struct pt_regs *regs)
268} 270}
269 271
270 272
271static void usX2Y_hwdep_urb_release(struct urb** urb) 273static void usX2Y_hwdep_urb_release(struct urb **urb)
272{ 274{
273 usb_kill_urb(*urb); 275 usb_kill_urb(*urb);
274 usb_free_urb(*urb); 276 usb_free_urb(*urb);
@@ -278,7 +280,7 @@ static void usX2Y_hwdep_urb_release(struct urb** urb)
278/* 280/*
279 * release a substream 281 * release a substream
280 */ 282 */
281static void usX2Y_usbpcm_urbs_release(snd_usX2Y_substream_t *subs) 283static void usX2Y_usbpcm_urbs_release(struct snd_usX2Y_substream *subs)
282{ 284{
283 int i; 285 int i;
284 snd_printdd("snd_usX2Y_urbs_release() %i\n", subs->endpoint); 286 snd_printdd("snd_usX2Y_urbs_release() %i\n", subs->endpoint);
@@ -286,7 +288,7 @@ static void usX2Y_usbpcm_urbs_release(snd_usX2Y_substream_t *subs)
286 usX2Y_hwdep_urb_release(subs->urb + i); 288 usX2Y_hwdep_urb_release(subs->urb + i);
287} 289}
288 290
289static void usX2Y_usbpcm_subs_startup_finish(usX2Ydev_t * usX2Y) 291static void usX2Y_usbpcm_subs_startup_finish(struct usX2Ydev * usX2Y)
290{ 292{
291 usX2Y_urbs_set_complete(usX2Y, i_usX2Y_usbpcm_urb_complete); 293 usX2Y_urbs_set_complete(usX2Y, i_usX2Y_usbpcm_urb_complete);
292 usX2Y->prepare_subs = NULL; 294 usX2Y->prepare_subs = NULL;
@@ -294,14 +296,14 @@ static void usX2Y_usbpcm_subs_startup_finish(usX2Ydev_t * usX2Y)
294 296
295static void i_usX2Y_usbpcm_subs_startup(struct urb *urb, struct pt_regs *regs) 297static void i_usX2Y_usbpcm_subs_startup(struct urb *urb, struct pt_regs *regs)
296{ 298{
297 snd_usX2Y_substream_t *subs = (snd_usX2Y_substream_t*)urb->context; 299 struct snd_usX2Y_substream *subs = urb->context;
298 usX2Ydev_t *usX2Y = subs->usX2Y; 300 struct usX2Ydev *usX2Y = subs->usX2Y;
299 snd_usX2Y_substream_t *prepare_subs = usX2Y->prepare_subs; 301 struct snd_usX2Y_substream *prepare_subs = usX2Y->prepare_subs;
300 if (NULL != prepare_subs && 302 if (NULL != prepare_subs &&
301 urb->start_frame == prepare_subs->urb[0]->start_frame) { 303 urb->start_frame == prepare_subs->urb[0]->start_frame) {
302 atomic_inc(&prepare_subs->state); 304 atomic_inc(&prepare_subs->state);
303 if (prepare_subs == usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE]) { 305 if (prepare_subs == usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE]) {
304 snd_usX2Y_substream_t *cap_subs2 = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2]; 306 struct snd_usX2Y_substream *cap_subs2 = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2];
305 if (cap_subs2 != NULL) 307 if (cap_subs2 != NULL)
306 atomic_inc(&cap_subs2->state); 308 atomic_inc(&cap_subs2->state);
307 } 309 }
@@ -315,7 +317,7 @@ static void i_usX2Y_usbpcm_subs_startup(struct urb *urb, struct pt_regs *regs)
315/* 317/*
316 * initialize a substream's urbs 318 * initialize a substream's urbs
317 */ 319 */
318static int usX2Y_usbpcm_urbs_allocate(snd_usX2Y_substream_t *subs) 320static int usX2Y_usbpcm_urbs_allocate(struct snd_usX2Y_substream *subs)
319{ 321{
320 int i; 322 int i;
321 unsigned int pipe; 323 unsigned int pipe;
@@ -330,7 +332,7 @@ static int usX2Y_usbpcm_urbs_allocate(snd_usX2Y_substream_t *subs)
330 332
331 /* allocate and initialize data urbs */ 333 /* allocate and initialize data urbs */
332 for (i = 0; i < NRURBS; i++) { 334 for (i = 0; i < NRURBS; i++) {
333 struct urb** purb = subs->urb + i; 335 struct urb **purb = subs->urb + i;
334 if (*purb) { 336 if (*purb) {
335 usb_kill_urb(*purb); 337 usb_kill_urb(*purb);
336 continue; 338 continue;
@@ -359,16 +361,16 @@ static int usX2Y_usbpcm_urbs_allocate(snd_usX2Y_substream_t *subs)
359/* 361/*
360 * free the buffer 362 * free the buffer
361 */ 363 */
362static int snd_usX2Y_usbpcm_hw_free(snd_pcm_substream_t *substream) 364static int snd_usX2Y_usbpcm_hw_free(struct snd_pcm_substream *substream)
363{ 365{
364 snd_pcm_runtime_t *runtime = substream->runtime; 366 struct snd_pcm_runtime *runtime = substream->runtime;
365 snd_usX2Y_substream_t *subs = (snd_usX2Y_substream_t *)runtime->private_data, 367 struct snd_usX2Y_substream *subs = runtime->private_data,
366 *cap_subs2 = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2]; 368 *cap_subs2 = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2];
367 down(&subs->usX2Y->prepare_mutex); 369 down(&subs->usX2Y->prepare_mutex);
368 snd_printdd("snd_usX2Y_usbpcm_hw_free(%p)\n", substream); 370 snd_printdd("snd_usX2Y_usbpcm_hw_free(%p)\n", substream);
369 371
370 if (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) { 372 if (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) {
371 snd_usX2Y_substream_t *cap_subs = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE]; 373 struct snd_usX2Y_substream *cap_subs = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE];
372 atomic_set(&subs->state, state_STOPPED); 374 atomic_set(&subs->state, state_STOPPED);
373 usX2Y_usbpcm_urbs_release(subs); 375 usX2Y_usbpcm_urbs_release(subs);
374 if (!cap_subs->pcm_substream || 376 if (!cap_subs->pcm_substream ||
@@ -383,7 +385,7 @@ static int snd_usX2Y_usbpcm_hw_free(snd_pcm_substream_t *substream)
383 usX2Y_usbpcm_urbs_release(cap_subs2); 385 usX2Y_usbpcm_urbs_release(cap_subs2);
384 } 386 }
385 } else { 387 } else {
386 snd_usX2Y_substream_t *playback_subs = subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]; 388 struct snd_usX2Y_substream *playback_subs = subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK];
387 if (atomic_read(&playback_subs->state) < state_PREPARED) { 389 if (atomic_read(&playback_subs->state) < state_PREPARED) {
388 atomic_set(&subs->state, state_STOPPED); 390 atomic_set(&subs->state, state_STOPPED);
389 if (NULL != cap_subs2) 391 if (NULL != cap_subs2)
@@ -397,20 +399,20 @@ static int snd_usX2Y_usbpcm_hw_free(snd_pcm_substream_t *substream)
397 return snd_pcm_lib_free_pages(substream); 399 return snd_pcm_lib_free_pages(substream);
398} 400}
399 401
400static void usX2Y_usbpcm_subs_startup(snd_usX2Y_substream_t *subs) 402static void usX2Y_usbpcm_subs_startup(struct snd_usX2Y_substream *subs)
401{ 403{
402 usX2Ydev_t * usX2Y = subs->usX2Y; 404 struct usX2Ydev * usX2Y = subs->usX2Y;
403 usX2Y->prepare_subs = subs; 405 usX2Y->prepare_subs = subs;
404 subs->urb[0]->start_frame = -1; 406 subs->urb[0]->start_frame = -1;
405 smp_wmb(); // Make shure above modifications are seen by i_usX2Y_subs_startup() 407 smp_wmb(); // Make shure above modifications are seen by i_usX2Y_subs_startup()
406 usX2Y_urbs_set_complete(usX2Y, i_usX2Y_usbpcm_subs_startup); 408 usX2Y_urbs_set_complete(usX2Y, i_usX2Y_usbpcm_subs_startup);
407} 409}
408 410
409static int usX2Y_usbpcm_urbs_start(snd_usX2Y_substream_t *subs) 411static int usX2Y_usbpcm_urbs_start(struct snd_usX2Y_substream *subs)
410{ 412{
411 int p, u, err, 413 int p, u, err,
412 stream = subs->pcm_substream->stream; 414 stream = subs->pcm_substream->stream;
413 usX2Ydev_t *usX2Y = subs->usX2Y; 415 struct usX2Ydev *usX2Y = subs->usX2Y;
414 416
415 if (SNDRV_PCM_STREAM_CAPTURE == stream) { 417 if (SNDRV_PCM_STREAM_CAPTURE == stream) {
416 usX2Y->hwdep_pcm_shm->captured_iso_head = -1; 418 usX2Y->hwdep_pcm_shm->captured_iso_head = -1;
@@ -418,7 +420,7 @@ static int usX2Y_usbpcm_urbs_start(snd_usX2Y_substream_t *subs)
418 } 420 }
419 421
420 for (p = 0; 3 >= (stream + p); p += 2) { 422 for (p = 0; 3 >= (stream + p); p += 2) {
421 snd_usX2Y_substream_t *subs = usX2Y->subs[stream + p]; 423 struct snd_usX2Y_substream *subs = usX2Y->subs[stream + p];
422 if (subs != NULL) { 424 if (subs != NULL) {
423 if ((err = usX2Y_usbpcm_urbs_allocate(subs)) < 0) 425 if ((err = usX2Y_usbpcm_urbs_allocate(subs)) < 0)
424 return err; 426 return err;
@@ -427,7 +429,7 @@ static int usX2Y_usbpcm_urbs_start(snd_usX2Y_substream_t *subs)
427 } 429 }
428 430
429 for (p = 0; p < 4; p++) { 431 for (p = 0; p < 4; p++) {
430 snd_usX2Y_substream_t *subs = usX2Y->subs[p]; 432 struct snd_usX2Y_substream *subs = usX2Y->subs[p];
431 if (subs != NULL && atomic_read(&subs->state) >= state_PREPARED) 433 if (subs != NULL && atomic_read(&subs->state) >= state_PREPARED)
432 goto start; 434 goto start;
433 } 435 }
@@ -437,7 +439,7 @@ static int usX2Y_usbpcm_urbs_start(snd_usX2Y_substream_t *subs)
437 usX2Y_usbpcm_subs_startup(subs); 439 usX2Y_usbpcm_subs_startup(subs);
438 for (u = 0; u < NRURBS; u++) { 440 for (u = 0; u < NRURBS; u++) {
439 for (p = 0; 3 >= (stream + p); p += 2) { 441 for (p = 0; 3 >= (stream + p); p += 2) {
440 snd_usX2Y_substream_t *subs = usX2Y->subs[stream + p]; 442 struct snd_usX2Y_substream *subs = usX2Y->subs[stream + p];
441 if (subs != NULL) { 443 if (subs != NULL) {
442 struct urb *urb = subs->urb[u]; 444 struct urb *urb = subs->urb[u];
443 if (usb_pipein(urb->pipe)) { 445 if (usb_pipein(urb->pipe)) {
@@ -486,19 +488,19 @@ static int usX2Y_usbpcm_urbs_start(snd_usX2Y_substream_t *subs)
486 * 488 *
487 * set format and initialize urbs 489 * set format and initialize urbs
488 */ 490 */
489static int snd_usX2Y_usbpcm_prepare(snd_pcm_substream_t *substream) 491static int snd_usX2Y_usbpcm_prepare(struct snd_pcm_substream *substream)
490{ 492{
491 snd_pcm_runtime_t *runtime = substream->runtime; 493 struct snd_pcm_runtime *runtime = substream->runtime;
492 snd_usX2Y_substream_t *subs = (snd_usX2Y_substream_t *)runtime->private_data; 494 struct snd_usX2Y_substream *subs = runtime->private_data;
493 usX2Ydev_t *usX2Y = subs->usX2Y; 495 struct usX2Ydev *usX2Y = subs->usX2Y;
494 snd_usX2Y_substream_t *capsubs = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE]; 496 struct snd_usX2Y_substream *capsubs = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE];
495 int err = 0; 497 int err = 0;
496 snd_printdd("snd_usX2Y_pcm_prepare(%p)\n", substream); 498 snd_printdd("snd_usX2Y_pcm_prepare(%p)\n", substream);
497 499
498 if (NULL == usX2Y->hwdep_pcm_shm) { 500 if (NULL == usX2Y->hwdep_pcm_shm) {
499 if (NULL == (usX2Y->hwdep_pcm_shm = snd_malloc_pages(sizeof(snd_usX2Y_hwdep_pcm_shm_t), GFP_KERNEL))) 501 if (NULL == (usX2Y->hwdep_pcm_shm = snd_malloc_pages(sizeof(struct snd_usX2Y_hwdep_pcm_shm), GFP_KERNEL)))
500 return -ENOMEM; 502 return -ENOMEM;
501 memset(usX2Y->hwdep_pcm_shm, 0, sizeof(snd_usX2Y_hwdep_pcm_shm_t)); 503 memset(usX2Y->hwdep_pcm_shm, 0, sizeof(struct snd_usX2Y_hwdep_pcm_shm));
502 } 504 }
503 505
504 down(&usX2Y->prepare_mutex); 506 down(&usX2Y->prepare_mutex);
@@ -512,7 +514,8 @@ static int snd_usX2Y_usbpcm_prepare(snd_pcm_substream_t *substream)
512 if (usX2Y->rate != runtime->rate) 514 if (usX2Y->rate != runtime->rate)
513 if ((err = usX2Y_rate_set(usX2Y, runtime->rate)) < 0) 515 if ((err = usX2Y_rate_set(usX2Y, runtime->rate)) < 0)
514 goto up_prepare_mutex; 516 goto up_prepare_mutex;
515 snd_printdd("starting capture pipe for %s\n", subs == capsubs ? "self" : "playpipe"); 517 snd_printdd("starting capture pipe for %s\n", subs == capsubs ?
518 "self" : "playpipe");
516 if (0 > (err = usX2Y_usbpcm_urbs_start(capsubs))) 519 if (0 > (err = usX2Y_usbpcm_urbs_start(capsubs)))
517 goto up_prepare_mutex; 520 goto up_prepare_mutex;
518 } 521 }
@@ -520,8 +523,12 @@ static int snd_usX2Y_usbpcm_prepare(snd_pcm_substream_t *substream)
520 if (subs != capsubs) { 523 if (subs != capsubs) {
521 usX2Y->hwdep_pcm_shm->playback_iso_start = -1; 524 usX2Y->hwdep_pcm_shm->playback_iso_start = -1;
522 if (atomic_read(&subs->state) < state_PREPARED) { 525 if (atomic_read(&subs->state) < state_PREPARED) {
523 while (usX2Y_iso_frames_per_buffer(runtime, usX2Y) > usX2Y->hwdep_pcm_shm->captured_iso_frames) { 526 while (usX2Y_iso_frames_per_buffer(runtime, usX2Y) >
524 snd_printd("Wait: iso_frames_per_buffer=%i,captured_iso_frames=%i\n", usX2Y_iso_frames_per_buffer(runtime, usX2Y), usX2Y->hwdep_pcm_shm->captured_iso_frames); 527 usX2Y->hwdep_pcm_shm->captured_iso_frames) {
528 snd_printdd("Wait: iso_frames_per_buffer=%i,"
529 "captured_iso_frames=%i\n",
530 usX2Y_iso_frames_per_buffer(runtime, usX2Y),
531 usX2Y->hwdep_pcm_shm->captured_iso_frames);
525 if (msleep_interruptible(10)) { 532 if (msleep_interruptible(10)) {
526 err = -ERESTARTSYS; 533 err = -ERESTARTSYS;
527 goto up_prepare_mutex; 534 goto up_prepare_mutex;
@@ -530,7 +537,9 @@ static int snd_usX2Y_usbpcm_prepare(snd_pcm_substream_t *substream)
530 if (0 > (err = usX2Y_usbpcm_urbs_start(subs))) 537 if (0 > (err = usX2Y_usbpcm_urbs_start(subs)))
531 goto up_prepare_mutex; 538 goto up_prepare_mutex;
532 } 539 }
533 snd_printd("Ready: iso_frames_per_buffer=%i,captured_iso_frames=%i\n", usX2Y_iso_frames_per_buffer(runtime, usX2Y), usX2Y->hwdep_pcm_shm->captured_iso_frames); 540 snd_printdd("Ready: iso_frames_per_buffer=%i,captured_iso_frames=%i\n",
541 usX2Y_iso_frames_per_buffer(runtime, usX2Y),
542 usX2Y->hwdep_pcm_shm->captured_iso_frames);
534 } else 543 } else
535 usX2Y->hwdep_pcm_shm->capture_iso_start = -1; 544 usX2Y->hwdep_pcm_shm->capture_iso_start = -1;
536 545
@@ -539,7 +548,7 @@ static int snd_usX2Y_usbpcm_prepare(snd_pcm_substream_t *substream)
539 return err; 548 return err;
540} 549}
541 550
542static snd_pcm_hardware_t snd_usX2Y_4c = 551static struct snd_pcm_hardware snd_usX2Y_4c =
543{ 552{
544 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 553 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
545 SNDRV_PCM_INFO_BLOCK_TRANSFER | 554 SNDRV_PCM_INFO_BLOCK_TRANSFER |
@@ -560,11 +569,11 @@ static snd_pcm_hardware_t snd_usX2Y_4c =
560 569
561 570
562 571
563static int snd_usX2Y_usbpcm_open(snd_pcm_substream_t *substream) 572static int snd_usX2Y_usbpcm_open(struct snd_pcm_substream *substream)
564{ 573{
565 snd_usX2Y_substream_t *subs = ((snd_usX2Y_substream_t **) 574 struct snd_usX2Y_substream *subs = ((struct snd_usX2Y_substream **)
566 snd_pcm_substream_chip(substream))[substream->stream]; 575 snd_pcm_substream_chip(substream))[substream->stream];
567 snd_pcm_runtime_t *runtime = substream->runtime; 576 struct snd_pcm_runtime *runtime = substream->runtime;
568 577
569 if (!(subs->usX2Y->chip_status & USX2Y_STAT_CHIP_MMAP_PCM_URBS)) 578 if (!(subs->usX2Y->chip_status & USX2Y_STAT_CHIP_MMAP_PCM_URBS))
570 return -EBUSY; 579 return -EBUSY;
@@ -578,18 +587,17 @@ static int snd_usX2Y_usbpcm_open(snd_pcm_substream_t *substream)
578} 587}
579 588
580 589
581static int snd_usX2Y_usbpcm_close(snd_pcm_substream_t *substream) 590static int snd_usX2Y_usbpcm_close(struct snd_pcm_substream *substream)
582{ 591{
583 snd_pcm_runtime_t *runtime = substream->runtime; 592 struct snd_pcm_runtime *runtime = substream->runtime;
584 snd_usX2Y_substream_t *subs = (snd_usX2Y_substream_t *)runtime->private_data; 593 struct snd_usX2Y_substream *subs = runtime->private_data;
585 int err = 0; 594
586 snd_printd("\n");
587 subs->pcm_substream = NULL; 595 subs->pcm_substream = NULL;
588 return err; 596 return 0;
589} 597}
590 598
591 599
592static snd_pcm_ops_t snd_usX2Y_usbpcm_ops = 600static struct snd_pcm_ops snd_usX2Y_usbpcm_ops =
593{ 601{
594 .open = snd_usX2Y_usbpcm_open, 602 .open = snd_usX2Y_usbpcm_open,
595 .close = snd_usX2Y_usbpcm_close, 603 .close = snd_usX2Y_usbpcm_close,
@@ -602,11 +610,11 @@ static snd_pcm_ops_t snd_usX2Y_usbpcm_ops =
602}; 610};
603 611
604 612
605static int usX2Y_pcms_lock_check(snd_card_t *card) 613static int usX2Y_pcms_lock_check(struct snd_card *card)
606{ 614{
607 struct list_head *list; 615 struct list_head *list;
608 snd_device_t *dev; 616 struct snd_device *dev;
609 snd_pcm_t *pcm; 617 struct snd_pcm *pcm;
610 int err = 0; 618 int err = 0;
611 list_for_each(list, &card->devices) { 619 list_for_each(list, &card->devices) {
612 dev = snd_device(list); 620 dev = snd_device(list);
@@ -622,7 +630,7 @@ static int usX2Y_pcms_lock_check(snd_card_t *card)
622 continue; 630 continue;
623 pcm = dev->device_data; 631 pcm = dev->device_data;
624 for (s = 0; s < 2; ++s) { 632 for (s = 0; s < 2; ++s) {
625 snd_pcm_substream_t *substream; 633 struct snd_pcm_substream *substream;
626 substream = pcm->streams[s].substream; 634 substream = pcm->streams[s].substream;
627 if (substream && substream->ffile != NULL) 635 if (substream && substream->ffile != NULL)
628 err = -EBUSY; 636 err = -EBUSY;
@@ -632,11 +640,11 @@ static int usX2Y_pcms_lock_check(snd_card_t *card)
632} 640}
633 641
634 642
635static void usX2Y_pcms_unlock(snd_card_t *card) 643static void usX2Y_pcms_unlock(struct snd_card *card)
636{ 644{
637 struct list_head *list; 645 struct list_head *list;
638 snd_device_t *dev; 646 struct snd_device *dev;
639 snd_pcm_t *pcm; 647 struct snd_pcm *pcm;
640 list_for_each(list, &card->devices) { 648 list_for_each(list, &card->devices) {
641 dev = snd_device(list); 649 dev = snd_device(list);
642 if (dev->type != SNDRV_DEV_PCM) 650 if (dev->type != SNDRV_DEV_PCM)
@@ -647,10 +655,10 @@ static void usX2Y_pcms_unlock(snd_card_t *card)
647} 655}
648 656
649 657
650static int snd_usX2Y_hwdep_pcm_open(snd_hwdep_t *hw, struct file *file) 658static int snd_usX2Y_hwdep_pcm_open(struct snd_hwdep *hw, struct file *file)
651{ 659{
652 // we need to be the first 660 // we need to be the first
653 snd_card_t *card = hw->card; 661 struct snd_card *card = hw->card;
654 int err = usX2Y_pcms_lock_check(card); 662 int err = usX2Y_pcms_lock_check(card);
655 if (0 == err) 663 if (0 == err)
656 usX2Y(card)->chip_status |= USX2Y_STAT_CHIP_MMAP_PCM_URBS; 664 usX2Y(card)->chip_status |= USX2Y_STAT_CHIP_MMAP_PCM_URBS;
@@ -659,9 +667,9 @@ static int snd_usX2Y_hwdep_pcm_open(snd_hwdep_t *hw, struct file *file)
659} 667}
660 668
661 669
662static int snd_usX2Y_hwdep_pcm_release(snd_hwdep_t *hw, struct file *file) 670static int snd_usX2Y_hwdep_pcm_release(struct snd_hwdep *hw, struct file *file)
663{ 671{
664 snd_card_t *card = hw->card; 672 struct snd_card *card = hw->card;
665 int err = usX2Y_pcms_lock_check(card); 673 int err = usX2Y_pcms_lock_check(card);
666 if (0 == err) 674 if (0 == err)
667 usX2Y(hw->card)->chip_status &= ~USX2Y_STAT_CHIP_MMAP_PCM_URBS; 675 usX2Y(hw->card)->chip_status &= ~USX2Y_STAT_CHIP_MMAP_PCM_URBS;
@@ -689,7 +697,7 @@ static struct page * snd_usX2Y_hwdep_pcm_vm_nopage(struct vm_area_struct *area,
689 offset = area->vm_pgoff << PAGE_SHIFT; 697 offset = area->vm_pgoff << PAGE_SHIFT;
690 offset += address - area->vm_start; 698 offset += address - area->vm_start;
691 snd_assert((offset % PAGE_SIZE) == 0, return NOPAGE_OOM); 699 snd_assert((offset % PAGE_SIZE) == 0, return NOPAGE_OOM);
692 vaddr = (char*)((usX2Ydev_t*)area->vm_private_data)->hwdep_pcm_shm + offset; 700 vaddr = (char*)((struct usX2Ydev *)area->vm_private_data)->hwdep_pcm_shm + offset;
693 page = virt_to_page(vaddr); 701 page = virt_to_page(vaddr);
694 get_page(page); 702 get_page(page);
695 703
@@ -707,17 +715,17 @@ static struct vm_operations_struct snd_usX2Y_hwdep_pcm_vm_ops = {
707}; 715};
708 716
709 717
710static int snd_usX2Y_hwdep_pcm_mmap(snd_hwdep_t * hw, struct file *filp, struct vm_area_struct *area) 718static int snd_usX2Y_hwdep_pcm_mmap(struct snd_hwdep * hw, struct file *filp, struct vm_area_struct *area)
711{ 719{
712 unsigned long size = (unsigned long)(area->vm_end - area->vm_start); 720 unsigned long size = (unsigned long)(area->vm_end - area->vm_start);
713 usX2Ydev_t *usX2Y = (usX2Ydev_t*)hw->private_data; 721 struct usX2Ydev *usX2Y = hw->private_data;
714 722
715 if (!(((usX2Ydev_t*)hw->private_data)->chip_status & USX2Y_STAT_CHIP_INIT)) 723 if (!(usX2Y->chip_status & USX2Y_STAT_CHIP_INIT))
716 return -EBUSY; 724 return -EBUSY;
717 725
718 /* if userspace tries to mmap beyond end of our buffer, fail */ 726 /* if userspace tries to mmap beyond end of our buffer, fail */
719 if (size > PAGE_ALIGN(sizeof(snd_usX2Y_hwdep_pcm_shm_t))) { 727 if (size > PAGE_ALIGN(sizeof(struct snd_usX2Y_hwdep_pcm_shm))) {
720 snd_printd("%lu > %lu\n", size, (unsigned long)sizeof(snd_usX2Y_hwdep_pcm_shm_t)); 728 snd_printd("%lu > %lu\n", size, (unsigned long)sizeof(struct snd_usX2Y_hwdep_pcm_shm));
721 return -EINVAL; 729 return -EINVAL;
722 } 730 }
723 731
@@ -726,39 +734,31 @@ static int snd_usX2Y_hwdep_pcm_mmap(snd_hwdep_t * hw, struct file *filp, struct
726 } 734 }
727 area->vm_ops = &snd_usX2Y_hwdep_pcm_vm_ops; 735 area->vm_ops = &snd_usX2Y_hwdep_pcm_vm_ops;
728 area->vm_flags |= VM_RESERVED; 736 area->vm_flags |= VM_RESERVED;
729 snd_printd("vm_flags=0x%lX\n", area->vm_flags);
730 area->vm_private_data = hw->private_data; 737 area->vm_private_data = hw->private_data;
731 return 0; 738 return 0;
732} 739}
733 740
734 741
735static void snd_usX2Y_hwdep_pcm_private_free(snd_hwdep_t *hwdep) 742static void snd_usX2Y_hwdep_pcm_private_free(struct snd_hwdep *hwdep)
736{ 743{
737 usX2Ydev_t *usX2Y = (usX2Ydev_t *)hwdep->private_data; 744 struct usX2Ydev *usX2Y = hwdep->private_data;
738 if (NULL != usX2Y->hwdep_pcm_shm) 745 if (NULL != usX2Y->hwdep_pcm_shm)
739 snd_free_pages(usX2Y->hwdep_pcm_shm, sizeof(snd_usX2Y_hwdep_pcm_shm_t)); 746 snd_free_pages(usX2Y->hwdep_pcm_shm, sizeof(struct snd_usX2Y_hwdep_pcm_shm));
740} 747}
741 748
742 749
743static void snd_usX2Y_usbpcm_private_free(snd_pcm_t *pcm) 750int usX2Y_hwdep_pcm_new(struct snd_card *card)
744{
745 snd_pcm_lib_preallocate_free_for_all(pcm);
746}
747
748
749int usX2Y_hwdep_pcm_new(snd_card_t* card)
750{ 751{
751 int err; 752 int err;
752 snd_hwdep_t *hw; 753 struct snd_hwdep *hw;
753 snd_pcm_t *pcm; 754 struct snd_pcm *pcm;
754 struct usb_device *dev = usX2Y(card)->chip.dev; 755 struct usb_device *dev = usX2Y(card)->chip.dev;
755 if (1 != nr_of_packs()) 756 if (1 != nr_of_packs())
756 return 0; 757 return 0;
757 758
758 if ((err = snd_hwdep_new(card, SND_USX2Y_USBPCM_ID, 1, &hw)) < 0) { 759 if ((err = snd_hwdep_new(card, SND_USX2Y_USBPCM_ID, 1, &hw)) < 0)
759 snd_printd("\n");
760 return err; 760 return err;
761 } 761
762 hw->iface = SNDRV_HWDEP_IFACE_USX2Y_PCM; 762 hw->iface = SNDRV_HWDEP_IFACE_USX2Y_PCM;
763 hw->private_data = usX2Y(card); 763 hw->private_data = usX2Y(card);
764 hw->private_free = snd_usX2Y_hwdep_pcm_private_free; 764 hw->private_free = snd_usX2Y_hwdep_pcm_private_free;
@@ -776,7 +776,6 @@ int usX2Y_hwdep_pcm_new(snd_card_t* card)
776 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_usX2Y_usbpcm_ops); 776 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_usX2Y_usbpcm_ops);
777 777
778 pcm->private_data = usX2Y(card)->subs; 778 pcm->private_data = usX2Y(card)->subs;
779 pcm->private_free = snd_usX2Y_usbpcm_private_free;
780 pcm->info_flags = 0; 779 pcm->info_flags = 0;
781 780
782 sprintf(pcm->name, NAME_ALLCAPS" hwdep Audio"); 781 sprintf(pcm->name, NAME_ALLCAPS" hwdep Audio");
@@ -788,7 +787,6 @@ int usX2Y_hwdep_pcm_new(snd_card_t* card)
788 SNDRV_DMA_TYPE_CONTINUOUS, 787 SNDRV_DMA_TYPE_CONTINUOUS,
789 snd_dma_continuous_data(GFP_KERNEL), 788 snd_dma_continuous_data(GFP_KERNEL),
790 64*1024, 128*1024))) { 789 64*1024, 128*1024))) {
791 snd_usX2Y_usbpcm_private_free(pcm);
792 return err; 790 return err;
793 } 791 }
794 792
@@ -798,7 +796,7 @@ int usX2Y_hwdep_pcm_new(snd_card_t* card)
798 796
799#else 797#else
800 798
801int usX2Y_hwdep_pcm_new(snd_card_t* card) 799int usX2Y_hwdep_pcm_new(struct snd_card *card)
802{ 800{
803 return 0; 801 return 0;
804} 802}