Blame view
sound/usb/usx2y/usx2yhwdeppcm.c
23.8 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* USX2Y "rawusb" aka hwdep_pcm implementation Its usb's unableness to atomically handle power of 2 period sized data chuncs at standard samplerates, what led to this part of the usx2y module: It provides the alsa kernel half of the usx2y-alsa-jack driver pair. |
25985edce Fix common misspe... |
23 |
The pair uses a hardware dependent alsa-device for mmaped pcm transport. |
1da177e4c Linux-2.6.12-rc2 |
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
Advantage achieved: The usb_hc moves pcm data from/into memory via DMA. That memory is mmaped by jack's usx2y driver. Jack's usx2y driver is the first/last to read/write pcm data. Read/write is a combination of power of 2 period shaping and float/int conversation. Compared to mainline alsa/jack we leave out power of 2 period shaping inside snd-usb-usx2y which needs memcpy() and additional buffers. As a side effect possible unwanted pcm-data coruption resulting of standard alsa's snd-usb-usx2y period shaping scheme falls away. Result is sane jack operation at buffering schemes down to 128frames, 2 periods. plain usx2y alsa mode is able to achieve 64frames, 4periods, but only at the cost of easier triggered i.e. aeolus xruns (128 or 256frames, 2periods works but is useless cause of crackling). |
fa2eb005e sound: fixed typos |
39 |
|
1da177e4c Linux-2.6.12-rc2 |
40 |
This is a first "proof of concept" implementation. |
25985edce Fix common misspe... |
41 |
Later, functionalities should migrate to more appropriate places: |
1da177e4c Linux-2.6.12-rc2 |
42 43 44 45 46 47 48 49 50 51 |
Userland: - The jackd could mmap its float-pcm buffers directly from alsa-lib. - alsa-lib could provide power of 2 period sized shaping combined with int/float conversation. Currently the usx2y jack driver provides above 2 services. Kernel: - rawusb dma pcm buffer transport should go to snd-usb-lib, so also snd-usb-audio devices can use it. Currently rawusb dma pcm buffer transport (this file) is only available to snd-usb-usx2y. */ |
b27c187f9 [ALSA] Fix-up sle... |
52 |
#include <linux/delay.h> |
5a0e3ad6a include cleanup: ... |
53 |
#include <linux/gfp.h> |
1da177e4c Linux-2.6.12-rc2 |
54 |
#include "usbusx2yaudio.c" |
1d2019fb6 ALSA: sound/usb/u... |
55 |
#if defined(USX2Y_NRPACKS_VARIABLE) || USX2Y_NRPACKS == 1 |
1da177e4c Linux-2.6.12-rc2 |
56 57 |
#include <sound/hwdep.h> |
bbe85bbd0 [ALSA] Remove xxx... |
58 |
static int usX2Y_usbpcm_urb_capt_retire(struct snd_usX2Y_substream *subs) |
1da177e4c Linux-2.6.12-rc2 |
59 60 |
{ struct urb *urb = subs->completed_urb; |
bbe85bbd0 [ALSA] Remove xxx... |
61 |
struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; |
1da177e4c Linux-2.6.12-rc2 |
62 |
int i, lens = 0, hwptr_done = subs->hwptr_done; |
bbe85bbd0 [ALSA] Remove xxx... |
63 |
struct usX2Ydev *usX2Y = subs->usX2Y; |
1da177e4c Linux-2.6.12-rc2 |
64 65 66 67 68 69 70 71 72 73 |
if (0 > usX2Y->hwdep_pcm_shm->capture_iso_start) { //FIXME int head = usX2Y->hwdep_pcm_shm->captured_iso_head + 1; if (head >= ARRAY_SIZE(usX2Y->hwdep_pcm_shm->captured_iso)) head = 0; usX2Y->hwdep_pcm_shm->capture_iso_start = head; snd_printdd("cap start %i ", head); } for (i = 0; i < nr_of_packs(); i++) { if (urb->iso_frame_desc[i].status) { /* active? hmm, skip this */ |
6e8d5d2f1 ALSA: usx2y: Fix ... |
74 75 |
snd_printk(KERN_ERR "active frame status %i. Most probably some hardware problem. ", urb->iso_frame_desc[i].status); |
1da177e4c Linux-2.6.12-rc2 |
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
return urb->iso_frame_desc[i].status; } lens += urb->iso_frame_desc[i].actual_length / usX2Y->stride; } if ((hwptr_done += lens) >= runtime->buffer_size) hwptr_done -= runtime->buffer_size; subs->hwptr_done = hwptr_done; subs->transfer_done += lens; /* update the pointer, call callback if necessary */ if (subs->transfer_done >= runtime->period_size) { subs->transfer_done -= runtime->period_size; snd_pcm_period_elapsed(subs->pcm_substream); } return 0; } |
bbe85bbd0 [ALSA] Remove xxx... |
91 92 |
static inline int usX2Y_iso_frames_per_buffer(struct snd_pcm_runtime *runtime, struct usX2Ydev * usX2Y) |
1da177e4c Linux-2.6.12-rc2 |
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
{ return (runtime->buffer_size * 1000) / usX2Y->rate + 1; //FIXME: so far only correct period_size == 2^x ? } /* * prepare urb for playback data pipe * * we copy the data directly from the pcm buffer. * the current position to be copied is held in hwptr field. * since a urb can handle only a single linear buffer, if the total * transferred area overflows the buffer boundary, we cannot send * it directly from the buffer. thus the data is once copied to * a temporary buffer and urb points to that. */ |
bbe85bbd0 [ALSA] Remove xxx... |
107 108 |
static int usX2Y_hwdep_urb_play_prepare(struct snd_usX2Y_substream *subs, struct urb *urb) |
1da177e4c Linux-2.6.12-rc2 |
109 110 |
{ int count, counts, pack; |
bbe85bbd0 [ALSA] Remove xxx... |
111 |
struct usX2Ydev *usX2Y = subs->usX2Y; |
1da177e4c Linux-2.6.12-rc2 |
112 |
struct snd_usX2Y_hwdep_pcm_shm *shm = usX2Y->hwdep_pcm_shm; |
bbe85bbd0 [ALSA] Remove xxx... |
113 |
struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; |
1da177e4c Linux-2.6.12-rc2 |
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
if (0 > shm->playback_iso_start) { shm->playback_iso_start = shm->captured_iso_head - usX2Y_iso_frames_per_buffer(runtime, usX2Y); if (0 > shm->playback_iso_start) shm->playback_iso_start += ARRAY_SIZE(shm->captured_iso); shm->playback_iso_head = shm->playback_iso_start; } count = 0; for (pack = 0; pack < nr_of_packs(); pack++) { /* calculate the size of a packet */ counts = shm->captured_iso[shm->playback_iso_head].length / usX2Y->stride; if (counts < 43 || counts > 50) { |
d3d579f84 [ALSA] Add missin... |
128 129 |
snd_printk(KERN_ERR "should not be here with counts=%i ", counts); |
1da177e4c Linux-2.6.12-rc2 |
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
return -EPIPE; } /* set up descriptor */ urb->iso_frame_desc[pack].offset = shm->captured_iso[shm->playback_iso_head].offset; urb->iso_frame_desc[pack].length = shm->captured_iso[shm->playback_iso_head].length; if (atomic_read(&subs->state) != state_RUNNING) memset((char *)urb->transfer_buffer + urb->iso_frame_desc[pack].offset, 0, urb->iso_frame_desc[pack].length); if (++shm->playback_iso_head >= ARRAY_SIZE(shm->captured_iso)) shm->playback_iso_head = 0; count += counts; } urb->transfer_buffer_length = count * usX2Y->stride; return 0; } |
bbe85bbd0 [ALSA] Remove xxx... |
145 146 |
static inline void usX2Y_usbpcm_urb_capt_iso_advance(struct snd_usX2Y_substream *subs, struct urb *urb) |
1da177e4c Linux-2.6.12-rc2 |
147 148 149 150 151 |
{ int pack; for (pack = 0; pack < nr_of_packs(); ++pack) { struct usb_iso_packet_descriptor *desc = urb->iso_frame_desc + pack; if (NULL != subs) { |
bbe85bbd0 [ALSA] Remove xxx... |
152 |
struct snd_usX2Y_hwdep_pcm_shm *shm = subs->usX2Y->hwdep_pcm_shm; |
1da177e4c Linux-2.6.12-rc2 |
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
int head = shm->captured_iso_head + 1; if (head >= ARRAY_SIZE(shm->captured_iso)) head = 0; shm->captured_iso[head].frame = urb->start_frame + pack; shm->captured_iso[head].offset = desc->offset; shm->captured_iso[head].length = desc->actual_length; shm->captured_iso_head = head; shm->captured_iso_frames++; } if ((desc->offset += desc->length * NRURBS*nr_of_packs()) + desc->length >= SSS) desc->offset -= (SSS - desc->length); } } |
bbe85bbd0 [ALSA] Remove xxx... |
167 168 169 170 |
static inline int usX2Y_usbpcm_usbframe_complete(struct snd_usX2Y_substream *capsubs, struct snd_usX2Y_substream *capsubs2, struct snd_usX2Y_substream *playbacksubs, int frame) |
1da177e4c Linux-2.6.12-rc2 |
171 172 173 174 175 176 177 178 |
{ int err, state; struct urb *urb = playbacksubs->completed_urb; state = atomic_read(&playbacksubs->state); if (NULL != urb) { if (state == state_RUNNING) usX2Y_urb_play_retire(playbacksubs, urb); |
cb432379e [ALSA] usx2y - Co... |
179 180 |
else if (state >= state_PRERUNNING) atomic_inc(&playbacksubs->state); |
1da177e4c Linux-2.6.12-rc2 |
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
} else { switch (state) { case state_STARTING1: urb = playbacksubs->urb[0]; atomic_inc(&playbacksubs->state); break; case state_STARTING2: urb = playbacksubs->urb[1]; atomic_inc(&playbacksubs->state); break; } } if (urb) { if ((err = usX2Y_hwdep_urb_play_prepare(playbacksubs, urb)) || (err = usX2Y_urb_submit(playbacksubs, urb, frame))) { return err; } } playbacksubs->completed_urb = NULL; state = atomic_read(&capsubs->state); if (state >= state_PREPARED) { if (state == state_RUNNING) { if ((err = usX2Y_usbpcm_urb_capt_retire(capsubs))) return err; |
cb432379e [ALSA] usx2y - Co... |
207 208 |
} else if (state >= state_PRERUNNING) atomic_inc(&capsubs->state); |
1da177e4c Linux-2.6.12-rc2 |
209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
usX2Y_usbpcm_urb_capt_iso_advance(capsubs, capsubs->completed_urb); if (NULL != capsubs2) usX2Y_usbpcm_urb_capt_iso_advance(NULL, capsubs2->completed_urb); if ((err = usX2Y_urb_submit(capsubs, capsubs->completed_urb, frame))) return err; if (NULL != capsubs2) if ((err = usX2Y_urb_submit(capsubs2, capsubs2->completed_urb, frame))) return err; } capsubs->completed_urb = NULL; if (NULL != capsubs2) capsubs2->completed_urb = NULL; return 0; } |
7d12e780e IRQ: Maintain reg... |
223 |
static void i_usX2Y_usbpcm_urb_complete(struct urb *urb) |
1da177e4c Linux-2.6.12-rc2 |
224 |
{ |
bbe85bbd0 [ALSA] Remove xxx... |
225 226 227 |
struct snd_usX2Y_substream *subs = urb->context; struct usX2Ydev *usX2Y = subs->usX2Y; struct snd_usX2Y_substream *capsubs, *capsubs2, *playbacksubs; |
1da177e4c Linux-2.6.12-rc2 |
228 229 |
if (unlikely(atomic_read(&subs->state) < state_PREPARED)) { |
bbe85bbd0 [ALSA] Remove xxx... |
230 231 |
snd_printdd("hcd_frame=%i ep=%i%s status=%i start_frame=%i ", |
a014bbadb sound: usxxx: cle... |
232 |
usb_get_current_frame_number(usX2Y->dev), |
bbe85bbd0 [ALSA] Remove xxx... |
233 234 |
subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", urb->status, urb->start_frame); |
1da177e4c Linux-2.6.12-rc2 |
235 236 237 238 239 240 |
return; } if (unlikely(urb->status)) { usX2Y_error_urb_status(usX2Y, subs, urb); return; } |
1da177e4c Linux-2.6.12-rc2 |
241 |
|
a9d14bc0b ALSA: snd-usb-usx... |
242 |
subs->completed_urb = urb; |
1da177e4c Linux-2.6.12-rc2 |
243 244 245 246 247 248 |
capsubs = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE]; capsubs2 = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2]; playbacksubs = usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]; if (capsubs->completed_urb && atomic_read(&capsubs->state) >= state_PREPARED && (NULL == capsubs2 || capsubs2->completed_urb) && (playbacksubs->completed_urb || atomic_read(&playbacksubs->state) < state_PREPARED)) { |
635bbb355 [ALSA] Repair snd... |
249 250 251 |
if (!usX2Y_usbpcm_usbframe_complete(capsubs, capsubs2, playbacksubs, urb->start_frame)) usX2Y->wait_iso_frame += nr_of_packs(); else { |
1da177e4c Linux-2.6.12-rc2 |
252 253 254 255 256 257 |
snd_printdd(" "); usX2Y_clients_stop(usX2Y); } } } |
bbe85bbd0 [ALSA] Remove xxx... |
258 |
static void usX2Y_hwdep_urb_release(struct urb **urb) |
1da177e4c Linux-2.6.12-rc2 |
259 260 261 262 263 264 265 266 267 |
{ usb_kill_urb(*urb); usb_free_urb(*urb); *urb = NULL; } /* * release a substream */ |
bbe85bbd0 [ALSA] Remove xxx... |
268 |
static void usX2Y_usbpcm_urbs_release(struct snd_usX2Y_substream *subs) |
1da177e4c Linux-2.6.12-rc2 |
269 270 271 272 273 274 275 |
{ int i; snd_printdd("snd_usX2Y_urbs_release() %i ", subs->endpoint); for (i = 0; i < NRURBS; i++) usX2Y_hwdep_urb_release(subs->urb + i); } |
bbe85bbd0 [ALSA] Remove xxx... |
276 |
static void usX2Y_usbpcm_subs_startup_finish(struct usX2Ydev * usX2Y) |
1da177e4c Linux-2.6.12-rc2 |
277 278 279 280 |
{ usX2Y_urbs_set_complete(usX2Y, i_usX2Y_usbpcm_urb_complete); usX2Y->prepare_subs = NULL; } |
7d12e780e IRQ: Maintain reg... |
281 |
static void i_usX2Y_usbpcm_subs_startup(struct urb *urb) |
1da177e4c Linux-2.6.12-rc2 |
282 |
{ |
bbe85bbd0 [ALSA] Remove xxx... |
283 284 285 |
struct snd_usX2Y_substream *subs = urb->context; struct usX2Ydev *usX2Y = subs->usX2Y; struct snd_usX2Y_substream *prepare_subs = usX2Y->prepare_subs; |
1da177e4c Linux-2.6.12-rc2 |
286 287 288 289 |
if (NULL != prepare_subs && urb->start_frame == prepare_subs->urb[0]->start_frame) { atomic_inc(&prepare_subs->state); if (prepare_subs == usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE]) { |
bbe85bbd0 [ALSA] Remove xxx... |
290 |
struct snd_usX2Y_substream *cap_subs2 = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2]; |
1da177e4c Linux-2.6.12-rc2 |
291 292 293 294 295 296 |
if (cap_subs2 != NULL) atomic_inc(&cap_subs2->state); } usX2Y_usbpcm_subs_startup_finish(usX2Y); wake_up(&usX2Y->prepare_wait_queue); } |
7d12e780e IRQ: Maintain reg... |
297 |
i_usX2Y_usbpcm_urb_complete(urb); |
1da177e4c Linux-2.6.12-rc2 |
298 299 300 301 302 |
} /* * initialize a substream's urbs */ |
bbe85bbd0 [ALSA] Remove xxx... |
303 |
static int usX2Y_usbpcm_urbs_allocate(struct snd_usX2Y_substream *subs) |
1da177e4c Linux-2.6.12-rc2 |
304 305 306 307 |
{ int i; unsigned int pipe; int is_playback = subs == subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]; |
a014bbadb sound: usxxx: cle... |
308 |
struct usb_device *dev = subs->usX2Y->dev; |
1da177e4c Linux-2.6.12-rc2 |
309 310 311 312 313 314 315 316 317 |
pipe = is_playback ? usb_sndisocpipe(dev, subs->endpoint) : usb_rcvisocpipe(dev, subs->endpoint); subs->maxpacksize = usb_maxpacket(dev, pipe, is_playback); if (!subs->maxpacksize) return -EINVAL; /* allocate and initialize data urbs */ for (i = 0; i < NRURBS; i++) { |
cb432379e [ALSA] usx2y - Co... |
318 |
struct urb **purb = subs->urb + i; |
1da177e4c Linux-2.6.12-rc2 |
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
if (*purb) { usb_kill_urb(*purb); continue; } *purb = usb_alloc_urb(nr_of_packs(), GFP_KERNEL); if (NULL == *purb) { usX2Y_usbpcm_urbs_release(subs); return -ENOMEM; } (*purb)->transfer_buffer = is_playback ? subs->usX2Y->hwdep_pcm_shm->playback : ( subs->endpoint == 0x8 ? subs->usX2Y->hwdep_pcm_shm->capture0x8 : subs->usX2Y->hwdep_pcm_shm->capture0xA); (*purb)->dev = dev; (*purb)->pipe = pipe; (*purb)->number_of_packets = nr_of_packs(); (*purb)->context = subs; (*purb)->interval = 1; (*purb)->complete = i_usX2Y_usbpcm_subs_startup; } return 0; } /* * free the buffer */ |
bbe85bbd0 [ALSA] Remove xxx... |
347 |
static int snd_usX2Y_usbpcm_hw_free(struct snd_pcm_substream *substream) |
1da177e4c Linux-2.6.12-rc2 |
348 |
{ |
bbe85bbd0 [ALSA] Remove xxx... |
349 350 |
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_usX2Y_substream *subs = runtime->private_data, |
1da177e4c Linux-2.6.12-rc2 |
351 |
*cap_subs2 = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2]; |
e2439a540 ALSA: usx2y: Don'... |
352 |
mutex_lock(&subs->usX2Y->pcm_mutex); |
1da177e4c Linux-2.6.12-rc2 |
353 354 355 356 |
snd_printdd("snd_usX2Y_usbpcm_hw_free(%p) ", substream); if (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) { |
bbe85bbd0 [ALSA] Remove xxx... |
357 |
struct snd_usX2Y_substream *cap_subs = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE]; |
1da177e4c Linux-2.6.12-rc2 |
358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
atomic_set(&subs->state, state_STOPPED); usX2Y_usbpcm_urbs_release(subs); if (!cap_subs->pcm_substream || !cap_subs->pcm_substream->runtime || !cap_subs->pcm_substream->runtime->status || cap_subs->pcm_substream->runtime->status->state < SNDRV_PCM_STATE_PREPARED) { atomic_set(&cap_subs->state, state_STOPPED); if (NULL != cap_subs2) atomic_set(&cap_subs2->state, state_STOPPED); usX2Y_usbpcm_urbs_release(cap_subs); if (NULL != cap_subs2) usX2Y_usbpcm_urbs_release(cap_subs2); } } else { |
bbe85bbd0 [ALSA] Remove xxx... |
372 |
struct snd_usX2Y_substream *playback_subs = subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]; |
1da177e4c Linux-2.6.12-rc2 |
373 374 375 376 377 378 379 380 381 |
if (atomic_read(&playback_subs->state) < state_PREPARED) { atomic_set(&subs->state, state_STOPPED); if (NULL != cap_subs2) atomic_set(&cap_subs2->state, state_STOPPED); usX2Y_usbpcm_urbs_release(subs); if (NULL != cap_subs2) usX2Y_usbpcm_urbs_release(cap_subs2); } } |
e2439a540 ALSA: usx2y: Don'... |
382 |
mutex_unlock(&subs->usX2Y->pcm_mutex); |
1da177e4c Linux-2.6.12-rc2 |
383 384 |
return snd_pcm_lib_free_pages(substream); } |
bbe85bbd0 [ALSA] Remove xxx... |
385 |
static void usX2Y_usbpcm_subs_startup(struct snd_usX2Y_substream *subs) |
1da177e4c Linux-2.6.12-rc2 |
386 |
{ |
bbe85bbd0 [ALSA] Remove xxx... |
387 |
struct usX2Ydev * usX2Y = subs->usX2Y; |
1da177e4c Linux-2.6.12-rc2 |
388 389 |
usX2Y->prepare_subs = subs; subs->urb[0]->start_frame = -1; |
7f927fcc2 [PATCH] Typo fixes |
390 |
smp_wmb(); // Make sure above modifications are seen by i_usX2Y_subs_startup() |
1da177e4c Linux-2.6.12-rc2 |
391 392 |
usX2Y_urbs_set_complete(usX2Y, i_usX2Y_usbpcm_subs_startup); } |
bbe85bbd0 [ALSA] Remove xxx... |
393 |
static int usX2Y_usbpcm_urbs_start(struct snd_usX2Y_substream *subs) |
1da177e4c Linux-2.6.12-rc2 |
394 395 396 |
{ int p, u, err, stream = subs->pcm_substream->stream; |
bbe85bbd0 [ALSA] Remove xxx... |
397 |
struct usX2Ydev *usX2Y = subs->usX2Y; |
1da177e4c Linux-2.6.12-rc2 |
398 399 400 401 402 403 404 |
if (SNDRV_PCM_STREAM_CAPTURE == stream) { usX2Y->hwdep_pcm_shm->captured_iso_head = -1; usX2Y->hwdep_pcm_shm->captured_iso_frames = 0; } for (p = 0; 3 >= (stream + p); p += 2) { |
bbe85bbd0 [ALSA] Remove xxx... |
405 |
struct snd_usX2Y_substream *subs = usX2Y->subs[stream + p]; |
1da177e4c Linux-2.6.12-rc2 |
406 407 408 409 410 411 412 413 |
if (subs != NULL) { if ((err = usX2Y_usbpcm_urbs_allocate(subs)) < 0) return err; subs->completed_urb = NULL; } } for (p = 0; p < 4; p++) { |
bbe85bbd0 [ALSA] Remove xxx... |
414 |
struct snd_usX2Y_substream *subs = usX2Y->subs[p]; |
1da177e4c Linux-2.6.12-rc2 |
415 416 417 |
if (subs != NULL && atomic_read(&subs->state) >= state_PREPARED) goto start; } |
1da177e4c Linux-2.6.12-rc2 |
418 419 420 421 422 |
start: usX2Y_usbpcm_subs_startup(subs); for (u = 0; u < NRURBS; u++) { for (p = 0; 3 >= (stream + p); p += 2) { |
bbe85bbd0 [ALSA] Remove xxx... |
423 |
struct snd_usX2Y_substream *subs = usX2Y->subs[stream + p]; |
1da177e4c Linux-2.6.12-rc2 |
424 425 426 427 428 429 |
if (subs != NULL) { struct urb *urb = subs->urb[u]; if (usb_pipein(urb->pipe)) { unsigned long pack; if (0 == u) atomic_set(&subs->state, state_STARTING3); |
a014bbadb sound: usxxx: cle... |
430 |
urb->dev = usX2Y->dev; |
1da177e4c Linux-2.6.12-rc2 |
431 432 433 434 435 436 437 438 439 440 441 442 443 |
for (pack = 0; pack < nr_of_packs(); pack++) { urb->iso_frame_desc[pack].offset = subs->maxpacksize * (pack + u * nr_of_packs()); urb->iso_frame_desc[pack].length = subs->maxpacksize; } urb->transfer_buffer_length = subs->maxpacksize * nr_of_packs(); if ((err = usb_submit_urb(urb, GFP_KERNEL)) < 0) { snd_printk (KERN_ERR "cannot usb_submit_urb() for urb %d, err = %d ", u, err); err = -EPIPE; goto cleanup; } else { snd_printdd("%i ", urb->start_frame); |
635bbb355 [ALSA] Repair snd... |
444 |
if (u == 0) |
1da177e4c Linux-2.6.12-rc2 |
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
usX2Y->wait_iso_frame = urb->start_frame; } urb->transfer_flags = 0; } else { atomic_set(&subs->state, state_STARTING1); break; } } } } err = 0; wait_event(usX2Y->prepare_wait_queue, NULL == usX2Y->prepare_subs); if (atomic_read(&subs->state) != state_PREPARED) err = -EPIPE; cleanup: if (err) { usX2Y_subs_startup_finish(usX2Y); // Call it now usX2Y_clients_stop(usX2Y); // something is completely wroong > stop evrything } return err; } /* * prepare callback * * set format and initialize urbs */ |
bbe85bbd0 [ALSA] Remove xxx... |
473 |
static int snd_usX2Y_usbpcm_prepare(struct snd_pcm_substream *substream) |
1da177e4c Linux-2.6.12-rc2 |
474 |
{ |
bbe85bbd0 [ALSA] Remove xxx... |
475 476 477 478 |
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_usX2Y_substream *subs = runtime->private_data; struct usX2Ydev *usX2Y = subs->usX2Y; struct snd_usX2Y_substream *capsubs = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE]; |
1da177e4c Linux-2.6.12-rc2 |
479 480 481 482 483 |
int err = 0; snd_printdd("snd_usX2Y_pcm_prepare(%p) ", substream); if (NULL == usX2Y->hwdep_pcm_shm) { |
bbe85bbd0 [ALSA] Remove xxx... |
484 |
if (NULL == (usX2Y->hwdep_pcm_shm = snd_malloc_pages(sizeof(struct snd_usX2Y_hwdep_pcm_shm), GFP_KERNEL))) |
1da177e4c Linux-2.6.12-rc2 |
485 |
return -ENOMEM; |
bbe85bbd0 [ALSA] Remove xxx... |
486 |
memset(usX2Y->hwdep_pcm_shm, 0, sizeof(struct snd_usX2Y_hwdep_pcm_shm)); |
1da177e4c Linux-2.6.12-rc2 |
487 |
} |
e2439a540 ALSA: usx2y: Don'... |
488 |
mutex_lock(&usX2Y->pcm_mutex); |
1da177e4c Linux-2.6.12-rc2 |
489 490 491 492 493 494 495 496 497 498 |
usX2Y_subs_prepare(subs); // Start hardware streams // SyncStream first.... if (atomic_read(&capsubs->state) < state_PREPARED) { if (usX2Y->format != runtime->format) if ((err = usX2Y_format_set(usX2Y, runtime->format)) < 0) goto up_prepare_mutex; if (usX2Y->rate != runtime->rate) if ((err = usX2Y_rate_set(usX2Y, runtime->rate)) < 0) goto up_prepare_mutex; |
bbe85bbd0 [ALSA] Remove xxx... |
499 500 501 |
snd_printdd("starting capture pipe for %s ", subs == capsubs ? "self" : "playpipe"); |
1da177e4c Linux-2.6.12-rc2 |
502 503 504 505 506 507 508 |
if (0 > (err = usX2Y_usbpcm_urbs_start(capsubs))) goto up_prepare_mutex; } if (subs != capsubs) { usX2Y->hwdep_pcm_shm->playback_iso_start = -1; if (atomic_read(&subs->state) < state_PREPARED) { |
bbe85bbd0 [ALSA] Remove xxx... |
509 510 511 512 513 514 515 |
while (usX2Y_iso_frames_per_buffer(runtime, usX2Y) > usX2Y->hwdep_pcm_shm->captured_iso_frames) { snd_printdd("Wait: iso_frames_per_buffer=%i," "captured_iso_frames=%i ", usX2Y_iso_frames_per_buffer(runtime, usX2Y), usX2Y->hwdep_pcm_shm->captured_iso_frames); |
b27c187f9 [ALSA] Fix-up sle... |
516 |
if (msleep_interruptible(10)) { |
1da177e4c Linux-2.6.12-rc2 |
517 518 519 520 521 522 523 |
err = -ERESTARTSYS; goto up_prepare_mutex; } } if (0 > (err = usX2Y_usbpcm_urbs_start(subs))) goto up_prepare_mutex; } |
bbe85bbd0 [ALSA] Remove xxx... |
524 525 526 527 |
snd_printdd("Ready: iso_frames_per_buffer=%i,captured_iso_frames=%i ", usX2Y_iso_frames_per_buffer(runtime, usX2Y), usX2Y->hwdep_pcm_shm->captured_iso_frames); |
1da177e4c Linux-2.6.12-rc2 |
528 529 530 531 |
} else usX2Y->hwdep_pcm_shm->capture_iso_start = -1; up_prepare_mutex: |
e2439a540 ALSA: usx2y: Don'... |
532 |
mutex_unlock(&usX2Y->pcm_mutex); |
1da177e4c Linux-2.6.12-rc2 |
533 534 |
return err; } |
bbe85bbd0 [ALSA] Remove xxx... |
535 |
static struct snd_pcm_hardware snd_usX2Y_4c = |
1da177e4c Linux-2.6.12-rc2 |
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 |
{ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID), .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE, .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000, .rate_min = 44100, .rate_max = 48000, .channels_min = 2, .channels_max = 4, .buffer_bytes_max = (2*128*1024), .period_bytes_min = 64, .period_bytes_max = (128*1024), .periods_min = 2, .periods_max = 1024, .fifo_size = 0 }; |
bbe85bbd0 [ALSA] Remove xxx... |
553 |
static int snd_usX2Y_usbpcm_open(struct snd_pcm_substream *substream) |
1da177e4c Linux-2.6.12-rc2 |
554 |
{ |
bbe85bbd0 [ALSA] Remove xxx... |
555 |
struct snd_usX2Y_substream *subs = ((struct snd_usX2Y_substream **) |
1da177e4c Linux-2.6.12-rc2 |
556 |
snd_pcm_substream_chip(substream))[substream->stream]; |
bbe85bbd0 [ALSA] Remove xxx... |
557 |
struct snd_pcm_runtime *runtime = substream->runtime; |
1da177e4c Linux-2.6.12-rc2 |
558 559 560 561 562 563 564 565 566 567 568 |
if (!(subs->usX2Y->chip_status & USX2Y_STAT_CHIP_MMAP_PCM_URBS)) return -EBUSY; runtime->hw = SNDRV_PCM_STREAM_PLAYBACK == substream->stream ? snd_usX2Y_2c : (subs->usX2Y->subs[3] ? snd_usX2Y_4c : snd_usX2Y_2c); runtime->private_data = subs; subs->pcm_substream = substream; snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 1000, 200000); return 0; } |
bbe85bbd0 [ALSA] Remove xxx... |
569 |
static int snd_usX2Y_usbpcm_close(struct snd_pcm_substream *substream) |
1da177e4c Linux-2.6.12-rc2 |
570 |
{ |
bbe85bbd0 [ALSA] Remove xxx... |
571 572 |
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_usX2Y_substream *subs = runtime->private_data; |
cb432379e [ALSA] usx2y - Co... |
573 |
|
1da177e4c Linux-2.6.12-rc2 |
574 |
subs->pcm_substream = NULL; |
cb432379e [ALSA] usx2y - Co... |
575 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
576 |
} |
bbe85bbd0 [ALSA] Remove xxx... |
577 |
static struct snd_pcm_ops snd_usX2Y_usbpcm_ops = |
1da177e4c Linux-2.6.12-rc2 |
578 579 580 581 582 583 584 585 586 587 |
{ .open = snd_usX2Y_usbpcm_open, .close = snd_usX2Y_usbpcm_close, .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_usX2Y_pcm_hw_params, .hw_free = snd_usX2Y_usbpcm_hw_free, .prepare = snd_usX2Y_usbpcm_prepare, .trigger = snd_usX2Y_pcm_trigger, .pointer = snd_usX2Y_pcm_pointer, }; |
e2439a540 ALSA: usx2y: Don'... |
588 |
static int usX2Y_pcms_busy_check(struct snd_card *card) |
1da177e4c Linux-2.6.12-rc2 |
589 |
{ |
e2439a540 ALSA: usx2y: Don'... |
590 591 |
struct usX2Ydev *dev = usX2Y(card); int i; |
1da177e4c Linux-2.6.12-rc2 |
592 |
|
e2439a540 ALSA: usx2y: Don'... |
593 594 595 596 597 |
for (i = 0; i < dev->pcm_devs * 2; i++) { struct snd_usX2Y_substream *subs = dev->subs[i]; if (subs && subs->pcm_substream && SUBSTREAM_BUSY(subs->pcm_substream)) return -EBUSY; |
1da177e4c Linux-2.6.12-rc2 |
598 |
} |
e2439a540 ALSA: usx2y: Don'... |
599 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
600 |
} |
bbe85bbd0 [ALSA] Remove xxx... |
601 |
static int snd_usX2Y_hwdep_pcm_open(struct snd_hwdep *hw, struct file *file) |
1da177e4c Linux-2.6.12-rc2 |
602 |
{ |
bbe85bbd0 [ALSA] Remove xxx... |
603 |
struct snd_card *card = hw->card; |
e2439a540 ALSA: usx2y: Don'... |
604 605 606 607 608 |
int err; mutex_lock(&usX2Y(card)->pcm_mutex); err = usX2Y_pcms_busy_check(card); if (!err) |
1da177e4c Linux-2.6.12-rc2 |
609 |
usX2Y(card)->chip_status |= USX2Y_STAT_CHIP_MMAP_PCM_URBS; |
e2439a540 ALSA: usx2y: Don'... |
610 |
mutex_unlock(&usX2Y(card)->pcm_mutex); |
1da177e4c Linux-2.6.12-rc2 |
611 612 |
return err; } |
bbe85bbd0 [ALSA] Remove xxx... |
613 |
static int snd_usX2Y_hwdep_pcm_release(struct snd_hwdep *hw, struct file *file) |
1da177e4c Linux-2.6.12-rc2 |
614 |
{ |
bbe85bbd0 [ALSA] Remove xxx... |
615 |
struct snd_card *card = hw->card; |
e2439a540 ALSA: usx2y: Don'... |
616 617 618 619 620 |
int err; mutex_lock(&usX2Y(card)->pcm_mutex); err = usX2Y_pcms_busy_check(card); if (!err) |
1da177e4c Linux-2.6.12-rc2 |
621 |
usX2Y(hw->card)->chip_status &= ~USX2Y_STAT_CHIP_MMAP_PCM_URBS; |
e2439a540 ALSA: usx2y: Don'... |
622 |
mutex_unlock(&usX2Y(card)->pcm_mutex); |
1da177e4c Linux-2.6.12-rc2 |
623 624 625 626 627 628 629 630 631 632 633 634 |
return err; } static void snd_usX2Y_hwdep_pcm_vm_open(struct vm_area_struct *area) { } static void snd_usX2Y_hwdep_pcm_vm_close(struct vm_area_struct *area) { } |
eb415b8f6 [ALSA] alsa: usx2... |
635 636 |
static int snd_usX2Y_hwdep_pcm_vm_fault(struct vm_area_struct *area, struct vm_fault *vmf) |
1da177e4c Linux-2.6.12-rc2 |
637 638 |
{ unsigned long offset; |
1da177e4c Linux-2.6.12-rc2 |
639 |
void *vaddr; |
eb415b8f6 [ALSA] alsa: usx2... |
640 |
offset = vmf->pgoff << PAGE_SHIFT; |
bbe85bbd0 [ALSA] Remove xxx... |
641 |
vaddr = (char*)((struct usX2Ydev *)area->vm_private_data)->hwdep_pcm_shm + offset; |
eb415b8f6 [ALSA] alsa: usx2... |
642 643 644 |
vmf->page = virt_to_page(vaddr); get_page(vmf->page); return 0; |
1da177e4c Linux-2.6.12-rc2 |
645 |
} |
f0f37e2f7 const: mark struc... |
646 |
static const struct vm_operations_struct snd_usX2Y_hwdep_pcm_vm_ops = { |
1da177e4c Linux-2.6.12-rc2 |
647 648 |
.open = snd_usX2Y_hwdep_pcm_vm_open, .close = snd_usX2Y_hwdep_pcm_vm_close, |
eb415b8f6 [ALSA] alsa: usx2... |
649 |
.fault = snd_usX2Y_hwdep_pcm_vm_fault, |
1da177e4c Linux-2.6.12-rc2 |
650 |
}; |
bbe85bbd0 [ALSA] Remove xxx... |
651 |
static int snd_usX2Y_hwdep_pcm_mmap(struct snd_hwdep * hw, struct file *filp, struct vm_area_struct *area) |
1da177e4c Linux-2.6.12-rc2 |
652 653 |
{ unsigned long size = (unsigned long)(area->vm_end - area->vm_start); |
bbe85bbd0 [ALSA] Remove xxx... |
654 |
struct usX2Ydev *usX2Y = hw->private_data; |
1da177e4c Linux-2.6.12-rc2 |
655 |
|
cb432379e [ALSA] usx2y - Co... |
656 |
if (!(usX2Y->chip_status & USX2Y_STAT_CHIP_INIT)) |
1da177e4c Linux-2.6.12-rc2 |
657 658 659 |
return -EBUSY; /* if userspace tries to mmap beyond end of our buffer, fail */ |
bbe85bbd0 [ALSA] Remove xxx... |
660 661 662 |
if (size > PAGE_ALIGN(sizeof(struct snd_usX2Y_hwdep_pcm_shm))) { snd_printd("%lu > %lu ", size, (unsigned long)sizeof(struct snd_usX2Y_hwdep_pcm_shm)); |
1da177e4c Linux-2.6.12-rc2 |
663 664 665 666 667 668 669 |
return -EINVAL; } if (!usX2Y->hwdep_pcm_shm) { return -ENODEV; } area->vm_ops = &snd_usX2Y_hwdep_pcm_vm_ops; |
314e51b98 mm: kill vma flag... |
670 |
area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; |
1da177e4c Linux-2.6.12-rc2 |
671 672 673 |
area->vm_private_data = hw->private_data; return 0; } |
bbe85bbd0 [ALSA] Remove xxx... |
674 |
static void snd_usX2Y_hwdep_pcm_private_free(struct snd_hwdep *hwdep) |
1da177e4c Linux-2.6.12-rc2 |
675 |
{ |
bbe85bbd0 [ALSA] Remove xxx... |
676 |
struct usX2Ydev *usX2Y = hwdep->private_data; |
1da177e4c Linux-2.6.12-rc2 |
677 |
if (NULL != usX2Y->hwdep_pcm_shm) |
bbe85bbd0 [ALSA] Remove xxx... |
678 |
snd_free_pages(usX2Y->hwdep_pcm_shm, sizeof(struct snd_usX2Y_hwdep_pcm_shm)); |
1da177e4c Linux-2.6.12-rc2 |
679 |
} |
bbe85bbd0 [ALSA] Remove xxx... |
680 |
int usX2Y_hwdep_pcm_new(struct snd_card *card) |
1da177e4c Linux-2.6.12-rc2 |
681 682 |
{ int err; |
bbe85bbd0 [ALSA] Remove xxx... |
683 684 |
struct snd_hwdep *hw; struct snd_pcm *pcm; |
a014bbadb sound: usxxx: cle... |
685 |
struct usb_device *dev = usX2Y(card)->dev; |
1da177e4c Linux-2.6.12-rc2 |
686 687 |
if (1 != nr_of_packs()) return 0; |
cb432379e [ALSA] usx2y - Co... |
688 |
if ((err = snd_hwdep_new(card, SND_USX2Y_USBPCM_ID, 1, &hw)) < 0) |
1da177e4c Linux-2.6.12-rc2 |
689 |
return err; |
cb432379e [ALSA] usx2y - Co... |
690 |
|
1da177e4c Linux-2.6.12-rc2 |
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 |
hw->iface = SNDRV_HWDEP_IFACE_USX2Y_PCM; hw->private_data = usX2Y(card); hw->private_free = snd_usX2Y_hwdep_pcm_private_free; hw->ops.open = snd_usX2Y_hwdep_pcm_open; hw->ops.release = snd_usX2Y_hwdep_pcm_release; hw->ops.mmap = snd_usX2Y_hwdep_pcm_mmap; hw->exclusive = 1; sprintf(hw->name, "/proc/bus/usb/%03d/%03d/hwdeppcm", dev->bus->busnum, dev->devnum); err = snd_pcm_new(card, NAME_ALLCAPS" hwdep Audio", 2, 1, 1, &pcm); if (err < 0) { return err; } snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_usX2Y_usbpcm_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_usX2Y_usbpcm_ops); pcm->private_data = usX2Y(card)->subs; |
1da177e4c Linux-2.6.12-rc2 |
708 709 710 711 712 713 714 715 716 717 718 |
pcm->info_flags = 0; sprintf(pcm->name, NAME_ALLCAPS" hwdep Audio"); if (0 > (err = snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream, SNDRV_DMA_TYPE_CONTINUOUS, snd_dma_continuous_data(GFP_KERNEL), 64*1024, 128*1024)) || 0 > (err = snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream, SNDRV_DMA_TYPE_CONTINUOUS, snd_dma_continuous_data(GFP_KERNEL), 64*1024, 128*1024))) { |
1da177e4c Linux-2.6.12-rc2 |
719 720 721 722 723 724 725 726 |
return err; } return 0; } #else |
bbe85bbd0 [ALSA] Remove xxx... |
727 |
int usX2Y_hwdep_pcm_new(struct snd_card *card) |
1da177e4c Linux-2.6.12-rc2 |
728 729 730 731 732 |
{ return 0; } #endif |