Thomas Gleixner | a10e763 | 2019-05-31 01:09:32 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 2 | /* |
Chris Rorvick | c078a4a | 2015-01-20 02:20:50 -0600 | [diff] [blame] | 3 | * Line 6 Linux USB driver |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 4 | * |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 5 | * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 6 | */ |
| 7 | |
Stefan Hajnoczi | 140e28b | 2011-11-23 08:20:45 +0000 | [diff] [blame] | 8 | #include <linux/slab.h> |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 9 | #include <sound/core.h> |
| 10 | #include <sound/pcm.h> |
| 11 | #include <sound/pcm_params.h> |
| 12 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 13 | #include "capture.h" |
| 14 | #include "driver.h" |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 15 | #include "pcm.h" |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 16 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 17 | /* |
| 18 | Find a free URB and submit it. |
Takashi Iwai | 3d3ae44 | 2015-01-27 12:50:44 +0100 | [diff] [blame] | 19 | must be called in line6pcm->in.lock context |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 20 | */ |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 21 | static int submit_audio_in_urb(struct snd_line6_pcm *line6pcm) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 22 | { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 23 | int index; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 24 | int i, urb_size; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 25 | int ret; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 26 | struct urb *urb_in; |
| 27 | |
Andrej Krutak | b2233d9 | 2016-09-18 20:59:21 +0200 | [diff] [blame] | 28 | index = find_first_zero_bit(&line6pcm->in.active_urbs, |
| 29 | line6pcm->line6->iso_buffers); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 30 | |
Andrej Krutak | b2233d9 | 2016-09-18 20:59:21 +0200 | [diff] [blame] | 31 | if (index < 0 || index >= line6pcm->line6->iso_buffers) { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 32 | dev_err(line6pcm->line6->ifcdev, "no free URB found\n"); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 33 | return -EINVAL; |
| 34 | } |
| 35 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 36 | urb_in = line6pcm->in.urbs[index]; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 37 | urb_size = 0; |
| 38 | |
Greg Kroah-Hartman | 6efc566 | 2009-02-27 22:39:22 -0800 | [diff] [blame] | 39 | for (i = 0; i < LINE6_ISO_PACKETS; ++i) { |
Shawn Bohrer | e0645d6 | 2009-11-15 22:17:52 -0600 | [diff] [blame] | 40 | struct usb_iso_packet_descriptor *fin = |
| 41 | &urb_in->iso_frame_desc[i]; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 42 | fin->offset = urb_size; |
Andrej Krutak | 7a0f55a | 2016-09-18 20:59:23 +0200 | [diff] [blame] | 43 | fin->length = line6pcm->max_packet_size_in; |
| 44 | urb_size += line6pcm->max_packet_size_in; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Shawn Bohrer | e0645d6 | 2009-11-15 22:17:52 -0600 | [diff] [blame] | 47 | urb_in->transfer_buffer = |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 48 | line6pcm->in.buffer + |
Andrej Krutak | 7a0f55a | 2016-09-18 20:59:23 +0200 | [diff] [blame] | 49 | index * LINE6_ISO_PACKETS * line6pcm->max_packet_size_in; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 50 | urb_in->transfer_buffer_length = urb_size; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 51 | urb_in->context = line6pcm; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 52 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 53 | ret = usb_submit_urb(urb_in, GFP_ATOMIC); |
| 54 | |
| 55 | if (ret == 0) |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 56 | set_bit(index, &line6pcm->in.active_urbs); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 57 | else |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 58 | dev_err(line6pcm->line6->ifcdev, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 59 | "URB in #%d submission failed (%d)\n", index, ret); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 60 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | Submit all currently available capture URBs. |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 66 | must be called in line6pcm->in.lock context |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 67 | */ |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 68 | int line6_submit_audio_in_all_urbs(struct snd_line6_pcm *line6pcm) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 69 | { |
Takashi Iwai | 3d3ae44 | 2015-01-27 12:50:44 +0100 | [diff] [blame] | 70 | int ret = 0, i; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 71 | |
Andrej Krutak | b2233d9 | 2016-09-18 20:59:21 +0200 | [diff] [blame] | 72 | for (i = 0; i < line6pcm->line6->iso_buffers; ++i) { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 73 | ret = submit_audio_in_urb(line6pcm); |
Greg Kroah-Hartman | 6efc566 | 2009-02-27 22:39:22 -0800 | [diff] [blame] | 74 | if (ret < 0) |
Takashi Iwai | 3d3ae44 | 2015-01-27 12:50:44 +0100 | [diff] [blame] | 75 | break; |
Greg Kroah-Hartman | 6efc566 | 2009-02-27 22:39:22 -0800 | [diff] [blame] | 76 | } |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 77 | |
Takashi Iwai | 3d3ae44 | 2015-01-27 12:50:44 +0100 | [diff] [blame] | 78 | return ret; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /* |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 82 | Copy data into ALSA capture buffer. |
| 83 | */ |
| 84 | void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf, int fsize) |
| 85 | { |
| 86 | struct snd_pcm_substream *substream = |
| 87 | get_substream(line6pcm, SNDRV_PCM_STREAM_CAPTURE); |
| 88 | struct snd_pcm_runtime *runtime = substream->runtime; |
Andrej Krutak | 97d78ac | 2016-09-18 20:59:24 +0200 | [diff] [blame] | 89 | const int bytes_per_frame = |
| 90 | line6pcm->properties->bytes_per_channel * |
| 91 | line6pcm->properties->capture_hw.channels_max; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 92 | int frames = fsize / bytes_per_frame; |
| 93 | |
Peter Huewe | 597a1e7 | 2010-12-07 23:38:02 +0100 | [diff] [blame] | 94 | if (runtime == NULL) |
Markus Grabner | c7fcf25 | 2010-09-17 23:33:25 +0200 | [diff] [blame] | 95 | return; |
| 96 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 97 | if (line6pcm->in.pos_done + frames > runtime->buffer_size) { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 98 | /* |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 99 | The transferred area goes over buffer boundary, |
| 100 | copy two separate chunks. |
| 101 | */ |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 102 | int len; |
Mikhail Boiko | b5f87cf | 2014-03-18 23:59:46 +0200 | [diff] [blame] | 103 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 104 | len = runtime->buffer_size - line6pcm->in.pos_done; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 105 | |
| 106 | if (len > 0) { |
| 107 | memcpy(runtime->dma_area + |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 108 | line6pcm->in.pos_done * bytes_per_frame, fbuf, |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 109 | len * bytes_per_frame); |
| 110 | memcpy(runtime->dma_area, fbuf + len * bytes_per_frame, |
| 111 | (frames - len) * bytes_per_frame); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 112 | } else { |
| 113 | /* this is somewhat paranoid */ |
| 114 | dev_err(line6pcm->line6->ifcdev, |
| 115 | "driver bug: len = %d\n", len); |
| 116 | } |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 117 | } else { |
| 118 | /* copy single chunk */ |
| 119 | memcpy(runtime->dma_area + |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 120 | line6pcm->in.pos_done * bytes_per_frame, fbuf, fsize); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 121 | } |
| 122 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 123 | line6pcm->in.pos_done += frames; |
| 124 | if (line6pcm->in.pos_done >= runtime->buffer_size) |
| 125 | line6pcm->in.pos_done -= runtime->buffer_size; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void line6_capture_check_period(struct snd_line6_pcm *line6pcm, int length) |
| 129 | { |
| 130 | struct snd_pcm_substream *substream = |
| 131 | get_substream(line6pcm, SNDRV_PCM_STREAM_CAPTURE); |
| 132 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 133 | line6pcm->in.bytes += length; |
| 134 | if (line6pcm->in.bytes >= line6pcm->in.period) { |
| 135 | line6pcm->in.bytes %= line6pcm->in.period; |
Takashi Iwai | 3d3ae44 | 2015-01-27 12:50:44 +0100 | [diff] [blame] | 136 | spin_unlock(&line6pcm->in.lock); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 137 | snd_pcm_period_elapsed(substream); |
Takashi Iwai | 3d3ae44 | 2015-01-27 12:50:44 +0100 | [diff] [blame] | 138 | spin_lock(&line6pcm->in.lock); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
| 142 | /* |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 143 | * Callback for completed capture URB. |
| 144 | */ |
Greg Kroah-Hartman | 0c7ab15 | 2009-02-27 20:28:04 -0800 | [diff] [blame] | 145 | static void audio_in_callback(struct urb *urb) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 146 | { |
| 147 | int i, index, length = 0, shutdown = 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 148 | unsigned long flags; |
| 149 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 150 | struct snd_line6_pcm *line6pcm = (struct snd_line6_pcm *)urb->context; |
| 151 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 152 | line6pcm->in.last_frame = urb->start_frame; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 153 | |
| 154 | /* find index of URB */ |
Andrej Krutak | b2233d9 | 2016-09-18 20:59:21 +0200 | [diff] [blame] | 155 | for (index = 0; index < line6pcm->line6->iso_buffers; ++index) |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 156 | if (urb == line6pcm->in.urbs[index]) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 157 | break; |
| 158 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 159 | spin_lock_irqsave(&line6pcm->in.lock, flags); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 160 | |
Greg Kroah-Hartman | 6efc566 | 2009-02-27 22:39:22 -0800 | [diff] [blame] | 161 | for (i = 0; i < LINE6_ISO_PACKETS; ++i) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 162 | char *fbuf; |
| 163 | int fsize; |
| 164 | struct usb_iso_packet_descriptor *fin = &urb->iso_frame_desc[i]; |
| 165 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 166 | if (fin->status == -EXDEV) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 167 | shutdown = 1; |
| 168 | break; |
| 169 | } |
| 170 | |
| 171 | fbuf = urb->transfer_buffer + fin->offset; |
| 172 | fsize = fin->actual_length; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 173 | |
Andrej Krutak | 7a0f55a | 2016-09-18 20:59:23 +0200 | [diff] [blame] | 174 | if (fsize > line6pcm->max_packet_size_in) { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 175 | dev_err(line6pcm->line6->ifcdev, |
| 176 | "driver and/or device bug: packet too large (%d > %d)\n", |
Andrej Krutak | 7a0f55a | 2016-09-18 20:59:23 +0200 | [diff] [blame] | 177 | fsize, line6pcm->max_packet_size_in); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 180 | length += fsize; |
| 181 | |
Andrej Krutak | 79faa2b | 2016-09-18 20:59:22 +0200 | [diff] [blame] | 182 | BUILD_BUG_ON_MSG(LINE6_ISO_PACKETS != 1, |
| 183 | "The following code assumes LINE6_ISO_PACKETS == 1"); |
| 184 | /* TODO: |
| 185 | * Also, if iso_buffers != 2, the prev frame is almost random at |
| 186 | * playback side. |
| 187 | * This needs to be redesigned. It should be "stable", but we may |
| 188 | * experience sync problems on such high-speed configs. |
| 189 | */ |
| 190 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 191 | line6pcm->prev_fbuf = fbuf; |
Andrej Krutak | 97d78ac | 2016-09-18 20:59:24 +0200 | [diff] [blame] | 192 | line6pcm->prev_fsize = fsize / |
| 193 | (line6pcm->properties->bytes_per_channel * |
| 194 | line6pcm->properties->capture_hw.channels_max); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 195 | |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 196 | if (!test_bit(LINE6_STREAM_IMPULSE, &line6pcm->in.running) && |
| 197 | test_bit(LINE6_STREAM_PCM, &line6pcm->in.running) && |
| 198 | fsize > 0) |
| 199 | line6_capture_copy(line6pcm, fbuf, fsize); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 202 | clear_bit(index, &line6pcm->in.active_urbs); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 203 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 204 | if (test_and_clear_bit(index, &line6pcm->in.unlink_urbs)) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 205 | shutdown = 1; |
| 206 | |
Greg Kroah-Hartman | 6efc566 | 2009-02-27 22:39:22 -0800 | [diff] [blame] | 207 | if (!shutdown) { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 208 | submit_audio_in_urb(line6pcm); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 209 | |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 210 | if (!test_bit(LINE6_STREAM_IMPULSE, &line6pcm->in.running) && |
| 211 | test_bit(LINE6_STREAM_PCM, &line6pcm->in.running)) |
| 212 | line6_capture_check_period(line6pcm, length); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 213 | } |
Takashi Iwai | 3d3ae44 | 2015-01-27 12:50:44 +0100 | [diff] [blame] | 214 | |
| 215 | spin_unlock_irqrestore(&line6pcm->in.lock, flags); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /* open capture callback */ |
| 219 | static int snd_line6_capture_open(struct snd_pcm_substream *substream) |
| 220 | { |
| 221 | int err; |
| 222 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 223 | struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream); |
| 224 | |
Greg Kroah-Hartman | 6efc566 | 2009-02-27 22:39:22 -0800 | [diff] [blame] | 225 | err = snd_pcm_hw_constraint_ratdens(runtime, 0, |
| 226 | SNDRV_PCM_HW_PARAM_RATE, |
Takashi Iwai | 1263f61 | 2015-01-28 15:08:59 +0100 | [diff] [blame] | 227 | &line6pcm->properties->rates); |
Greg Kroah-Hartman | 6efc566 | 2009-02-27 22:39:22 -0800 | [diff] [blame] | 228 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 229 | return err; |
| 230 | |
Andrej Krutak | f56742c | 2016-09-18 20:59:25 +0200 | [diff] [blame] | 231 | line6_pcm_acquire(line6pcm, LINE6_STREAM_CAPTURE_HELPER, false); |
| 232 | |
Takashi Iwai | 1263f61 | 2015-01-28 15:08:59 +0100 | [diff] [blame] | 233 | runtime->hw = line6pcm->properties->capture_hw; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | /* close capture callback */ |
| 238 | static int snd_line6_capture_close(struct snd_pcm_substream *substream) |
| 239 | { |
Andrej Krutak | f56742c | 2016-09-18 20:59:25 +0200 | [diff] [blame] | 240 | struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream); |
| 241 | |
| 242 | line6_pcm_release(line6pcm, LINE6_STREAM_CAPTURE_HELPER); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 243 | return 0; |
| 244 | } |
| 245 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 246 | /* capture operators */ |
Bhumika Goyal | e195a33 | 2017-09-27 11:49:27 +0530 | [diff] [blame] | 247 | const struct snd_pcm_ops snd_line6_capture_ops = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 248 | .open = snd_line6_capture_open, |
| 249 | .close = snd_line6_capture_close, |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 250 | .hw_params = snd_line6_hw_params, |
| 251 | .hw_free = snd_line6_hw_free, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 252 | .prepare = snd_line6_prepare, |
| 253 | .trigger = snd_line6_trigger, |
Takashi Iwai | 2954f91 | 2015-01-27 15:41:27 +0100 | [diff] [blame] | 254 | .pointer = snd_line6_pointer, |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 255 | }; |
| 256 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 257 | int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 258 | { |
Chris Rorvick | 16d603d | 2015-01-12 12:42:55 -0800 | [diff] [blame] | 259 | struct usb_line6 *line6 = line6pcm->line6; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 260 | int i; |
| 261 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 262 | line6pcm->in.urbs = kcalloc(line6->iso_buffers, sizeof(struct urb *), |
| 263 | GFP_KERNEL); |
Andrej Krutak | b2233d9 | 2016-09-18 20:59:21 +0200 | [diff] [blame] | 264 | if (line6pcm->in.urbs == NULL) |
| 265 | return -ENOMEM; |
| 266 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 267 | /* create audio URBs and fill in constant values: */ |
Andrej Krutak | b2233d9 | 2016-09-18 20:59:21 +0200 | [diff] [blame] | 268 | for (i = 0; i < line6->iso_buffers; ++i) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 269 | struct urb *urb; |
| 270 | |
| 271 | /* URB for audio in: */ |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 272 | urb = line6pcm->in.urbs[i] = |
Shawn Bohrer | e0645d6 | 2009-11-15 22:17:52 -0600 | [diff] [blame] | 273 | usb_alloc_urb(LINE6_ISO_PACKETS, GFP_KERNEL); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 274 | |
Takashi Iwai | a019f5e | 2015-01-19 15:05:10 +0100 | [diff] [blame] | 275 | if (urb == NULL) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 276 | return -ENOMEM; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 277 | |
Chris Rorvick | 16d603d | 2015-01-12 12:42:55 -0800 | [diff] [blame] | 278 | urb->dev = line6->usbdev; |
Shawn Bohrer | e0645d6 | 2009-11-15 22:17:52 -0600 | [diff] [blame] | 279 | urb->pipe = |
Chris Rorvick | 16d603d | 2015-01-12 12:42:55 -0800 | [diff] [blame] | 280 | usb_rcvisocpipe(line6->usbdev, |
| 281 | line6->properties->ep_audio_r & |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 282 | USB_ENDPOINT_NUMBER_MASK); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 283 | urb->transfer_flags = URB_ISO_ASAP; |
| 284 | urb->start_frame = -1; |
| 285 | urb->number_of_packets = LINE6_ISO_PACKETS; |
| 286 | urb->interval = LINE6_ISO_INTERVAL; |
| 287 | urb->error_count = 0; |
| 288 | urb->complete = audio_in_callback; |
Takashi Iwai | 6e8a914 | 2020-07-10 15:33:51 +0200 | [diff] [blame] | 289 | if (usb_urb_ep_type_check(urb)) |
| 290 | return -EINVAL; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | return 0; |
| 294 | } |