Merge tag 'md-3.4' of git://neil.brown.name/md
[cascardo/linux.git] / drivers / staging / line6 / capture.c
index 127f952..c85c5b6 100644 (file)
@@ -107,7 +107,7 @@ void line6_unlink_audio_in_urbs(struct snd_line6_pcm *line6pcm)
        Wait until unlinking of all currently active capture URBs has been
        finished.
 */
-static void wait_clear_audio_in_urbs(struct snd_line6_pcm *line6pcm)
+void line6_wait_clear_audio_in_urbs(struct snd_line6_pcm *line6pcm)
 {
        int timeout = HZ;
        unsigned int i;
@@ -134,7 +134,7 @@ static void wait_clear_audio_in_urbs(struct snd_line6_pcm *line6pcm)
 void line6_unlink_wait_clear_audio_in_urbs(struct snd_line6_pcm *line6pcm)
 {
        line6_unlink_audio_in_urbs(line6pcm);
-       wait_clear_audio_in_urbs(line6pcm);
+       line6_wait_clear_audio_in_urbs(line6pcm);
 }
 
 /*
@@ -193,25 +193,6 @@ void line6_capture_check_period(struct snd_line6_pcm *line6pcm, int length)
        }
 }
 
-int line6_alloc_capture_buffer(struct snd_line6_pcm *line6pcm)
-{
-       /* We may be invoked multiple times in a row so allocate once only */
-       if (line6pcm->buffer_in)
-               return 0;
-
-       line6pcm->buffer_in =
-               kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
-                       line6pcm->max_packet_size, GFP_KERNEL);
-
-       if (!line6pcm->buffer_in) {
-               dev_err(line6pcm->line6->ifcdev,
-                       "cannot malloc capture buffer\n");
-               return -ENOMEM;
-       }
-
-       return 0;
-}
-
 void line6_free_capture_buffer(struct snd_line6_pcm *line6pcm)
 {
        kfree(line6pcm->buffer_in);
@@ -273,9 +254,9 @@ static void audio_in_callback(struct urb *urb)
                line6pcm->prev_fsize = fsize;
 
 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
-               if (!(line6pcm->flags & MASK_PCM_IMPULSE))
+               if (!(line6pcm->flags & LINE6_BITS_PCM_IMPULSE))
 #endif
-                       if (test_bit(BIT_PCM_ALSA_CAPTURE, &line6pcm->flags)
+                       if (test_bit(LINE6_INDEX_PCM_ALSA_CAPTURE_STREAM, &line6pcm->flags)
                            && (fsize > 0))
                                line6_capture_copy(line6pcm, fbuf, fsize);
        }
@@ -291,9 +272,9 @@ static void audio_in_callback(struct urb *urb)
                submit_audio_in_urb(line6pcm);
 
 #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
-               if (!(line6pcm->flags & MASK_PCM_IMPULSE))
+               if (!(line6pcm->flags & LINE6_BITS_PCM_IMPULSE))
 #endif
-                       if (test_bit(BIT_PCM_ALSA_CAPTURE, &line6pcm->flags))
+                       if (test_bit(LINE6_INDEX_PCM_ALSA_CAPTURE_STREAM, &line6pcm->flags))
                                line6_capture_check_period(line6pcm, length);
        }
 }
@@ -341,17 +322,17 @@ static int snd_line6_capture_hw_params(struct snd_pcm_substream *substream,
        }
        /* -- [FD] end */
 
-       if ((line6pcm->flags & MASK_CAPTURE) == 0) {
-               ret = line6_alloc_capture_buffer(line6pcm);
+       ret = line6_pcm_acquire(line6pcm, LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER);
 
-               if (ret < 0)
-                       return ret;
-       }
+       if (ret < 0)
+               return ret;
 
        ret = snd_pcm_lib_malloc_pages(substream,
                                       params_buffer_bytes(hw_params));
-       if (ret < 0)
+       if (ret < 0) {
+               line6_pcm_release(line6pcm, LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER);
                return ret;
+       }
 
        line6pcm->period_in = params_period_bytes(hw_params);
        return 0;
@@ -361,12 +342,7 @@ static int snd_line6_capture_hw_params(struct snd_pcm_substream *substream,
 static int snd_line6_capture_hw_free(struct snd_pcm_substream *substream)
 {
        struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
-
-       if ((line6pcm->flags & MASK_CAPTURE) == 0) {
-               line6_unlink_wait_clear_audio_in_urbs(line6pcm);
-               line6_free_capture_buffer(line6pcm);
-       }
-
+       line6_pcm_release(line6pcm, LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER);
        return snd_pcm_lib_free_pages(substream);
 }
 
@@ -380,7 +356,7 @@ int snd_line6_capture_trigger(struct snd_line6_pcm *line6pcm, int cmd)
 #ifdef CONFIG_PM
        case SNDRV_PCM_TRIGGER_RESUME:
 #endif
-               err = line6_pcm_start(line6pcm, MASK_PCM_ALSA_CAPTURE);
+               err = line6_pcm_acquire(line6pcm, LINE6_BIT_PCM_ALSA_CAPTURE_STREAM);
 
                if (err < 0)
                        return err;
@@ -391,7 +367,7 @@ int snd_line6_capture_trigger(struct snd_line6_pcm *line6pcm, int cmd)
 #ifdef CONFIG_PM
        case SNDRV_PCM_TRIGGER_SUSPEND:
 #endif
-               err = line6_pcm_stop(line6pcm, MASK_PCM_ALSA_CAPTURE);
+               err = line6_pcm_release(line6pcm, LINE6_BIT_PCM_ALSA_CAPTURE_STREAM);
 
                if (err < 0)
                        return err;