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