Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * US-X2Y AUDIO |
| 3 | * Copyright (c) 2002-2004 by Karsten Wiese |
| 4 | * |
| 5 | * based on |
| 6 | * |
| 7 | * (Tentative) USB Audio Driver for ALSA |
| 8 | * |
| 9 | * Main and PCM part |
| 10 | * |
| 11 | * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> |
| 12 | * |
| 13 | * Many codes borrowed from audio.c by |
| 14 | * Alan Cox (alan@lxorguk.ukuu.org.uk) |
| 15 | * Thomas Sailer (sailer@ife.ee.ethz.ch) |
| 16 | * |
| 17 | * |
| 18 | * This program is free software; you can redistribute it and/or modify |
| 19 | * it under the terms of the GNU General Public License as published by |
| 20 | * the Free Software Foundation; either version 2 of the License, or |
| 21 | * (at your option) any later version. |
| 22 | * |
| 23 | * This program is distributed in the hope that it will be useful, |
| 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 26 | * GNU General Public License for more details. |
| 27 | * |
| 28 | * You should have received a copy of the GNU General Public License |
| 29 | * along with this program; if not, write to the Free Software |
| 30 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 31 | */ |
| 32 | |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/interrupt.h> |
| 35 | #include <linux/usb.h> |
| 36 | #include <sound/core.h> |
| 37 | #include <sound/info.h> |
| 38 | #include <sound/pcm.h> |
| 39 | #include <sound/pcm_params.h> |
| 40 | #include "usx2y.h" |
| 41 | #include "usbusx2y.h" |
| 42 | |
| 43 | #define USX2Y_NRPACKS 4 /* Default value used for nr of packs per urb. |
| 44 | 1 to 4 have been tested ok on uhci. |
| 45 | To use 3 on ohci, you'd need a patch: |
| 46 | look for "0000425-linux-2.6.9-rc4-mm1_ohci-hcd.patch.gz" on |
| 47 | "https://bugtrack.alsa-project.org/alsa-bug/bug_view_page.php?bug_id=0000425" |
| 48 | . |
| 49 | 1, 2 and 4 work out of the box on ohci, if I recall correctly. |
| 50 | Bigger is safer operation, |
| 51 | smaller gives lower latencies. |
| 52 | */ |
| 53 | #define USX2Y_NRPACKS_VARIABLE y /* If your system works ok with this module's parameter |
| 54 | nrpacks set to 1, you might as well comment |
| 55 | this #define out, and thereby produce smaller, faster code. |
| 56 | You'd also set USX2Y_NRPACKS to 1 then. |
| 57 | */ |
| 58 | |
| 59 | #ifdef USX2Y_NRPACKS_VARIABLE |
| 60 | static int nrpacks = USX2Y_NRPACKS; /* number of packets per urb */ |
| 61 | #define nr_of_packs() nrpacks |
| 62 | module_param(nrpacks, int, 0444); |
| 63 | MODULE_PARM_DESC(nrpacks, "Number of packets per URB."); |
| 64 | #else |
| 65 | #define nr_of_packs() USX2Y_NRPACKS |
| 66 | #endif |
| 67 | |
| 68 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 69 | static int usX2Y_urb_capt_retire(struct snd_usX2Y_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
| 71 | struct urb *urb = subs->completed_urb; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 72 | struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | unsigned char *cp; |
| 74 | int i, len, lens = 0, hwptr_done = subs->hwptr_done; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 75 | struct usX2Ydev *usX2Y = subs->usX2Y; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | for (i = 0; i < nr_of_packs(); i++) { |
| 78 | cp = (unsigned char*)urb->transfer_buffer + urb->iso_frame_desc[i].offset; |
| 79 | if (urb->iso_frame_desc[i].status) { /* active? hmm, skip this */ |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 80 | snd_printk(KERN_ERR "active frame status %i. " |
| 81 | "Most propably some hardware problem.\n", |
| 82 | urb->iso_frame_desc[i].status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | return urb->iso_frame_desc[i].status; |
| 84 | } |
| 85 | len = urb->iso_frame_desc[i].actual_length / usX2Y->stride; |
| 86 | if (! len) { |
| 87 | snd_printd("0 == len ERROR!\n"); |
| 88 | continue; |
| 89 | } |
| 90 | |
| 91 | /* copy a data chunk */ |
| 92 | if ((hwptr_done + len) > runtime->buffer_size) { |
| 93 | int cnt = runtime->buffer_size - hwptr_done; |
| 94 | int blen = cnt * usX2Y->stride; |
| 95 | memcpy(runtime->dma_area + hwptr_done * usX2Y->stride, cp, blen); |
| 96 | memcpy(runtime->dma_area, cp + blen, len * usX2Y->stride - blen); |
| 97 | } else { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 98 | memcpy(runtime->dma_area + hwptr_done * usX2Y->stride, cp, |
| 99 | len * usX2Y->stride); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | lens += len; |
| 102 | if ((hwptr_done += len) >= runtime->buffer_size) |
| 103 | hwptr_done -= runtime->buffer_size; |
| 104 | } |
| 105 | |
| 106 | subs->hwptr_done = hwptr_done; |
| 107 | subs->transfer_done += lens; |
| 108 | /* update the pointer, call callback if necessary */ |
| 109 | if (subs->transfer_done >= runtime->period_size) { |
| 110 | subs->transfer_done -= runtime->period_size; |
| 111 | snd_pcm_period_elapsed(subs->pcm_substream); |
| 112 | } |
| 113 | return 0; |
| 114 | } |
| 115 | /* |
| 116 | * prepare urb for playback data pipe |
| 117 | * |
| 118 | * we copy the data directly from the pcm buffer. |
| 119 | * the current position to be copied is held in hwptr field. |
| 120 | * since a urb can handle only a single linear buffer, if the total |
| 121 | * transferred area overflows the buffer boundary, we cannot send |
| 122 | * it directly from the buffer. thus the data is once copied to |
| 123 | * a temporary buffer and urb points to that. |
| 124 | */ |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 125 | static int usX2Y_urb_play_prepare(struct snd_usX2Y_substream *subs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | struct urb *cap_urb, |
| 127 | struct urb *urb) |
| 128 | { |
| 129 | int count, counts, pack; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 130 | struct usX2Ydev *usX2Y = subs->usX2Y; |
| 131 | struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | count = 0; |
| 134 | for (pack = 0; pack < nr_of_packs(); pack++) { |
| 135 | /* calculate the size of a packet */ |
| 136 | counts = cap_urb->iso_frame_desc[pack].actual_length / usX2Y->stride; |
| 137 | count += counts; |
| 138 | if (counts < 43 || counts > 50) { |
Takashi Iwai | d3d579f | 2005-10-21 16:20:11 +0200 | [diff] [blame] | 139 | snd_printk(KERN_ERR "should not be here with counts=%i\n", counts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | return -EPIPE; |
| 141 | } |
| 142 | /* set up descriptor */ |
| 143 | urb->iso_frame_desc[pack].offset = pack ? |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 144 | urb->iso_frame_desc[pack - 1].offset + |
| 145 | urb->iso_frame_desc[pack - 1].length : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | 0; |
| 147 | urb->iso_frame_desc[pack].length = cap_urb->iso_frame_desc[pack].actual_length; |
| 148 | } |
| 149 | if (atomic_read(&subs->state) >= state_PRERUNNING) |
| 150 | if (subs->hwptr + count > runtime->buffer_size) { |
| 151 | /* err, the transferred area goes over buffer boundary. |
| 152 | * copy the data to the temp buffer. |
| 153 | */ |
| 154 | int len; |
| 155 | len = runtime->buffer_size - subs->hwptr; |
| 156 | urb->transfer_buffer = subs->tmpbuf; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 157 | memcpy(subs->tmpbuf, runtime->dma_area + |
| 158 | subs->hwptr * usX2Y->stride, len * usX2Y->stride); |
| 159 | memcpy(subs->tmpbuf + len * usX2Y->stride, |
| 160 | runtime->dma_area, (count - len) * usX2Y->stride); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | subs->hwptr += count; |
| 162 | subs->hwptr -= runtime->buffer_size; |
| 163 | } else { |
| 164 | /* set the buffer pointer */ |
| 165 | urb->transfer_buffer = runtime->dma_area + subs->hwptr * usX2Y->stride; |
| 166 | if ((subs->hwptr += count) >= runtime->buffer_size) |
| 167 | subs->hwptr -= runtime->buffer_size; |
| 168 | } |
| 169 | else |
| 170 | urb->transfer_buffer = subs->tmpbuf; |
| 171 | urb->transfer_buffer_length = count * usX2Y->stride; |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * process after playback data complete |
| 177 | * |
| 178 | * update the current position and call callback if a period is processed. |
| 179 | */ |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 180 | static void usX2Y_urb_play_retire(struct snd_usX2Y_substream *subs, struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 182 | struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | int len = urb->actual_length / subs->usX2Y->stride; |
| 184 | |
| 185 | subs->transfer_done += len; |
| 186 | subs->hwptr_done += len; |
| 187 | if (subs->hwptr_done >= runtime->buffer_size) |
| 188 | subs->hwptr_done -= runtime->buffer_size; |
| 189 | if (subs->transfer_done >= runtime->period_size) { |
| 190 | subs->transfer_done -= runtime->period_size; |
| 191 | snd_pcm_period_elapsed(subs->pcm_substream); |
| 192 | } |
| 193 | } |
| 194 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 195 | static int usX2Y_urb_submit(struct snd_usX2Y_substream *subs, struct urb *urb, int frame) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | int err; |
| 198 | if (!urb) |
| 199 | return -ENODEV; |
| 200 | urb->start_frame = (frame + NRURBS * nr_of_packs()); // let hcd do rollover sanity checks |
| 201 | urb->hcpriv = NULL; |
| 202 | urb->dev = subs->usX2Y->chip.dev; /* we need to set this at each time */ |
| 203 | if ((err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { |
Takashi Iwai | d3d579f | 2005-10-21 16:20:11 +0200 | [diff] [blame] | 204 | snd_printk(KERN_ERR "usb_submit_urb() returned %i\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | return err; |
| 206 | } |
| 207 | return 0; |
| 208 | } |
| 209 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 210 | static inline int usX2Y_usbframe_complete(struct snd_usX2Y_substream *capsubs, |
| 211 | struct snd_usX2Y_substream *playbacksubs, |
| 212 | int frame) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
| 214 | int err, state; |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 215 | struct urb *urb = playbacksubs->completed_urb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 217 | state = atomic_read(&playbacksubs->state); |
| 218 | if (NULL != urb) { |
| 219 | if (state == state_RUNNING) |
| 220 | usX2Y_urb_play_retire(playbacksubs, urb); |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 221 | else if (state >= state_PRERUNNING) |
| 222 | atomic_inc(&playbacksubs->state); |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 223 | } else { |
| 224 | switch (state) { |
| 225 | case state_STARTING1: |
| 226 | urb = playbacksubs->urb[0]; |
| 227 | atomic_inc(&playbacksubs->state); |
| 228 | break; |
| 229 | case state_STARTING2: |
| 230 | urb = playbacksubs->urb[1]; |
| 231 | atomic_inc(&playbacksubs->state); |
| 232 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 235 | if (urb) { |
| 236 | if ((err = usX2Y_urb_play_prepare(playbacksubs, capsubs->completed_urb, urb)) || |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 237 | (err = usX2Y_urb_submit(playbacksubs, urb, frame))) { |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 238 | return err; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 239 | } |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | playbacksubs->completed_urb = NULL; |
| 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | state = atomic_read(&capsubs->state); |
| 245 | if (state >= state_PREPARED) { |
| 246 | if (state == state_RUNNING) { |
| 247 | if ((err = usX2Y_urb_capt_retire(capsubs))) |
| 248 | return err; |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 249 | } else if (state >= state_PRERUNNING) |
| 250 | atomic_inc(&capsubs->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | if ((err = usX2Y_urb_submit(capsubs, capsubs->completed_urb, frame))) |
| 252 | return err; |
| 253 | } |
| 254 | capsubs->completed_urb = NULL; |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 259 | static void usX2Y_clients_stop(struct usX2Ydev *usX2Y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | { |
| 261 | int s, u; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | for (s = 0; s < 4; s++) { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 264 | struct snd_usX2Y_substream *subs = usX2Y->subs[s]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | if (subs) { |
| 266 | snd_printdd("%i %p state=%i\n", s, subs, atomic_read(&subs->state)); |
| 267 | atomic_set(&subs->state, state_STOPPED); |
| 268 | } |
| 269 | } |
| 270 | for (s = 0; s < 4; s++) { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 271 | struct snd_usX2Y_substream *subs = usX2Y->subs[s]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | if (subs) { |
| 273 | if (atomic_read(&subs->state) >= state_PRERUNNING) { |
| 274 | snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN); |
| 275 | } |
| 276 | for (u = 0; u < NRURBS; u++) { |
| 277 | struct urb *urb = subs->urb[u]; |
| 278 | if (NULL != urb) |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 279 | snd_printdd("%i status=%i start_frame=%i\n", |
| 280 | u, urb->status, urb->start_frame); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | } |
| 284 | usX2Y->prepare_subs = NULL; |
| 285 | wake_up(&usX2Y->prepare_wait_queue); |
| 286 | } |
| 287 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 288 | static void usX2Y_error_urb_status(struct usX2Ydev *usX2Y, |
| 289 | struct snd_usX2Y_substream *subs, struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
Takashi Iwai | d3d579f | 2005-10-21 16:20:11 +0200 | [diff] [blame] | 291 | snd_printk(KERN_ERR "ep=%i stalled with status=%i\n", subs->endpoint, urb->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | urb->status = 0; |
| 293 | usX2Y_clients_stop(usX2Y); |
| 294 | } |
| 295 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 296 | static void usX2Y_error_sequence(struct usX2Ydev *usX2Y, |
| 297 | struct snd_usX2Y_substream *subs, struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { |
Takashi Iwai | d3d579f | 2005-10-21 16:20:11 +0200 | [diff] [blame] | 299 | snd_printk(KERN_ERR "Sequence Error!(hcd_frame=%i ep=%i%s;wait=%i,frame=%i).\n" |
| 300 | KERN_ERR "Most propably some urb of usb-frame %i is still missing.\n" |
| 301 | KERN_ERR "Cause could be too long delays in usb-hcd interrupt handling.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | usb_get_current_frame_number(usX2Y->chip.dev), |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 303 | subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", |
| 304 | usX2Y->wait_iso_frame, urb->start_frame, usX2Y->wait_iso_frame); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | usX2Y_clients_stop(usX2Y); |
| 306 | } |
| 307 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 308 | static void i_usX2Y_urb_complete(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 310 | struct snd_usX2Y_substream *subs = urb->context; |
| 311 | struct usX2Ydev *usX2Y = subs->usX2Y; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
| 313 | if (unlikely(atomic_read(&subs->state) < state_PREPARED)) { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 314 | snd_printdd("hcd_frame=%i ep=%i%s status=%i start_frame=%i\n", |
| 315 | usb_get_current_frame_number(usX2Y->chip.dev), |
| 316 | subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", |
| 317 | urb->status, urb->start_frame); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | return; |
| 319 | } |
| 320 | if (unlikely(urb->status)) { |
| 321 | usX2Y_error_urb_status(usX2Y, subs, urb); |
| 322 | return; |
| 323 | } |
Karsten Wiese | bc6191b | 2007-01-10 19:02:26 +0100 | [diff] [blame] | 324 | if (likely((urb->start_frame & 0xFFFF) == (usX2Y->wait_iso_frame & 0xFFFF))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | subs->completed_urb = urb; |
| 326 | else { |
| 327 | usX2Y_error_sequence(usX2Y, subs, urb); |
| 328 | return; |
| 329 | } |
| 330 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 331 | struct snd_usX2Y_substream *capsubs = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | *playbacksubs = usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 333 | if (capsubs->completed_urb && |
| 334 | atomic_read(&capsubs->state) >= state_PREPARED && |
| 335 | (playbacksubs->completed_urb || |
| 336 | atomic_read(&playbacksubs->state) < state_PREPARED)) { |
Karsten Wiese | 635bbb3 | 2006-10-04 17:17:32 +0200 | [diff] [blame] | 337 | if (!usX2Y_usbframe_complete(capsubs, playbacksubs, urb->start_frame)) |
| 338 | usX2Y->wait_iso_frame += nr_of_packs(); |
| 339 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | snd_printdd("\n"); |
| 341 | usX2Y_clients_stop(usX2Y); |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 347 | static void usX2Y_urbs_set_complete(struct usX2Ydev * usX2Y, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 348 | void (*complete)(struct urb *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
| 350 | int s, u; |
| 351 | for (s = 0; s < 4; s++) { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 352 | struct snd_usX2Y_substream *subs = usX2Y->subs[s]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (NULL != subs) |
| 354 | for (u = 0; u < NRURBS; u++) { |
| 355 | struct urb * urb = subs->urb[u]; |
| 356 | if (NULL != urb) |
| 357 | urb->complete = complete; |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 362 | static void usX2Y_subs_startup_finish(struct usX2Ydev * usX2Y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { |
| 364 | usX2Y_urbs_set_complete(usX2Y, i_usX2Y_urb_complete); |
| 365 | usX2Y->prepare_subs = NULL; |
| 366 | } |
| 367 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 368 | static void i_usX2Y_subs_startup(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 370 | struct snd_usX2Y_substream *subs = urb->context; |
| 371 | struct usX2Ydev *usX2Y = subs->usX2Y; |
| 372 | struct snd_usX2Y_substream *prepare_subs = usX2Y->prepare_subs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | if (NULL != prepare_subs) |
| 374 | if (urb->start_frame == prepare_subs->urb[0]->start_frame) { |
| 375 | usX2Y_subs_startup_finish(usX2Y); |
| 376 | atomic_inc(&prepare_subs->state); |
| 377 | wake_up(&usX2Y->prepare_wait_queue); |
| 378 | } |
| 379 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 380 | i_usX2Y_urb_complete(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 383 | static void usX2Y_subs_prepare(struct snd_usX2Y_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 385 | snd_printdd("usX2Y_substream_prepare(%p) ep=%i urb0=%p urb1=%p\n", |
| 386 | subs, subs->endpoint, subs->urb[0], subs->urb[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | /* reset the pointer */ |
| 388 | subs->hwptr = 0; |
| 389 | subs->hwptr_done = 0; |
| 390 | subs->transfer_done = 0; |
| 391 | } |
| 392 | |
| 393 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 394 | static void usX2Y_urb_release(struct urb **urb, int free_tb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
| 396 | if (*urb) { |
| 397 | usb_kill_urb(*urb); |
| 398 | if (free_tb) |
| 399 | kfree((*urb)->transfer_buffer); |
| 400 | usb_free_urb(*urb); |
| 401 | *urb = NULL; |
| 402 | } |
| 403 | } |
| 404 | /* |
| 405 | * release a substreams urbs |
| 406 | */ |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 407 | static void usX2Y_urbs_release(struct snd_usX2Y_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | { |
| 409 | int i; |
| 410 | snd_printdd("usX2Y_urbs_release() %i\n", subs->endpoint); |
| 411 | for (i = 0; i < NRURBS; i++) |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 412 | usX2Y_urb_release(subs->urb + i, |
| 413 | subs != subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Jesper Juhl | 4d57277 | 2005-05-30 17:30:32 +0200 | [diff] [blame] | 415 | kfree(subs->tmpbuf); |
| 416 | subs->tmpbuf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | /* |
| 419 | * initialize a substream's urbs |
| 420 | */ |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 421 | static int usX2Y_urbs_allocate(struct snd_usX2Y_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | { |
| 423 | int i; |
| 424 | unsigned int pipe; |
| 425 | int is_playback = subs == subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]; |
| 426 | struct usb_device *dev = subs->usX2Y->chip.dev; |
| 427 | |
| 428 | pipe = is_playback ? usb_sndisocpipe(dev, subs->endpoint) : |
| 429 | usb_rcvisocpipe(dev, subs->endpoint); |
| 430 | subs->maxpacksize = usb_maxpacket(dev, pipe, is_playback); |
| 431 | if (!subs->maxpacksize) |
| 432 | return -EINVAL; |
| 433 | |
| 434 | if (is_playback && NULL == subs->tmpbuf) { /* allocate a temporary buffer for playback */ |
| 435 | subs->tmpbuf = kcalloc(nr_of_packs(), subs->maxpacksize, GFP_KERNEL); |
| 436 | if (NULL == subs->tmpbuf) { |
| 437 | snd_printk(KERN_ERR "cannot malloc tmpbuf\n"); |
| 438 | return -ENOMEM; |
| 439 | } |
| 440 | } |
| 441 | /* allocate and initialize data urbs */ |
| 442 | for (i = 0; i < NRURBS; i++) { |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 443 | struct urb **purb = subs->urb + i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | if (*purb) { |
| 445 | usb_kill_urb(*purb); |
| 446 | continue; |
| 447 | } |
| 448 | *purb = usb_alloc_urb(nr_of_packs(), GFP_KERNEL); |
| 449 | if (NULL == *purb) { |
| 450 | usX2Y_urbs_release(subs); |
| 451 | return -ENOMEM; |
| 452 | } |
| 453 | if (!is_playback && !(*purb)->transfer_buffer) { |
| 454 | /* allocate a capture buffer per urb */ |
| 455 | (*purb)->transfer_buffer = kmalloc(subs->maxpacksize * nr_of_packs(), GFP_KERNEL); |
| 456 | if (NULL == (*purb)->transfer_buffer) { |
| 457 | usX2Y_urbs_release(subs); |
| 458 | return -ENOMEM; |
| 459 | } |
| 460 | } |
| 461 | (*purb)->dev = dev; |
| 462 | (*purb)->pipe = pipe; |
| 463 | (*purb)->number_of_packets = nr_of_packs(); |
| 464 | (*purb)->context = subs; |
| 465 | (*purb)->interval = 1; |
| 466 | (*purb)->complete = i_usX2Y_subs_startup; |
| 467 | } |
| 468 | return 0; |
| 469 | } |
| 470 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 471 | static void usX2Y_subs_startup(struct snd_usX2Y_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 473 | struct usX2Ydev *usX2Y = subs->usX2Y; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | usX2Y->prepare_subs = subs; |
| 475 | subs->urb[0]->start_frame = -1; |
| 476 | wmb(); |
| 477 | usX2Y_urbs_set_complete(usX2Y, i_usX2Y_subs_startup); |
| 478 | } |
| 479 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 480 | static int usX2Y_urbs_start(struct snd_usX2Y_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | { |
| 482 | int i, err; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 483 | struct usX2Ydev *usX2Y = subs->usX2Y; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | if ((err = usX2Y_urbs_allocate(subs)) < 0) |
| 486 | return err; |
| 487 | subs->completed_urb = NULL; |
| 488 | for (i = 0; i < 4; i++) { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 489 | struct snd_usX2Y_substream *subs = usX2Y->subs[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | if (subs != NULL && atomic_read(&subs->state) >= state_PREPARED) |
| 491 | goto start; |
| 492 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 494 | start: |
| 495 | usX2Y_subs_startup(subs); |
| 496 | for (i = 0; i < NRURBS; i++) { |
| 497 | struct urb *urb = subs->urb[i]; |
| 498 | if (usb_pipein(urb->pipe)) { |
| 499 | unsigned long pack; |
| 500 | if (0 == i) |
| 501 | atomic_set(&subs->state, state_STARTING3); |
| 502 | urb->dev = usX2Y->chip.dev; |
| 503 | urb->transfer_flags = URB_ISO_ASAP; |
| 504 | for (pack = 0; pack < nr_of_packs(); pack++) { |
| 505 | urb->iso_frame_desc[pack].offset = subs->maxpacksize * pack; |
| 506 | urb->iso_frame_desc[pack].length = subs->maxpacksize; |
| 507 | } |
| 508 | urb->transfer_buffer_length = subs->maxpacksize * nr_of_packs(); |
| 509 | if ((err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { |
| 510 | snd_printk (KERN_ERR "cannot submit datapipe for urb %d, err = %d\n", i, err); |
| 511 | err = -EPIPE; |
| 512 | goto cleanup; |
Karsten Wiese | 635bbb3 | 2006-10-04 17:17:32 +0200 | [diff] [blame] | 513 | } else |
| 514 | if (i == 0) |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 515 | usX2Y->wait_iso_frame = urb->start_frame; |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 516 | urb->transfer_flags = 0; |
| 517 | } else { |
| 518 | atomic_set(&subs->state, state_STARTING1); |
| 519 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
| 521 | } |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 522 | err = 0; |
| 523 | wait_event(usX2Y->prepare_wait_queue, NULL == usX2Y->prepare_subs); |
| 524 | if (atomic_read(&subs->state) != state_PREPARED) |
| 525 | err = -EPIPE; |
| 526 | |
| 527 | cleanup: |
| 528 | if (err) { |
| 529 | usX2Y_subs_startup_finish(usX2Y); |
| 530 | usX2Y_clients_stop(usX2Y); // something is completely wroong > stop evrything |
| 531 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | return err; |
| 533 | } |
| 534 | |
| 535 | /* |
| 536 | * return the current pcm pointer. just return the hwptr_done value. |
| 537 | */ |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 538 | static snd_pcm_uframes_t snd_usX2Y_pcm_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 540 | struct snd_usX2Y_substream *subs = substream->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | return subs->hwptr_done; |
| 542 | } |
| 543 | /* |
| 544 | * start/stop substream |
| 545 | */ |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 546 | static int snd_usX2Y_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 548 | struct snd_usX2Y_substream *subs = substream->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
| 550 | switch (cmd) { |
| 551 | case SNDRV_PCM_TRIGGER_START: |
| 552 | snd_printdd("snd_usX2Y_pcm_trigger(START)\n"); |
| 553 | if (atomic_read(&subs->state) == state_PREPARED && |
| 554 | atomic_read(&subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE]->state) >= state_PREPARED) { |
| 555 | atomic_set(&subs->state, state_PRERUNNING); |
| 556 | } else { |
| 557 | snd_printdd("\n"); |
| 558 | return -EPIPE; |
| 559 | } |
| 560 | break; |
| 561 | case SNDRV_PCM_TRIGGER_STOP: |
| 562 | snd_printdd("snd_usX2Y_pcm_trigger(STOP)\n"); |
| 563 | if (atomic_read(&subs->state) >= state_PRERUNNING) |
| 564 | atomic_set(&subs->state, state_PREPARED); |
| 565 | break; |
| 566 | default: |
| 567 | return -EINVAL; |
| 568 | } |
| 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | |
| 573 | /* |
| 574 | * allocate a buffer, setup samplerate |
| 575 | * |
| 576 | * so far we use a physically linear buffer although packetize transfer |
| 577 | * doesn't need a continuous area. |
| 578 | * if sg buffer is supported on the later version of alsa, we'll follow |
| 579 | * that. |
| 580 | */ |
| 581 | static struct s_c2 |
| 582 | { |
| 583 | char c1, c2; |
| 584 | } |
| 585 | SetRate44100[] = |
| 586 | { |
| 587 | { 0x14, 0x08}, // this line sets 44100, well actually a little less |
| 588 | { 0x18, 0x40}, // only tascam / frontier design knows the further lines ....... |
| 589 | { 0x18, 0x42}, |
| 590 | { 0x18, 0x45}, |
| 591 | { 0x18, 0x46}, |
| 592 | { 0x18, 0x48}, |
| 593 | { 0x18, 0x4A}, |
| 594 | { 0x18, 0x4C}, |
| 595 | { 0x18, 0x4E}, |
| 596 | { 0x18, 0x50}, |
| 597 | { 0x18, 0x52}, |
| 598 | { 0x18, 0x54}, |
| 599 | { 0x18, 0x56}, |
| 600 | { 0x18, 0x58}, |
| 601 | { 0x18, 0x5A}, |
| 602 | { 0x18, 0x5C}, |
| 603 | { 0x18, 0x5E}, |
| 604 | { 0x18, 0x60}, |
| 605 | { 0x18, 0x62}, |
| 606 | { 0x18, 0x64}, |
| 607 | { 0x18, 0x66}, |
| 608 | { 0x18, 0x68}, |
| 609 | { 0x18, 0x6A}, |
| 610 | { 0x18, 0x6C}, |
| 611 | { 0x18, 0x6E}, |
| 612 | { 0x18, 0x70}, |
| 613 | { 0x18, 0x72}, |
| 614 | { 0x18, 0x74}, |
| 615 | { 0x18, 0x76}, |
| 616 | { 0x18, 0x78}, |
| 617 | { 0x18, 0x7A}, |
| 618 | { 0x18, 0x7C}, |
| 619 | { 0x18, 0x7E} |
| 620 | }; |
| 621 | static struct s_c2 SetRate48000[] = |
| 622 | { |
| 623 | { 0x14, 0x09}, // this line sets 48000, well actually a little less |
| 624 | { 0x18, 0x40}, // only tascam / frontier design knows the further lines ....... |
| 625 | { 0x18, 0x42}, |
| 626 | { 0x18, 0x45}, |
| 627 | { 0x18, 0x46}, |
| 628 | { 0x18, 0x48}, |
| 629 | { 0x18, 0x4A}, |
| 630 | { 0x18, 0x4C}, |
| 631 | { 0x18, 0x4E}, |
| 632 | { 0x18, 0x50}, |
| 633 | { 0x18, 0x52}, |
| 634 | { 0x18, 0x54}, |
| 635 | { 0x18, 0x56}, |
| 636 | { 0x18, 0x58}, |
| 637 | { 0x18, 0x5A}, |
| 638 | { 0x18, 0x5C}, |
| 639 | { 0x18, 0x5E}, |
| 640 | { 0x18, 0x60}, |
| 641 | { 0x18, 0x62}, |
| 642 | { 0x18, 0x64}, |
| 643 | { 0x18, 0x66}, |
| 644 | { 0x18, 0x68}, |
| 645 | { 0x18, 0x6A}, |
| 646 | { 0x18, 0x6C}, |
| 647 | { 0x18, 0x6E}, |
| 648 | { 0x18, 0x70}, |
| 649 | { 0x18, 0x73}, |
| 650 | { 0x18, 0x74}, |
| 651 | { 0x18, 0x76}, |
| 652 | { 0x18, 0x78}, |
| 653 | { 0x18, 0x7A}, |
| 654 | { 0x18, 0x7C}, |
| 655 | { 0x18, 0x7E} |
| 656 | }; |
| 657 | #define NOOF_SETRATE_URBS ARRAY_SIZE(SetRate48000) |
| 658 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 659 | static void i_usX2Y_04Int(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 661 | struct usX2Ydev *usX2Y = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Takashi Iwai | d3d579f | 2005-10-21 16:20:11 +0200 | [diff] [blame] | 663 | if (urb->status) |
| 664 | snd_printk(KERN_ERR "snd_usX2Y_04Int() urb->status=%i\n", urb->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | if (0 == --usX2Y->US04->len) |
| 666 | wake_up(&usX2Y->In04WaitQueue); |
| 667 | } |
| 668 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 669 | static int usX2Y_rate_set(struct usX2Ydev *usX2Y, int rate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | { |
| 671 | int err = 0, i; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 672 | struct snd_usX2Y_urbSeq *us = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | int *usbdata = NULL; |
| 674 | struct s_c2 *ra = rate == 48000 ? SetRate48000 : SetRate44100; |
| 675 | |
| 676 | if (usX2Y->rate != rate) { |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 677 | us = kzalloc(sizeof(*us) + sizeof(struct urb*) * NOOF_SETRATE_URBS, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | if (NULL == us) { |
| 679 | err = -ENOMEM; |
| 680 | goto cleanup; |
| 681 | } |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 682 | usbdata = kmalloc(sizeof(int) * NOOF_SETRATE_URBS, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | if (NULL == usbdata) { |
| 684 | err = -ENOMEM; |
| 685 | goto cleanup; |
| 686 | } |
| 687 | for (i = 0; i < NOOF_SETRATE_URBS; ++i) { |
| 688 | if (NULL == (us->urb[i] = usb_alloc_urb(0, GFP_KERNEL))) { |
| 689 | err = -ENOMEM; |
| 690 | goto cleanup; |
| 691 | } |
| 692 | ((char*)(usbdata + i))[0] = ra[i].c1; |
| 693 | ((char*)(usbdata + i))[1] = ra[i].c2; |
| 694 | usb_fill_bulk_urb(us->urb[i], usX2Y->chip.dev, usb_sndbulkpipe(usX2Y->chip.dev, 4), |
| 695 | usbdata + i, 2, i_usX2Y_04Int, usX2Y); |
| 696 | #ifdef OLD_USB |
| 697 | us->urb[i]->transfer_flags = USB_QUEUE_BULK; |
| 698 | #endif |
| 699 | } |
| 700 | us->submitted = 0; |
| 701 | us->len = NOOF_SETRATE_URBS; |
| 702 | usX2Y->US04 = us; |
| 703 | wait_event_timeout(usX2Y->In04WaitQueue, 0 == us->len, HZ); |
| 704 | usX2Y->US04 = NULL; |
| 705 | if (us->len) |
| 706 | err = -ENODEV; |
| 707 | cleanup: |
| 708 | if (us) { |
| 709 | us->submitted = 2*NOOF_SETRATE_URBS; |
| 710 | for (i = 0; i < NOOF_SETRATE_URBS; ++i) { |
| 711 | struct urb *urb = us->urb[i]; |
| 712 | if (urb->status) { |
| 713 | if (!err) |
| 714 | err = -ENODEV; |
| 715 | usb_kill_urb(urb); |
| 716 | } |
| 717 | usb_free_urb(urb); |
| 718 | } |
| 719 | usX2Y->US04 = NULL; |
| 720 | kfree(usbdata); |
| 721 | kfree(us); |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 722 | if (!err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | usX2Y->rate = rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | } |
| 725 | } |
| 726 | |
| 727 | return err; |
| 728 | } |
| 729 | |
| 730 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 731 | static int usX2Y_format_set(struct usX2Ydev *usX2Y, snd_pcm_format_t format) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | { |
| 733 | int alternate, err; |
| 734 | struct list_head* p; |
| 735 | if (format == SNDRV_PCM_FORMAT_S24_3LE) { |
| 736 | alternate = 2; |
| 737 | usX2Y->stride = 6; |
| 738 | } else { |
| 739 | alternate = 1; |
| 740 | usX2Y->stride = 4; |
| 741 | } |
| 742 | list_for_each(p, &usX2Y->chip.midi_list) { |
| 743 | snd_usbmidi_input_stop(p); |
| 744 | } |
| 745 | usb_kill_urb(usX2Y->In04urb); |
| 746 | if ((err = usb_set_interface(usX2Y->chip.dev, 0, alternate))) { |
Takashi Iwai | d3d579f | 2005-10-21 16:20:11 +0200 | [diff] [blame] | 747 | snd_printk(KERN_ERR "usb_set_interface error \n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | return err; |
| 749 | } |
| 750 | usX2Y->In04urb->dev = usX2Y->chip.dev; |
| 751 | err = usb_submit_urb(usX2Y->In04urb, GFP_KERNEL); |
| 752 | list_for_each(p, &usX2Y->chip.midi_list) { |
| 753 | snd_usbmidi_input_start(p); |
| 754 | } |
| 755 | usX2Y->format = format; |
| 756 | usX2Y->rate = 0; |
| 757 | return err; |
| 758 | } |
| 759 | |
| 760 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 761 | static int snd_usX2Y_pcm_hw_params(struct snd_pcm_substream *substream, |
| 762 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | { |
| 764 | int err = 0; |
| 765 | unsigned int rate = params_rate(hw_params); |
| 766 | snd_pcm_format_t format = params_format(hw_params); |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 767 | struct snd_card *card = substream->pstr->pcm->card; |
| 768 | struct list_head *list; |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 769 | |
| 770 | snd_printdd("snd_usX2Y_hw_params(%p, %p)\n", substream, hw_params); |
| 771 | // all pcm substreams off one usX2Y have to operate at the same rate & format |
| 772 | list_for_each(list, &card->devices) { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 773 | struct snd_device *dev; |
| 774 | struct snd_pcm *pcm; |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 775 | int s; |
| 776 | dev = snd_device(list); |
| 777 | if (dev->type != SNDRV_DEV_PCM) |
| 778 | continue; |
| 779 | pcm = dev->device_data; |
| 780 | for (s = 0; s < 2; ++s) { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 781 | struct snd_pcm_substream *test_substream; |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 782 | test_substream = pcm->streams[s].substream; |
| 783 | if (test_substream && test_substream != substream && |
| 784 | test_substream->runtime && |
| 785 | ((test_substream->runtime->format && |
| 786 | test_substream->runtime->format != format) || |
| 787 | (test_substream->runtime->rate && |
| 788 | test_substream->runtime->rate != rate))) |
| 789 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | if (0 > (err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)))) { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 793 | snd_printk(KERN_ERR "snd_pcm_lib_malloc_pages(%p, %i) returned %i\n", |
| 794 | substream, params_buffer_bytes(hw_params), err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | return err; |
| 796 | } |
| 797 | return 0; |
| 798 | } |
| 799 | |
| 800 | /* |
| 801 | * free the buffer |
| 802 | */ |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 803 | static int snd_usX2Y_pcm_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 805 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 806 | struct snd_usX2Y_substream *subs = runtime->private_data; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 807 | mutex_lock(&subs->usX2Y->prepare_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | snd_printdd("snd_usX2Y_hw_free(%p)\n", substream); |
| 809 | |
| 810 | if (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 811 | struct snd_usX2Y_substream *cap_subs = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | atomic_set(&subs->state, state_STOPPED); |
| 813 | usX2Y_urbs_release(subs); |
| 814 | if (!cap_subs->pcm_substream || |
| 815 | !cap_subs->pcm_substream->runtime || |
| 816 | !cap_subs->pcm_substream->runtime->status || |
| 817 | cap_subs->pcm_substream->runtime->status->state < SNDRV_PCM_STATE_PREPARED) { |
| 818 | atomic_set(&cap_subs->state, state_STOPPED); |
| 819 | usX2Y_urbs_release(cap_subs); |
| 820 | } |
| 821 | } else { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 822 | struct snd_usX2Y_substream *playback_subs = subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | if (atomic_read(&playback_subs->state) < state_PREPARED) { |
| 824 | atomic_set(&subs->state, state_STOPPED); |
| 825 | usX2Y_urbs_release(subs); |
| 826 | } |
| 827 | } |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 828 | mutex_unlock(&subs->usX2Y->prepare_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | return snd_pcm_lib_free_pages(substream); |
| 830 | } |
| 831 | /* |
| 832 | * prepare callback |
| 833 | * |
| 834 | * set format and initialize urbs |
| 835 | */ |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 836 | static int snd_usX2Y_pcm_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 838 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 839 | struct snd_usX2Y_substream *subs = runtime->private_data; |
| 840 | struct usX2Ydev *usX2Y = subs->usX2Y; |
| 841 | struct snd_usX2Y_substream *capsubs = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | int err = 0; |
| 843 | snd_printdd("snd_usX2Y_pcm_prepare(%p)\n", substream); |
| 844 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 845 | mutex_lock(&usX2Y->prepare_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | usX2Y_subs_prepare(subs); |
| 847 | // Start hardware streams |
| 848 | // SyncStream first.... |
| 849 | if (atomic_read(&capsubs->state) < state_PREPARED) { |
| 850 | if (usX2Y->format != runtime->format) |
| 851 | if ((err = usX2Y_format_set(usX2Y, runtime->format)) < 0) |
| 852 | goto up_prepare_mutex; |
| 853 | if (usX2Y->rate != runtime->rate) |
| 854 | if ((err = usX2Y_rate_set(usX2Y, runtime->rate)) < 0) |
| 855 | goto up_prepare_mutex; |
| 856 | snd_printdd("starting capture pipe for %s\n", subs == capsubs ? "self" : "playpipe"); |
| 857 | if (0 > (err = usX2Y_urbs_start(capsubs))) |
| 858 | goto up_prepare_mutex; |
| 859 | } |
| 860 | |
| 861 | if (subs != capsubs && atomic_read(&subs->state) < state_PREPARED) |
| 862 | err = usX2Y_urbs_start(subs); |
| 863 | |
| 864 | up_prepare_mutex: |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 865 | mutex_unlock(&usX2Y->prepare_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | return err; |
| 867 | } |
| 868 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 869 | static struct snd_pcm_hardware snd_usX2Y_2c = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | { |
| 871 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 872 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 873 | SNDRV_PCM_INFO_MMAP_VALID), |
| 874 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE, |
| 875 | .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000, |
| 876 | .rate_min = 44100, |
| 877 | .rate_max = 48000, |
| 878 | .channels_min = 2, |
| 879 | .channels_max = 2, |
| 880 | .buffer_bytes_max = (2*128*1024), |
| 881 | .period_bytes_min = 64, |
| 882 | .period_bytes_max = (128*1024), |
| 883 | .periods_min = 2, |
| 884 | .periods_max = 1024, |
| 885 | .fifo_size = 0 |
| 886 | }; |
| 887 | |
| 888 | |
| 889 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 890 | static int snd_usX2Y_pcm_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 892 | struct snd_usX2Y_substream *subs = ((struct snd_usX2Y_substream **) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | snd_pcm_substream_chip(substream))[substream->stream]; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 894 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
| 896 | if (subs->usX2Y->chip_status & USX2Y_STAT_CHIP_MMAP_PCM_URBS) |
| 897 | return -EBUSY; |
| 898 | |
| 899 | runtime->hw = snd_usX2Y_2c; |
| 900 | runtime->private_data = subs; |
| 901 | subs->pcm_substream = substream; |
| 902 | snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 1000, 200000); |
| 903 | return 0; |
| 904 | } |
| 905 | |
| 906 | |
| 907 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 908 | static int snd_usX2Y_pcm_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 910 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 911 | struct snd_usX2Y_substream *subs = runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
| 913 | subs->pcm_substream = NULL; |
| 914 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 915 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 919 | static struct snd_pcm_ops snd_usX2Y_pcm_ops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | { |
| 921 | .open = snd_usX2Y_pcm_open, |
| 922 | .close = snd_usX2Y_pcm_close, |
| 923 | .ioctl = snd_pcm_lib_ioctl, |
| 924 | .hw_params = snd_usX2Y_pcm_hw_params, |
| 925 | .hw_free = snd_usX2Y_pcm_hw_free, |
| 926 | .prepare = snd_usX2Y_pcm_prepare, |
| 927 | .trigger = snd_usX2Y_pcm_trigger, |
| 928 | .pointer = snd_usX2Y_pcm_pointer, |
| 929 | }; |
| 930 | |
| 931 | |
| 932 | /* |
| 933 | * free a usb stream instance |
| 934 | */ |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 935 | static void usX2Y_audio_stream_free(struct snd_usX2Y_substream **usX2Y_substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | { |
Richard Knutsson | c111b8d | 2007-05-14 10:38:57 +0200 | [diff] [blame] | 937 | kfree(usX2Y_substream[SNDRV_PCM_STREAM_PLAYBACK]); |
| 938 | usX2Y_substream[SNDRV_PCM_STREAM_PLAYBACK] = NULL; |
| 939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | kfree(usX2Y_substream[SNDRV_PCM_STREAM_CAPTURE]); |
| 941 | usX2Y_substream[SNDRV_PCM_STREAM_CAPTURE] = NULL; |
| 942 | } |
| 943 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 944 | static void snd_usX2Y_pcm_private_free(struct snd_pcm *pcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 946 | struct snd_usX2Y_substream **usX2Y_stream = pcm->private_data; |
Takashi Iwai | c3e6f7d | 2005-11-16 18:43:35 +0100 | [diff] [blame] | 947 | if (usX2Y_stream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | usX2Y_audio_stream_free(usX2Y_stream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | } |
| 950 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 951 | static int usX2Y_audio_stream_new(struct snd_card *card, int playback_endpoint, int capture_endpoint) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 953 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | int err, i; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 955 | struct snd_usX2Y_substream **usX2Y_substream = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | usX2Y(card)->subs + 2 * usX2Y(card)->chip.pcm_devs; |
| 957 | |
| 958 | for (i = playback_endpoint ? SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE; |
| 959 | i <= SNDRV_PCM_STREAM_CAPTURE; ++i) { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 960 | usX2Y_substream[i] = kzalloc(sizeof(struct snd_usX2Y_substream), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | if (NULL == usX2Y_substream[i]) { |
| 962 | snd_printk(KERN_ERR "cannot malloc\n"); |
| 963 | return -ENOMEM; |
| 964 | } |
| 965 | usX2Y_substream[i]->usX2Y = usX2Y(card); |
| 966 | } |
| 967 | |
| 968 | if (playback_endpoint) |
| 969 | usX2Y_substream[SNDRV_PCM_STREAM_PLAYBACK]->endpoint = playback_endpoint; |
| 970 | usX2Y_substream[SNDRV_PCM_STREAM_CAPTURE]->endpoint = capture_endpoint; |
| 971 | |
| 972 | err = snd_pcm_new(card, NAME_ALLCAPS" Audio", usX2Y(card)->chip.pcm_devs, |
| 973 | playback_endpoint ? 1 : 0, 1, |
| 974 | &pcm); |
| 975 | if (err < 0) { |
| 976 | usX2Y_audio_stream_free(usX2Y_substream); |
| 977 | return err; |
| 978 | } |
| 979 | |
| 980 | if (playback_endpoint) |
| 981 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_usX2Y_pcm_ops); |
| 982 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_usX2Y_pcm_ops); |
| 983 | |
| 984 | pcm->private_data = usX2Y_substream; |
| 985 | pcm->private_free = snd_usX2Y_pcm_private_free; |
| 986 | pcm->info_flags = 0; |
| 987 | |
| 988 | sprintf(pcm->name, NAME_ALLCAPS" Audio #%d", usX2Y(card)->chip.pcm_devs); |
| 989 | |
| 990 | if ((playback_endpoint && |
| 991 | 0 > (err = snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream, |
| 992 | SNDRV_DMA_TYPE_CONTINUOUS, |
| 993 | snd_dma_continuous_data(GFP_KERNEL), |
| 994 | 64*1024, 128*1024))) || |
| 995 | 0 > (err = snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream, |
| 996 | SNDRV_DMA_TYPE_CONTINUOUS, |
| 997 | snd_dma_continuous_data(GFP_KERNEL), |
| 998 | 64*1024, 128*1024))) { |
| 999 | snd_usX2Y_pcm_private_free(pcm); |
| 1000 | return err; |
| 1001 | } |
| 1002 | usX2Y(card)->chip.pcm_devs++; |
| 1003 | |
| 1004 | return 0; |
| 1005 | } |
| 1006 | |
| 1007 | /* |
| 1008 | * create a chip instance and set its names. |
| 1009 | */ |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 1010 | int usX2Y_audio_create(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | { |
| 1012 | int err = 0; |
| 1013 | |
| 1014 | INIT_LIST_HEAD(&usX2Y(card)->chip.pcm_list); |
| 1015 | |
| 1016 | if (0 > (err = usX2Y_audio_stream_new(card, 0xA, 0x8))) |
| 1017 | return err; |
| 1018 | if (le16_to_cpu(usX2Y(card)->chip.dev->descriptor.idProduct) == USB_ID_US428) |
| 1019 | if (0 > (err = usX2Y_audio_stream_new(card, 0, 0xA))) |
| 1020 | return err; |
| 1021 | if (le16_to_cpu(usX2Y(card)->chip.dev->descriptor.idProduct) != USB_ID_US122) |
| 1022 | err = usX2Y_rate_set(usX2Y(card), 44100); // Lets us428 recognize output-volume settings, disturbs us122. |
| 1023 | return err; |
| 1024 | } |