18 #include <linux/slab.h>
21 #include <linux/usb/audio.h>
38 #define SUBSTREAM_FLAG_DATA_EP_STARTED 0
39 #define SUBSTREAM_FLAG_SYNC_EP_STARTED 1
45 int current_frame_number;
59 est_delay = subs->
last_delay - (frame_diff * rate / 1000);
76 spin_lock(&subs->
lock);
80 spin_unlock(&subs->
lock);
81 return hwptr_done / (substream->
runtime->frame_bits >> 3);
91 int cur_attr = 0,
attr;
122 if (
attr != cur_attr) {
147 struct usb_host_interface *alts,
150 struct usb_device *
dev = chip->
dev;
152 unsigned char data[1];
161 data,
sizeof(data))) < 0) {
163 dev->devnum, iface, ep);
170 static int init_pitch_v2(
struct snd_usb_audio *chip,
int iface,
171 struct usb_host_interface *alts,
174 struct usb_device *dev = chip->
dev;
175 unsigned char data[1];
185 data,
sizeof(data))) < 0) {
198 struct usb_host_interface *alts,
210 return init_pitch_v1(chip, iface, alts, fmt);
213 return init_pitch_v2(chip, iface, alts, fmt);
248 "%d:%d:%d: cannot set interface (%d)\n",
274 force, can_sleep, wait);
278 force, can_sleep, wait);
302 struct usb_device *dev = subs->
dev;
303 struct usb_host_interface *alts;
306 unsigned int ep,
attr;
308 int err, implicit_fb = 0;
361 switch (subs->
stream->chip->usb_id) {
362 case USB_ID(0x0763, 0x2080):
363 case
USB_ID(0x0763, 0x2081):
369 if (!iface || iface->num_altsetting == 0)
372 alts = &iface->altsetting[1];
388 snd_printk(
KERN_ERR "%d:%d:%d : invalid sync pipe. bmAttributes %02x, bLength %d, bSynchAddress %02x\n",
400 snd_printk(
KERN_ERR "%d:%d:%d : invalid sync pipe. is_playback %d, ep %02x, bSynchAddress %02x\n",
430 "setting done: format = %d, rate = %d..%d, channels = %d\n",
433 " datapipe = 0x%0x, syncpipe = 0x%0x\n",
434 subs->datapipe, subs->syncpipe);
450 stop_endpoints(subs, 0, 0, 0);
499 fmt = find_format(subs);
507 if (subs->
stream->chip->shutdown)
510 ret = set_format(subs, fmt);
535 if (!subs->
stream->chip->shutdown) {
536 stop_endpoints(subs, 0, 1, 1);
537 deactivate_endpoints(subs);
552 struct usb_host_interface *alts;
562 if (subs->
stream->chip->shutdown) {
579 alts = &iface->altsetting[subs->
cur_audiofmt->altset_idx];
589 ret = configure_endpoint(subs);
611 ret = start_endpoints(subs, 1);
626 .buffer_bytes_max = 1024 * 1024,
627 .period_bytes_min = 64,
628 .period_bytes_max = 512 * 1024,
645 snd_mask_none(&check_fmts);
647 check_fmts.bits[1] = (
u32)(fp->
formats >> 32);
648 snd_mask_intersect(&check_fmts, fmts);
649 if (snd_mask_empty(&check_fmts)) {
650 hwc_debug(
" > check: no supported format %d\n", fp->format);
671 hwc_debug(
" > check: ptime %u > max %u\n", ptime, pt->
max);
684 unsigned int rmin, rmax;
693 if (!hw_check_valid_format(subs, params, fp))
713 if (it->
min < rmin) {
718 if (it->
max > rmax) {
723 if (snd_interval_checkempty(it)) {
727 hwc_debug(
" --> (%d, %d) (changed = %d)\n", it->
min, it->
max, changed);
738 unsigned int rmin, rmax;
747 if (!hw_check_valid_format(subs, params, fp))
767 if (it->
min < rmin) {
772 if (it->
max > rmax) {
777 if (snd_interval_checkempty(it)) {
781 hwc_debug(
" --> (%d, %d) (changed = %d)\n", it->
min, it->
max, changed);
800 if (!hw_check_valid_format(subs, params, fp))
805 oldbits[0] = fmt->
bits[0];
806 oldbits[1] = fmt->
bits[1];
808 fmt->
bits[1] &= (
u32)(fbits >> 32);
809 if (!fmt->
bits[0] && !fmt->
bits[1]) {
813 changed = (oldbits[0] != fmt->
bits[0] || oldbits[1] != fmt->
bits[1]);
824 unsigned char min_datainterval;
830 min_datainterval = 0xff;
832 if (!hw_check_valid_format(subs, params, fp))
836 if (min_datainterval == 0xff) {
841 pmin = 125 * (1 << min_datainterval);
843 if (it->
min < pmin) {
848 if (snd_interval_checkempty(it)) {
864 int count = 0, needs_knot = 0;
908 unsigned int pt, ptmin;
909 int param_period_time_if_needed;
914 runtime->
hw.rate_min = 0x7fffffff;
915 runtime->
hw.rate_max = 0;
916 runtime->
hw.channels_min = 256;
917 runtime->
hw.channels_max = 0;
918 runtime->
hw.rates = 0;
924 runtime->
hw.rates |= fp->
rates;
935 runtime->
hw.period_bytes_min = runtime->
hw.period_bytes_max =
939 ptmin =
min(ptmin, pt);
941 err = snd_usb_autoresume(subs->
stream->chip);
951 param_period_time_if_needed = -1;
959 param_period_time_if_needed,
963 hw_rule_channels, subs,
966 param_period_time_if_needed,
970 hw_rule_format, subs,
973 param_period_time_if_needed,
976 if (param_period_time_if_needed >= 0) {
979 hw_rule_period_time, subs,
987 if ((err = snd_usb_pcm_check_knot(runtime, subs)) < 0)
992 snd_usb_autosuspend(subs->
stream->chip);
1004 runtime->
hw = snd_usb_hardware;
1008 return setup_hw_info(runtime, subs);
1016 stop_endpoints(subs, 0, 0, 0);
1024 snd_usb_autosuspend(subs->
stream->chip);
1038 unsigned int stride, frames,
bytes, oldptr;
1039 int i, period_elapsed = 0;
1040 unsigned long flags;
1045 for (i = 0; i < urb->number_of_packets; i++) {
1046 cp = (
unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset;
1047 if (urb->iso_frame_desc[i].status && printk_ratelimit()) {
1051 bytes = urb->iso_frame_desc[
i].actual_length;
1052 frames = bytes / stride;
1054 bytes = frames * stride;
1056 #ifdef CONFIG_SND_DEBUG_VERBOSE
1057 int oldbytes =
bytes;
1059 bytes = frames * stride;
1069 frames = (bytes + (oldptr % stride)) / stride;
1075 spin_unlock_irqrestore(&subs->
lock, flags);
1077 if (oldptr + bytes > runtime->
buffer_size * stride) {
1078 unsigned int bytes1 =
1097 unsigned int counts, frames,
bytes;
1098 int i, stride, period_elapsed = 0;
1099 unsigned long flags;
1104 urb->number_of_packets = 0;
1106 for (i = 0; i < ctx->
packets; i++) {
1113 urb->iso_frame_desc[
i].offset = frames * stride;
1114 urb->iso_frame_desc[
i].length = counts * stride;
1116 urb->number_of_packets++;
1127 urb->iso_frame_desc[
i].length =
1134 urb->iso_frame_desc[
i].offset =
1136 urb->iso_frame_desc[
i].length = 0;
1137 urb->number_of_packets++;
1142 if (period_elapsed &&
1146 bytes = frames * stride;
1149 unsigned int bytes1 =
1151 memcpy(urb->transfer_buffer,
1153 memcpy(urb->transfer_buffer + bytes1,
1154 runtime->
dma_area, bytes - bytes1);
1156 memcpy(urb->transfer_buffer,
1165 runtime->
delay += frames;
1172 spin_unlock_irqrestore(&subs->
lock, flags);
1173 urb->transfer_buffer_length =
bytes;
1185 unsigned long flags;
1188 int processed = urb->transfer_buffer_length / stride;
1215 spin_unlock_irqrestore(&subs->
lock, flags);
1238 static int snd_usb_substream_playback_trigger(
struct snd_pcm_substream *substream,
1246 subs->
data_endpoint->prepare_data_urb = prepare_playback_urb;
1251 stop_endpoints(subs, 0, 0, 0);
1264 static int snd_usb_substream_capture_trigger(
struct snd_pcm_substream *substream,
1272 err = start_endpoints(subs, 0);
1280 stop_endpoints(subs, 0, 0, 0);
1296 static struct snd_pcm_ops snd_usb_playback_ops = {
1297 .open = snd_usb_playback_open,
1298 .close = snd_usb_playback_close,
1300 .hw_params = snd_usb_hw_params,
1301 .hw_free = snd_usb_hw_free,
1302 .prepare = snd_usb_pcm_prepare,
1303 .trigger = snd_usb_substream_playback_trigger,
1304 .pointer = snd_usb_pcm_pointer,
1310 .open = snd_usb_capture_open,
1311 .close = snd_usb_capture_close,
1313 .hw_params = snd_usb_hw_params,
1314 .hw_free = snd_usb_hw_free,
1315 .prepare = snd_usb_pcm_prepare,
1316 .trigger = snd_usb_substream_capture_trigger,
1317 .pointer = snd_usb_pcm_pointer,
1326 &snd_usb_playback_ops : &snd_usb_capture_ops);