diff options
Diffstat (limited to 'sound/usb/usbaudio.c')
-rw-r--r-- | sound/usb/usbaudio.c | 105 |
1 files changed, 62 insertions, 43 deletions
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c index b5e734d975e0..8298c462c291 100644 --- a/sound/usb/usbaudio.c +++ b/sound/usb/usbaudio.c | |||
@@ -153,6 +153,7 @@ struct snd_usb_substream { | |||
153 | unsigned int format; /* USB data format */ | 153 | unsigned int format; /* USB data format */ |
154 | unsigned int datapipe; /* the data i/o pipe */ | 154 | unsigned int datapipe; /* the data i/o pipe */ |
155 | unsigned int syncpipe; /* 1 - async out or adaptive in */ | 155 | unsigned int syncpipe; /* 1 - async out or adaptive in */ |
156 | unsigned int datainterval; /* log_2 of data packet interval */ | ||
156 | unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */ | 157 | unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */ |
157 | unsigned int freqn; /* nominal sampling rate in fs/fps in Q16.16 format */ | 158 | unsigned int freqn; /* nominal sampling rate in fs/fps in Q16.16 format */ |
158 | unsigned int freqm; /* momentary sampling rate in fs/fps in Q16.16 format */ | 159 | unsigned int freqm; /* momentary sampling rate in fs/fps in Q16.16 format */ |
@@ -518,7 +519,8 @@ static int prepare_playback_urb(snd_usb_substream_t *subs, | |||
518 | if (subs->fill_max) | 519 | if (subs->fill_max) |
519 | counts = subs->maxframesize; /* fixed */ | 520 | counts = subs->maxframesize; /* fixed */ |
520 | else { | 521 | else { |
521 | subs->phase = (subs->phase & 0xffff) + subs->freqm; | 522 | subs->phase = (subs->phase & 0xffff) |
523 | + (subs->freqm << subs->datainterval); | ||
522 | counts = subs->phase >> 16; | 524 | counts = subs->phase >> 16; |
523 | if (counts > subs->maxframesize) | 525 | if (counts > subs->maxframesize) |
524 | counts = subs->maxframesize; | 526 | counts = subs->maxframesize; |
@@ -790,7 +792,7 @@ static int start_urbs(snd_usb_substream_t *subs, snd_pcm_runtime_t *runtime) | |||
790 | */ | 792 | */ |
791 | static int wait_clear_urbs(snd_usb_substream_t *subs) | 793 | static int wait_clear_urbs(snd_usb_substream_t *subs) |
792 | { | 794 | { |
793 | int timeout = HZ; | 795 | unsigned long end_time = jiffies + msecs_to_jiffies(1000); |
794 | unsigned int i; | 796 | unsigned int i; |
795 | int alive; | 797 | int alive; |
796 | 798 | ||
@@ -810,7 +812,7 @@ static int wait_clear_urbs(snd_usb_substream_t *subs) | |||
810 | break; | 812 | break; |
811 | set_current_state(TASK_UNINTERRUPTIBLE); | 813 | set_current_state(TASK_UNINTERRUPTIBLE); |
812 | schedule_timeout(1); | 814 | schedule_timeout(1); |
813 | } while (--timeout > 0); | 815 | } while (time_before(jiffies, end_time)); |
814 | if (alive) | 816 | if (alive) |
815 | snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive); | 817 | snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive); |
816 | return 0; | 818 | return 0; |
@@ -899,16 +901,19 @@ static int init_substream_urbs(snd_usb_substream_t *subs, unsigned int period_by | |||
899 | else | 901 | else |
900 | subs->freqn = get_usb_high_speed_rate(rate); | 902 | subs->freqn = get_usb_high_speed_rate(rate); |
901 | subs->freqm = subs->freqn; | 903 | subs->freqm = subs->freqn; |
902 | subs->freqmax = subs->freqn + (subs->freqn >> 2); /* max. allowed frequency */ | 904 | /* calculate max. frequency */ |
903 | subs->phase = 0; | 905 | if (subs->maxpacksize) { |
904 | 906 | /* whatever fits into a max. size packet */ | |
905 | /* calculate the max. size of packet */ | ||
906 | maxsize = ((subs->freqmax + 0xffff) * (frame_bits >> 3)) >> 16; | ||
907 | if (subs->maxpacksize && maxsize > subs->maxpacksize) { | ||
908 | //snd_printd(KERN_DEBUG "maxsize %d is greater than defined size %d\n", | ||
909 | // maxsize, subs->maxpacksize); | ||
910 | maxsize = subs->maxpacksize; | 907 | maxsize = subs->maxpacksize; |
908 | subs->freqmax = (maxsize / (frame_bits >> 3)) | ||
909 | << (16 - subs->datainterval); | ||
910 | } else { | ||
911 | /* no max. packet size: just take 25% higher than nominal */ | ||
912 | subs->freqmax = subs->freqn + (subs->freqn >> 2); | ||
913 | maxsize = ((subs->freqmax + 0xffff) * (frame_bits >> 3)) | ||
914 | >> (16 - subs->datainterval); | ||
911 | } | 915 | } |
916 | subs->phase = 0; | ||
912 | 917 | ||
913 | if (subs->fill_max) | 918 | if (subs->fill_max) |
914 | subs->curpacksize = subs->maxpacksize; | 919 | subs->curpacksize = subs->maxpacksize; |
@@ -918,7 +923,7 @@ static int init_substream_urbs(snd_usb_substream_t *subs, unsigned int period_by | |||
918 | if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) | 923 | if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) |
919 | urb_packs = nrpacks; | 924 | urb_packs = nrpacks; |
920 | else | 925 | else |
921 | urb_packs = nrpacks * 8; | 926 | urb_packs = (nrpacks * 8) >> subs->datainterval; |
922 | 927 | ||
923 | /* allocate a temporary buffer for playback */ | 928 | /* allocate a temporary buffer for playback */ |
924 | if (is_playback) { | 929 | if (is_playback) { |
@@ -991,7 +996,7 @@ static int init_substream_urbs(snd_usb_substream_t *subs, unsigned int period_by | |||
991 | u->urb->pipe = subs->datapipe; | 996 | u->urb->pipe = subs->datapipe; |
992 | u->urb->transfer_flags = URB_ISO_ASAP; | 997 | u->urb->transfer_flags = URB_ISO_ASAP; |
993 | u->urb->number_of_packets = u->packets; | 998 | u->urb->number_of_packets = u->packets; |
994 | u->urb->interval = 1; | 999 | u->urb->interval = 1 << subs->datainterval; |
995 | u->urb->context = u; | 1000 | u->urb->context = u; |
996 | u->urb->complete = snd_usb_complete_callback(snd_complete_urb); | 1001 | u->urb->complete = snd_usb_complete_callback(snd_complete_urb); |
997 | } | 1002 | } |
@@ -1195,6 +1200,12 @@ static int set_format(snd_usb_substream_t *subs, struct audioformat *fmt) | |||
1195 | subs->datapipe = usb_sndisocpipe(dev, ep); | 1200 | subs->datapipe = usb_sndisocpipe(dev, ep); |
1196 | else | 1201 | else |
1197 | subs->datapipe = usb_rcvisocpipe(dev, ep); | 1202 | subs->datapipe = usb_rcvisocpipe(dev, ep); |
1203 | if (snd_usb_get_speed(subs->dev) == USB_SPEED_HIGH && | ||
1204 | get_endpoint(alts, 0)->bInterval >= 1 && | ||
1205 | get_endpoint(alts, 0)->bInterval <= 4) | ||
1206 | subs->datainterval = get_endpoint(alts, 0)->bInterval - 1; | ||
1207 | else | ||
1208 | subs->datainterval = 0; | ||
1198 | subs->syncpipe = subs->syncinterval = 0; | 1209 | subs->syncpipe = subs->syncinterval = 0; |
1199 | subs->maxpacksize = fmt->maxpacksize; | 1210 | subs->maxpacksize = fmt->maxpacksize; |
1200 | subs->fill_max = 0; | 1211 | subs->fill_max = 0; |
@@ -2397,10 +2408,9 @@ static int parse_audio_format(snd_usb_audio_t *chip, struct audioformat *fp, | |||
2397 | if (chip->usb_id == USB_ID(0x041e, 0x3000) || | 2408 | if (chip->usb_id == USB_ID(0x041e, 0x3000) || |
2398 | chip->usb_id == USB_ID(0x041e, 0x3020)) { | 2409 | chip->usb_id == USB_ID(0x041e, 0x3020)) { |
2399 | if (fmt[3] == USB_FORMAT_TYPE_I && | 2410 | if (fmt[3] == USB_FORMAT_TYPE_I && |
2400 | stream == SNDRV_PCM_STREAM_PLAYBACK && | ||
2401 | fp->rates != SNDRV_PCM_RATE_48000 && | 2411 | fp->rates != SNDRV_PCM_RATE_48000 && |
2402 | fp->rates != SNDRV_PCM_RATE_96000) | 2412 | fp->rates != SNDRV_PCM_RATE_96000) |
2403 | return -1; /* use 48k only */ | 2413 | return -1; |
2404 | } | 2414 | } |
2405 | #endif | 2415 | #endif |
2406 | return 0; | 2416 | return 0; |
@@ -2492,8 +2502,10 @@ static int parse_audio_endpoints(snd_usb_audio_t *chip, int iface_no) | |||
2492 | fp->altset_idx = i; | 2502 | fp->altset_idx = i; |
2493 | fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress; | 2503 | fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress; |
2494 | fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; | 2504 | fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; |
2495 | /* FIXME: decode wMaxPacketSize of high bandwith endpoints */ | ||
2496 | fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); | 2505 | fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); |
2506 | if (snd_usb_get_speed(dev) == USB_SPEED_HIGH) | ||
2507 | fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1) | ||
2508 | * (fp->maxpacksize & 0x7ff); | ||
2497 | fp->attributes = csep[3]; | 2509 | fp->attributes = csep[3]; |
2498 | 2510 | ||
2499 | /* some quirks for attributes here */ | 2511 | /* some quirks for attributes here */ |
@@ -2723,7 +2735,8 @@ static int create_standard_interface_quirk(snd_usb_audio_t *chip, | |||
2723 | * to detect the sample rate is by looking at wMaxPacketSize. | 2735 | * to detect the sample rate is by looking at wMaxPacketSize. |
2724 | */ | 2736 | */ |
2725 | static int create_ua700_ua25_quirk(snd_usb_audio_t *chip, | 2737 | static int create_ua700_ua25_quirk(snd_usb_audio_t *chip, |
2726 | struct usb_interface *iface) | 2738 | struct usb_interface *iface, |
2739 | const snd_usb_audio_quirk_t *quirk) | ||
2727 | { | 2740 | { |
2728 | static const struct audioformat ua_format = { | 2741 | static const struct audioformat ua_format = { |
2729 | .format = SNDRV_PCM_FORMAT_S24_3LE, | 2742 | .format = SNDRV_PCM_FORMAT_S24_3LE, |
@@ -2814,7 +2827,9 @@ static int create_ua700_ua25_quirk(snd_usb_audio_t *chip, | |||
2814 | /* | 2827 | /* |
2815 | * Create a stream for an Edirol UA-1000 interface. | 2828 | * Create a stream for an Edirol UA-1000 interface. |
2816 | */ | 2829 | */ |
2817 | static int create_ua1000_quirk(snd_usb_audio_t *chip, struct usb_interface *iface) | 2830 | static int create_ua1000_quirk(snd_usb_audio_t *chip, |
2831 | struct usb_interface *iface, | ||
2832 | const snd_usb_audio_quirk_t *quirk) | ||
2818 | { | 2833 | { |
2819 | static const struct audioformat ua1000_format = { | 2834 | static const struct audioformat ua1000_format = { |
2820 | .format = SNDRV_PCM_FORMAT_S32_LE, | 2835 | .format = SNDRV_PCM_FORMAT_S32_LE, |
@@ -2891,6 +2906,13 @@ static int create_composite_quirk(snd_usb_audio_t *chip, | |||
2891 | return 0; | 2906 | return 0; |
2892 | } | 2907 | } |
2893 | 2908 | ||
2909 | static int ignore_interface_quirk(snd_usb_audio_t *chip, | ||
2910 | struct usb_interface *iface, | ||
2911 | const snd_usb_audio_quirk_t *quirk) | ||
2912 | { | ||
2913 | return 0; | ||
2914 | } | ||
2915 | |||
2894 | 2916 | ||
2895 | /* | 2917 | /* |
2896 | * boot quirks | 2918 | * boot quirks |
@@ -2926,8 +2948,6 @@ static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interfac | |||
2926 | 2948 | ||
2927 | static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev) | 2949 | static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev) |
2928 | { | 2950 | { |
2929 | #if 0 | ||
2930 | /* TODO: enable this when high speed synchronization actually works */ | ||
2931 | u8 buf = 1; | 2951 | u8 buf = 1; |
2932 | 2952 | ||
2933 | snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a, | 2953 | snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a, |
@@ -2939,7 +2959,6 @@ static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev) | |||
2939 | 1, 2000, NULL, 0, 1000); | 2959 | 1, 2000, NULL, 0, 1000); |
2940 | return -ENODEV; | 2960 | return -ENODEV; |
2941 | } | 2961 | } |
2942 | #endif | ||
2943 | return 0; | 2962 | return 0; |
2944 | } | 2963 | } |
2945 | 2964 | ||
@@ -2956,28 +2975,28 @@ static int snd_usb_create_quirk(snd_usb_audio_t *chip, | |||
2956 | struct usb_interface *iface, | 2975 | struct usb_interface *iface, |
2957 | const snd_usb_audio_quirk_t *quirk) | 2976 | const snd_usb_audio_quirk_t *quirk) |
2958 | { | 2977 | { |
2959 | switch (quirk->type) { | 2978 | typedef int (*quirk_func_t)(snd_usb_audio_t *, struct usb_interface *, |
2960 | case QUIRK_MIDI_FIXED_ENDPOINT: | 2979 | const snd_usb_audio_quirk_t *); |
2961 | case QUIRK_MIDI_YAMAHA: | 2980 | static const quirk_func_t quirk_funcs[] = { |
2962 | case QUIRK_MIDI_MIDIMAN: | 2981 | [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk, |
2963 | case QUIRK_MIDI_NOVATION: | 2982 | [QUIRK_COMPOSITE] = create_composite_quirk, |
2964 | case QUIRK_MIDI_MOTU: | 2983 | [QUIRK_MIDI_STANDARD_INTERFACE] = snd_usb_create_midi_interface, |
2965 | case QUIRK_MIDI_EMAGIC: | 2984 | [QUIRK_MIDI_FIXED_ENDPOINT] = snd_usb_create_midi_interface, |
2966 | return snd_usb_create_midi_interface(chip, iface, quirk); | 2985 | [QUIRK_MIDI_YAMAHA] = snd_usb_create_midi_interface, |
2967 | case QUIRK_COMPOSITE: | 2986 | [QUIRK_MIDI_MIDIMAN] = snd_usb_create_midi_interface, |
2968 | return create_composite_quirk(chip, iface, quirk); | 2987 | [QUIRK_MIDI_NOVATION] = snd_usb_create_midi_interface, |
2969 | case QUIRK_AUDIO_FIXED_ENDPOINT: | 2988 | [QUIRK_MIDI_RAW] = snd_usb_create_midi_interface, |
2970 | return create_fixed_stream_quirk(chip, iface, quirk); | 2989 | [QUIRK_MIDI_EMAGIC] = snd_usb_create_midi_interface, |
2971 | case QUIRK_AUDIO_STANDARD_INTERFACE: | 2990 | [QUIRK_MIDI_MIDITECH] = snd_usb_create_midi_interface, |
2972 | case QUIRK_MIDI_STANDARD_INTERFACE: | 2991 | [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_interface_quirk, |
2973 | return create_standard_interface_quirk(chip, iface, quirk); | 2992 | [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, |
2974 | case QUIRK_AUDIO_EDIROL_UA700_UA25: | 2993 | [QUIRK_AUDIO_EDIROL_UA700_UA25] = create_ua700_ua25_quirk, |
2975 | return create_ua700_ua25_quirk(chip, iface); | 2994 | [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk, |
2976 | case QUIRK_AUDIO_EDIROL_UA1000: | 2995 | }; |
2977 | return create_ua1000_quirk(chip, iface); | 2996 | |
2978 | case QUIRK_IGNORE_INTERFACE: | 2997 | if (quirk->type < QUIRK_TYPE_COUNT) { |
2979 | return 0; | 2998 | return quirk_funcs[quirk->type](chip, iface, quirk); |
2980 | default: | 2999 | } else { |
2981 | snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type); | 3000 | snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type); |
2982 | return -ENXIO; | 3001 | return -ENXIO; |
2983 | } | 3002 | } |