diff options
author | Takashi Iwai <tiwai@suse.de> | 2005-11-17 04:48:52 -0500 |
---|---|---|
committer | Jaroslav Kysela <perex@suse.cz> | 2006-01-03 06:17:09 -0500 |
commit | cb432379eff40d5656ca9f24afc435b4df353d13 (patch) | |
tree | f00428351803fc5ad0b5b2c74c239402d47a7293 /sound/usb/usx2y/usbusx2yaudio.c | |
parent | 9fd9156c6b0dfb8630f68d11dc48a3e824aa64e6 (diff) |
[ALSA] usx2y - Code clean up
Modules: USB USX2Y
Clean up snd-usb-usx2y driver code:
- Avoid unnecessary cast
- Fix spaces/indents
- Use kzalloc()
- Remove weird debug prints
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/usb/usx2y/usbusx2yaudio.c')
-rw-r--r-- | sound/usb/usx2y/usbusx2yaudio.c | 184 |
1 files changed, 87 insertions, 97 deletions
diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c index c5989cb7db3f..e1dbfbba8fa9 100644 --- a/sound/usb/usx2y/usbusx2yaudio.c +++ b/sound/usb/usx2y/usbusx2yaudio.c | |||
@@ -205,47 +205,42 @@ static int usX2Y_urb_submit(snd_usX2Y_substream_t *subs, struct urb *urb, int fr | |||
205 | static inline int usX2Y_usbframe_complete(snd_usX2Y_substream_t *capsubs, snd_usX2Y_substream_t *playbacksubs, int frame) | 205 | static inline int usX2Y_usbframe_complete(snd_usX2Y_substream_t *capsubs, snd_usX2Y_substream_t *playbacksubs, int frame) |
206 | { | 206 | { |
207 | int err, state; | 207 | int err, state; |
208 | { | 208 | struct urb *urb = playbacksubs->completed_urb; |
209 | struct urb *urb = playbacksubs->completed_urb; | 209 | |
210 | 210 | state = atomic_read(&playbacksubs->state); | |
211 | state = atomic_read(&playbacksubs->state); | 211 | if (NULL != urb) { |
212 | if (NULL != urb) { | 212 | if (state == state_RUNNING) |
213 | if (state == state_RUNNING) | 213 | usX2Y_urb_play_retire(playbacksubs, urb); |
214 | usX2Y_urb_play_retire(playbacksubs, urb); | 214 | else |
215 | else | 215 | if (state >= state_PRERUNNING) |
216 | if (state >= state_PRERUNNING) { | ||
217 | atomic_inc(&playbacksubs->state); | ||
218 | } | ||
219 | } else { | ||
220 | switch (state) { | ||
221 | case state_STARTING1: | ||
222 | urb = playbacksubs->urb[0]; | ||
223 | atomic_inc(&playbacksubs->state); | 216 | atomic_inc(&playbacksubs->state); |
224 | break; | 217 | } else { |
225 | case state_STARTING2: | 218 | switch (state) { |
226 | urb = playbacksubs->urb[1]; | 219 | case state_STARTING1: |
227 | atomic_inc(&playbacksubs->state); | 220 | urb = playbacksubs->urb[0]; |
228 | break; | 221 | atomic_inc(&playbacksubs->state); |
229 | } | 222 | break; |
230 | } | 223 | case state_STARTING2: |
231 | if (urb) { | 224 | urb = playbacksubs->urb[1]; |
232 | if ((err = usX2Y_urb_play_prepare(playbacksubs, capsubs->completed_urb, urb)) || | 225 | atomic_inc(&playbacksubs->state); |
233 | (err = usX2Y_urb_submit(playbacksubs, urb, frame))) { | 226 | break; |
234 | return err; | ||
235 | } | ||
236 | } | 227 | } |
237 | |||
238 | playbacksubs->completed_urb = NULL; | ||
239 | } | 228 | } |
229 | if (urb) { | ||
230 | if ((err = usX2Y_urb_play_prepare(playbacksubs, capsubs->completed_urb, urb)) || | ||
231 | (err = usX2Y_urb_submit(playbacksubs, urb, frame))) | ||
232 | return err; | ||
233 | } | ||
234 | |||
235 | playbacksubs->completed_urb = NULL; | ||
236 | |||
240 | state = atomic_read(&capsubs->state); | 237 | state = atomic_read(&capsubs->state); |
241 | if (state >= state_PREPARED) { | 238 | if (state >= state_PREPARED) { |
242 | if (state == state_RUNNING) { | 239 | if (state == state_RUNNING) { |
243 | if ((err = usX2Y_urb_capt_retire(capsubs))) | 240 | if ((err = usX2Y_urb_capt_retire(capsubs))) |
244 | return err; | 241 | return err; |
245 | } else | 242 | } else if (state >= state_PRERUNNING) |
246 | if (state >= state_PRERUNNING) { | 243 | atomic_inc(&capsubs->state); |
247 | atomic_inc(&capsubs->state); | ||
248 | } | ||
249 | if ((err = usX2Y_urb_submit(capsubs, capsubs->completed_urb, frame))) | 244 | if ((err = usX2Y_urb_submit(capsubs, capsubs->completed_urb, frame))) |
250 | return err; | 245 | return err; |
251 | } | 246 | } |
@@ -429,7 +424,7 @@ static int usX2Y_urbs_allocate(snd_usX2Y_substream_t *subs) | |||
429 | } | 424 | } |
430 | /* allocate and initialize data urbs */ | 425 | /* allocate and initialize data urbs */ |
431 | for (i = 0; i < NRURBS; i++) { | 426 | for (i = 0; i < NRURBS; i++) { |
432 | struct urb** purb = subs->urb + i; | 427 | struct urb **purb = subs->urb + i; |
433 | if (*purb) { | 428 | if (*purb) { |
434 | usb_kill_urb(*purb); | 429 | usb_kill_urb(*purb); |
435 | continue; | 430 | continue; |
@@ -480,47 +475,45 @@ static int usX2Y_urbs_start(snd_usX2Y_substream_t *subs) | |||
480 | goto start; | 475 | goto start; |
481 | } | 476 | } |
482 | usX2Y->wait_iso_frame = -1; | 477 | usX2Y->wait_iso_frame = -1; |
478 | |||
483 | start: | 479 | start: |
484 | { | 480 | usX2Y_subs_startup(subs); |
485 | usX2Y_subs_startup(subs); | 481 | for (i = 0; i < NRURBS; i++) { |
486 | for (i = 0; i < NRURBS; i++) { | 482 | struct urb *urb = subs->urb[i]; |
487 | struct urb *urb = subs->urb[i]; | 483 | if (usb_pipein(urb->pipe)) { |
488 | if (usb_pipein(urb->pipe)) { | 484 | unsigned long pack; |
489 | unsigned long pack; | 485 | if (0 == i) |
490 | if (0 == i) | 486 | atomic_set(&subs->state, state_STARTING3); |
491 | atomic_set(&subs->state, state_STARTING3); | 487 | urb->dev = usX2Y->chip.dev; |
492 | urb->dev = usX2Y->chip.dev; | 488 | urb->transfer_flags = URB_ISO_ASAP; |
493 | urb->transfer_flags = URB_ISO_ASAP; | 489 | for (pack = 0; pack < nr_of_packs(); pack++) { |
494 | for (pack = 0; pack < nr_of_packs(); pack++) { | 490 | urb->iso_frame_desc[pack].offset = subs->maxpacksize * pack; |
495 | urb->iso_frame_desc[pack].offset = subs->maxpacksize * pack; | 491 | urb->iso_frame_desc[pack].length = subs->maxpacksize; |
496 | urb->iso_frame_desc[pack].length = subs->maxpacksize; | 492 | } |
497 | } | 493 | urb->transfer_buffer_length = subs->maxpacksize * nr_of_packs(); |
498 | urb->transfer_buffer_length = subs->maxpacksize * nr_of_packs(); | 494 | if ((err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { |
499 | if ((err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | 495 | snd_printk (KERN_ERR "cannot submit datapipe for urb %d, err = %d\n", i, err); |
500 | snd_printk (KERN_ERR "cannot submit datapipe for urb %d, err = %d\n", i, err); | 496 | err = -EPIPE; |
501 | err = -EPIPE; | 497 | goto cleanup; |
502 | goto cleanup; | ||
503 | } else { | ||
504 | if (0 > usX2Y->wait_iso_frame) | ||
505 | usX2Y->wait_iso_frame = urb->start_frame; | ||
506 | } | ||
507 | urb->transfer_flags = 0; | ||
508 | } else { | 498 | } else { |
509 | atomic_set(&subs->state, state_STARTING1); | 499 | if (0 > usX2Y->wait_iso_frame) |
510 | break; | 500 | usX2Y->wait_iso_frame = urb->start_frame; |
511 | } | 501 | } |
502 | urb->transfer_flags = 0; | ||
503 | } else { | ||
504 | atomic_set(&subs->state, state_STARTING1); | ||
505 | break; | ||
512 | } | 506 | } |
513 | err = 0; | 507 | } |
514 | wait_event(usX2Y->prepare_wait_queue, NULL == usX2Y->prepare_subs); | 508 | err = 0; |
515 | if (atomic_read(&subs->state) != state_PREPARED) { | 509 | wait_event(usX2Y->prepare_wait_queue, NULL == usX2Y->prepare_subs); |
516 | err = -EPIPE; | 510 | if (atomic_read(&subs->state) != state_PREPARED) |
517 | } | 511 | err = -EPIPE; |
518 | 512 | ||
519 | cleanup: | 513 | cleanup: |
520 | if (err) { | 514 | if (err) { |
521 | usX2Y_subs_startup_finish(usX2Y); | 515 | usX2Y_subs_startup_finish(usX2Y); |
522 | usX2Y_clients_stop(usX2Y); // something is completely wroong > stop evrything | 516 | usX2Y_clients_stop(usX2Y); // something is completely wroong > stop evrything |
523 | } | ||
524 | } | 517 | } |
525 | return err; | 518 | return err; |
526 | } | 519 | } |
@@ -667,13 +660,12 @@ static int usX2Y_rate_set(usX2Ydev_t *usX2Y, int rate) | |||
667 | struct s_c2 *ra = rate == 48000 ? SetRate48000 : SetRate44100; | 660 | struct s_c2 *ra = rate == 48000 ? SetRate48000 : SetRate44100; |
668 | 661 | ||
669 | if (usX2Y->rate != rate) { | 662 | if (usX2Y->rate != rate) { |
670 | us = kmalloc(sizeof(*us) + sizeof(struct urb*) * NOOF_SETRATE_URBS, GFP_KERNEL); | 663 | us = kzalloc(sizeof(*us) + sizeof(struct urb*) * NOOF_SETRATE_URBS, GFP_KERNEL); |
671 | if (NULL == us) { | 664 | if (NULL == us) { |
672 | err = -ENOMEM; | 665 | err = -ENOMEM; |
673 | goto cleanup; | 666 | goto cleanup; |
674 | } | 667 | } |
675 | memset(us, 0, sizeof(*us) + sizeof(struct urb*) * NOOF_SETRATE_URBS); | 668 | usbdata = kmalloc(sizeof(int) * NOOF_SETRATE_URBS, GFP_KERNEL); |
676 | usbdata = kmalloc(sizeof(int)*NOOF_SETRATE_URBS, GFP_KERNEL); | ||
677 | if (NULL == usbdata) { | 669 | if (NULL == usbdata) { |
678 | err = -ENOMEM; | 670 | err = -ENOMEM; |
679 | goto cleanup; | 671 | goto cleanup; |
@@ -713,9 +705,8 @@ static int usX2Y_rate_set(usX2Ydev_t *usX2Y, int rate) | |||
713 | usX2Y->US04 = NULL; | 705 | usX2Y->US04 = NULL; |
714 | kfree(usbdata); | 706 | kfree(usbdata); |
715 | kfree(us); | 707 | kfree(us); |
716 | if (!err) { | 708 | if (!err) |
717 | usX2Y->rate = rate; | 709 | usX2Y->rate = rate; |
718 | } | ||
719 | } | 710 | } |
720 | } | 711 | } |
721 | 712 | ||
@@ -759,30 +750,29 @@ static int snd_usX2Y_pcm_hw_params(snd_pcm_substream_t *substream, | |||
759 | int err = 0; | 750 | int err = 0; |
760 | unsigned int rate = params_rate(hw_params); | 751 | unsigned int rate = params_rate(hw_params); |
761 | snd_pcm_format_t format = params_format(hw_params); | 752 | snd_pcm_format_t format = params_format(hw_params); |
762 | snd_printdd("snd_usX2Y_hw_params(%p, %p)\n", substream, hw_params); | ||
763 | |||
764 | { // all pcm substreams off one usX2Y have to operate at the same rate & format | ||
765 | snd_card_t *card = substream->pstr->pcm->card; | 753 | snd_card_t *card = substream->pstr->pcm->card; |
766 | struct list_head *list; | 754 | struct list_head *list; |
767 | list_for_each(list, &card->devices) { | 755 | |
768 | snd_device_t *dev; | 756 | snd_printdd("snd_usX2Y_hw_params(%p, %p)\n", substream, hw_params); |
769 | snd_pcm_t *pcm; | 757 | // all pcm substreams off one usX2Y have to operate at the same rate & format |
770 | int s; | 758 | list_for_each(list, &card->devices) { |
771 | dev = snd_device(list); | 759 | snd_device_t *dev; |
772 | if (dev->type != SNDRV_DEV_PCM) | 760 | snd_pcm_t *pcm; |
773 | continue; | 761 | int s; |
774 | pcm = dev->device_data; | 762 | dev = snd_device(list); |
775 | for (s = 0; s < 2; ++s) { | 763 | if (dev->type != SNDRV_DEV_PCM) |
776 | snd_pcm_substream_t *test_substream; | 764 | continue; |
777 | test_substream = pcm->streams[s].substream; | 765 | pcm = dev->device_data; |
778 | if (test_substream && test_substream != substream && | 766 | for (s = 0; s < 2; ++s) { |
779 | test_substream->runtime && | 767 | snd_pcm_substream_t *test_substream; |
780 | ((test_substream->runtime->format && | 768 | test_substream = pcm->streams[s].substream; |
781 | test_substream->runtime->format != format) || | 769 | if (test_substream && test_substream != substream && |
782 | (test_substream->runtime->rate && | 770 | test_substream->runtime && |
783 | test_substream->runtime->rate != rate))) | 771 | ((test_substream->runtime->format && |
784 | return -EINVAL; | 772 | test_substream->runtime->format != format) || |
785 | } | 773 | (test_substream->runtime->rate && |
774 | test_substream->runtime->rate != rate))) | ||
775 | return -EINVAL; | ||
786 | } | 776 | } |
787 | } | 777 | } |
788 | if (0 > (err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)))) { | 778 | if (0 > (err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)))) { |