diff options
author | Takashi Iwai <tiwai@suse.de> | 2011-10-26 17:51:43 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2011-10-26 17:51:43 -0400 |
commit | d22665702226e9c40bc331098559e3d55e7cd43d (patch) | |
tree | 6e92734c9835dc9e064b20182624939f3486d28d | |
parent | 5cdf745ebae0f5bcf9b798d8fd5cb57add592cc1 (diff) | |
parent | dde7ad8dee274763c8958769779aea8c993c950e (diff) |
Merge branch 'topic/misc' into for-linus
86 files changed, 2025 insertions, 1584 deletions
diff --git a/Documentation/DocBook/writing-an-alsa-driver.tmpl b/Documentation/DocBook/writing-an-alsa-driver.tmpl index 598c22f3b3ac..5de23c007078 100644 --- a/Documentation/DocBook/writing-an-alsa-driver.tmpl +++ b/Documentation/DocBook/writing-an-alsa-driver.tmpl | |||
@@ -4288,7 +4288,7 @@ struct _snd_pcm_runtime { | |||
4288 | <![CDATA[ | 4288 | <![CDATA[ |
4289 | struct snd_rawmidi *rmidi; | 4289 | struct snd_rawmidi *rmidi; |
4290 | snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port, info_flags, | 4290 | snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port, info_flags, |
4291 | irq, irq_flags, &rmidi); | 4291 | irq, &rmidi); |
4292 | ]]> | 4292 | ]]> |
4293 | </programlisting> | 4293 | </programlisting> |
4294 | </informalexample> | 4294 | </informalexample> |
@@ -4343,6 +4343,13 @@ struct _snd_pcm_runtime { | |||
4343 | by itself to start processing the output stream in the irq handler. | 4343 | by itself to start processing the output stream in the irq handler. |
4344 | </para> | 4344 | </para> |
4345 | 4345 | ||
4346 | <para> | ||
4347 | If the MPU-401 interface shares its interrupt with the other logical | ||
4348 | devices on the card, set <constant>MPU401_INFO_IRQ_HOOK</constant> | ||
4349 | (see <link linkend="midi-interface-interrupt-handler"><citetitle> | ||
4350 | below</citetitle></link>). | ||
4351 | </para> | ||
4352 | |||
4346 | <para> | 4353 | <para> |
4347 | Usually, the port address corresponds to the command port and | 4354 | Usually, the port address corresponds to the command port and |
4348 | port + 1 corresponds to the data port. If not, you may change | 4355 | port + 1 corresponds to the data port. If not, you may change |
@@ -4375,14 +4382,12 @@ struct _snd_pcm_runtime { | |||
4375 | </para> | 4382 | </para> |
4376 | 4383 | ||
4377 | <para> | 4384 | <para> |
4378 | The 6th argument specifies the irq number for UART. If the irq | 4385 | The 6th argument specifies the ISA irq number that will be |
4379 | is already allocated, pass 0 to the 7th argument | 4386 | allocated. If no interrupt is to be allocated (because your |
4380 | (<parameter>irq_flags</parameter>). Otherwise, pass the flags | 4387 | code is already allocating a shared interrupt, or because the |
4381 | for irq allocation | 4388 | device does not use interrupts), pass -1 instead. |
4382 | (<constant>SA_XXX</constant> bits) to it, and the irq will be | 4389 | For a MPU-401 device without an interrupt, a polling timer |
4383 | reserved by the mpu401-uart layer. If the card doesn't generate | 4390 | will be used instead. |
4384 | UART interrupts, pass -1 as the irq number. Then a timer | ||
4385 | interrupt will be invoked for polling. | ||
4386 | </para> | 4391 | </para> |
4387 | </section> | 4392 | </section> |
4388 | 4393 | ||
@@ -4390,12 +4395,13 @@ struct _snd_pcm_runtime { | |||
4390 | <title>Interrupt Handler</title> | 4395 | <title>Interrupt Handler</title> |
4391 | <para> | 4396 | <para> |
4392 | When the interrupt is allocated in | 4397 | When the interrupt is allocated in |
4393 | <function>snd_mpu401_uart_new()</function>, the private | 4398 | <function>snd_mpu401_uart_new()</function>, an exclusive ISA |
4394 | interrupt handler is used, hence you don't have anything else to do | 4399 | interrupt handler is automatically used, hence you don't have |
4395 | than creating the mpu401 stuff. Otherwise, you have to call | 4400 | anything else to do than creating the mpu401 stuff. Otherwise, you |
4396 | <function>snd_mpu401_uart_interrupt()</function> explicitly when | 4401 | have to set <constant>MPU401_INFO_IRQ_HOOK</constant>, and call |
4397 | a UART interrupt is invoked and checked in your own interrupt | 4402 | <function>snd_mpu401_uart_interrupt()</function> explicitly from your |
4398 | handler. | 4403 | own interrupt handler when it has determined that a UART interrupt |
4404 | has occurred. | ||
4399 | </para> | 4405 | </para> |
4400 | 4406 | ||
4401 | <para> | 4407 | <para> |
diff --git a/MAINTAINERS b/MAINTAINERS index 0b4ccdd35bbb..a676343a27bc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -5990,7 +5990,7 @@ M: Jaroslav Kysela <perex@perex.cz> | |||
5990 | M: Takashi Iwai <tiwai@suse.de> | 5990 | M: Takashi Iwai <tiwai@suse.de> |
5991 | L: alsa-devel@alsa-project.org (moderated for non-subscribers) | 5991 | L: alsa-devel@alsa-project.org (moderated for non-subscribers) |
5992 | W: http://www.alsa-project.org/ | 5992 | W: http://www.alsa-project.org/ |
5993 | T: git git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6.git | 5993 | T: git git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git |
5994 | T: git git://git.alsa-project.org/alsa-kernel.git | 5994 | T: git git://git.alsa-project.org/alsa-kernel.git |
5995 | S: Maintained | 5995 | S: Maintained |
5996 | F: Documentation/sound/ | 5996 | F: Documentation/sound/ |
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h index 0fd3fbdd8283..f30253599501 100644 --- a/include/linux/usb/ch9.h +++ b/include/linux/usb/ch9.h | |||
@@ -377,12 +377,6 @@ struct usb_endpoint_descriptor { | |||
377 | #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */ | 377 | #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */ |
378 | #define USB_ENDPOINT_DIR_MASK 0x80 | 378 | #define USB_ENDPOINT_DIR_MASK 0x80 |
379 | 379 | ||
380 | #define USB_ENDPOINT_SYNCTYPE 0x0c | ||
381 | #define USB_ENDPOINT_SYNC_NONE (0 << 2) | ||
382 | #define USB_ENDPOINT_SYNC_ASYNC (1 << 2) | ||
383 | #define USB_ENDPOINT_SYNC_ADAPTIVE (2 << 2) | ||
384 | #define USB_ENDPOINT_SYNC_SYNC (3 << 2) | ||
385 | |||
386 | #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */ | 380 | #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */ |
387 | #define USB_ENDPOINT_XFER_CONTROL 0 | 381 | #define USB_ENDPOINT_XFER_CONTROL 0 |
388 | #define USB_ENDPOINT_XFER_ISOC 1 | 382 | #define USB_ENDPOINT_XFER_ISOC 1 |
@@ -390,6 +384,17 @@ struct usb_endpoint_descriptor { | |||
390 | #define USB_ENDPOINT_XFER_INT 3 | 384 | #define USB_ENDPOINT_XFER_INT 3 |
391 | #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80 | 385 | #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80 |
392 | 386 | ||
387 | #define USB_ENDPOINT_SYNCTYPE 0x0c | ||
388 | #define USB_ENDPOINT_SYNC_NONE (0 << 2) | ||
389 | #define USB_ENDPOINT_SYNC_ASYNC (1 << 2) | ||
390 | #define USB_ENDPOINT_SYNC_ADAPTIVE (2 << 2) | ||
391 | #define USB_ENDPOINT_SYNC_SYNC (3 << 2) | ||
392 | |||
393 | #define USB_ENDPOINT_USAGE_MASK 0x30 | ||
394 | #define USB_ENDPOINT_USAGE_DATA 0x00 | ||
395 | #define USB_ENDPOINT_USAGE_FEEDBACK 0x10 | ||
396 | #define USB_ENDPOINT_USAGE_IMPLICIT_FB 0x20 /* Implicit feedback Data endpoint */ | ||
397 | |||
393 | /*-------------------------------------------------------------------------*/ | 398 | /*-------------------------------------------------------------------------*/ |
394 | 399 | ||
395 | /** | 400 | /** |
diff --git a/include/sound/asound.h b/include/sound/asound.h index 5d6074faa279..a2e4ff5ba9e9 100644 --- a/include/sound/asound.h +++ b/include/sound/asound.h | |||
@@ -706,7 +706,7 @@ struct snd_timer_tread { | |||
706 | * * | 706 | * * |
707 | ****************************************************************************/ | 707 | ****************************************************************************/ |
708 | 708 | ||
709 | #define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 6) | 709 | #define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 7) |
710 | 710 | ||
711 | struct snd_ctl_card_info { | 711 | struct snd_ctl_card_info { |
712 | int card; /* card number */ | 712 | int card; /* card number */ |
@@ -803,6 +803,8 @@ struct snd_ctl_elem_info { | |||
803 | unsigned int items; /* R: number of items */ | 803 | unsigned int items; /* R: number of items */ |
804 | unsigned int item; /* W: item number */ | 804 | unsigned int item; /* W: item number */ |
805 | char name[64]; /* R: value name */ | 805 | char name[64]; /* R: value name */ |
806 | __u64 names_ptr; /* W: names list (ELEM_ADD only) */ | ||
807 | unsigned int names_length; | ||
806 | } enumerated; | 808 | } enumerated; |
807 | unsigned char reserved[128]; | 809 | unsigned char reserved[128]; |
808 | } value; | 810 | } value; |
diff --git a/include/sound/mpu401.h b/include/sound/mpu401.h index 1f1d53f8830b..20230db00ef1 100644 --- a/include/sound/mpu401.h +++ b/include/sound/mpu401.h | |||
@@ -50,7 +50,10 @@ | |||
50 | #define MPU401_INFO_INTEGRATED (1 << 2) /* integrated h/w port */ | 50 | #define MPU401_INFO_INTEGRATED (1 << 2) /* integrated h/w port */ |
51 | #define MPU401_INFO_MMIO (1 << 3) /* MMIO access */ | 51 | #define MPU401_INFO_MMIO (1 << 3) /* MMIO access */ |
52 | #define MPU401_INFO_TX_IRQ (1 << 4) /* independent TX irq */ | 52 | #define MPU401_INFO_TX_IRQ (1 << 4) /* independent TX irq */ |
53 | #define MPU401_INFO_IRQ_HOOK (1 << 5) /* mpu401 irq handler is called | ||
54 | from driver irq handler */ | ||
53 | #define MPU401_INFO_NO_ACK (1 << 6) /* No ACK cmd needed */ | 55 | #define MPU401_INFO_NO_ACK (1 << 6) /* No ACK cmd needed */ |
56 | #define MPU401_INFO_USE_TIMER (1 << 15) /* internal */ | ||
54 | 57 | ||
55 | #define MPU401_MODE_BIT_INPUT 0 | 58 | #define MPU401_MODE_BIT_INPUT 0 |
56 | #define MPU401_MODE_BIT_OUTPUT 1 | 59 | #define MPU401_MODE_BIT_OUTPUT 1 |
@@ -73,8 +76,7 @@ struct snd_mpu401 { | |||
73 | unsigned long port; /* base port of MPU-401 chip */ | 76 | unsigned long port; /* base port of MPU-401 chip */ |
74 | unsigned long cport; /* port + 1 (usually) */ | 77 | unsigned long cport; /* port + 1 (usually) */ |
75 | struct resource *res; /* port resource */ | 78 | struct resource *res; /* port resource */ |
76 | int irq; /* IRQ number of MPU-401 chip (-1 = poll) */ | 79 | int irq; /* IRQ number of MPU-401 chip */ |
77 | int irq_flags; | ||
78 | 80 | ||
79 | unsigned long mode; /* MPU401_MODE_XXXX */ | 81 | unsigned long mode; /* MPU401_MODE_XXXX */ |
80 | int timer_invoked; | 82 | int timer_invoked; |
@@ -131,7 +133,6 @@ int snd_mpu401_uart_new(struct snd_card *card, | |||
131 | unsigned long port, | 133 | unsigned long port, |
132 | unsigned int info_flags, | 134 | unsigned int info_flags, |
133 | int irq, | 135 | int irq, |
134 | int irq_flags, | ||
135 | struct snd_rawmidi ** rrawmidi); | 136 | struct snd_rawmidi ** rrawmidi); |
136 | 137 | ||
137 | #endif /* __SOUND_MPU401_H */ | 138 | #endif /* __SOUND_MPU401_H */ |
diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 249d98838d90..3e7fda6e8164 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h | |||
@@ -825,6 +825,8 @@ int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime, | |||
825 | int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime, | 825 | int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime, |
826 | unsigned int cond, | 826 | unsigned int cond, |
827 | snd_pcm_hw_param_t var); | 827 | snd_pcm_hw_param_t var); |
828 | int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime, | ||
829 | unsigned int base_rate); | ||
828 | int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, | 830 | int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, |
829 | unsigned int cond, | 831 | unsigned int cond, |
830 | int var, | 832 | int var, |
diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c index 3687a6cc9881..762af68c8996 100644 --- a/sound/aoa/codecs/onyx.c +++ b/sound/aoa/codecs/onyx.c | |||
@@ -1067,7 +1067,6 @@ static int onyx_i2c_probe(struct i2c_client *client, | |||
1067 | printk(KERN_DEBUG PFX "created and attached onyx instance\n"); | 1067 | printk(KERN_DEBUG PFX "created and attached onyx instance\n"); |
1068 | return 0; | 1068 | return 0; |
1069 | fail: | 1069 | fail: |
1070 | i2c_set_clientdata(client, NULL); | ||
1071 | kfree(onyx); | 1070 | kfree(onyx); |
1072 | return -ENODEV; | 1071 | return -ENODEV; |
1073 | } | 1072 | } |
@@ -1112,8 +1111,7 @@ static int onyx_i2c_remove(struct i2c_client *client) | |||
1112 | 1111 | ||
1113 | aoa_codec_unregister(&onyx->codec); | 1112 | aoa_codec_unregister(&onyx->codec); |
1114 | of_node_put(onyx->codec.node); | 1113 | of_node_put(onyx->codec.node); |
1115 | if (onyx->codec_info) | 1114 | kfree(onyx->codec_info); |
1116 | kfree(onyx->codec_info); | ||
1117 | kfree(onyx); | 1115 | kfree(onyx); |
1118 | return 0; | 1116 | return 0; |
1119 | } | 1117 | } |
diff --git a/sound/core/control.c b/sound/core/control.c index f8c5be464510..978fe1a8e9f0 100644 --- a/sound/core/control.c +++ b/sound/core/control.c | |||
@@ -989,7 +989,6 @@ struct user_element { | |||
989 | void *tlv_data; /* TLV data */ | 989 | void *tlv_data; /* TLV data */ |
990 | unsigned long tlv_data_size; /* TLV data size */ | 990 | unsigned long tlv_data_size; /* TLV data size */ |
991 | void *priv_data; /* private data (like strings for enumerated type) */ | 991 | void *priv_data; /* private data (like strings for enumerated type) */ |
992 | unsigned long priv_data_size; /* size of private data in bytes */ | ||
993 | }; | 992 | }; |
994 | 993 | ||
995 | static int snd_ctl_elem_user_info(struct snd_kcontrol *kcontrol, | 994 | static int snd_ctl_elem_user_info(struct snd_kcontrol *kcontrol, |
@@ -1001,6 +1000,28 @@ static int snd_ctl_elem_user_info(struct snd_kcontrol *kcontrol, | |||
1001 | return 0; | 1000 | return 0; |
1002 | } | 1001 | } |
1003 | 1002 | ||
1003 | static int snd_ctl_elem_user_enum_info(struct snd_kcontrol *kcontrol, | ||
1004 | struct snd_ctl_elem_info *uinfo) | ||
1005 | { | ||
1006 | struct user_element *ue = kcontrol->private_data; | ||
1007 | const char *names; | ||
1008 | unsigned int item; | ||
1009 | |||
1010 | item = uinfo->value.enumerated.item; | ||
1011 | |||
1012 | *uinfo = ue->info; | ||
1013 | |||
1014 | item = min(item, uinfo->value.enumerated.items - 1); | ||
1015 | uinfo->value.enumerated.item = item; | ||
1016 | |||
1017 | names = ue->priv_data; | ||
1018 | for (; item > 0; --item) | ||
1019 | names += strlen(names) + 1; | ||
1020 | strcpy(uinfo->value.enumerated.name, names); | ||
1021 | |||
1022 | return 0; | ||
1023 | } | ||
1024 | |||
1004 | static int snd_ctl_elem_user_get(struct snd_kcontrol *kcontrol, | 1025 | static int snd_ctl_elem_user_get(struct snd_kcontrol *kcontrol, |
1005 | struct snd_ctl_elem_value *ucontrol) | 1026 | struct snd_ctl_elem_value *ucontrol) |
1006 | { | 1027 | { |
@@ -1055,11 +1076,46 @@ static int snd_ctl_elem_user_tlv(struct snd_kcontrol *kcontrol, | |||
1055 | return change; | 1076 | return change; |
1056 | } | 1077 | } |
1057 | 1078 | ||
1079 | static int snd_ctl_elem_init_enum_names(struct user_element *ue) | ||
1080 | { | ||
1081 | char *names, *p; | ||
1082 | size_t buf_len, name_len; | ||
1083 | unsigned int i; | ||
1084 | |||
1085 | if (ue->info.value.enumerated.names_length > 64 * 1024) | ||
1086 | return -EINVAL; | ||
1087 | |||
1088 | names = memdup_user( | ||
1089 | (const void __user *)ue->info.value.enumerated.names_ptr, | ||
1090 | ue->info.value.enumerated.names_length); | ||
1091 | if (IS_ERR(names)) | ||
1092 | return PTR_ERR(names); | ||
1093 | |||
1094 | /* check that there are enough valid names */ | ||
1095 | buf_len = ue->info.value.enumerated.names_length; | ||
1096 | p = names; | ||
1097 | for (i = 0; i < ue->info.value.enumerated.items; ++i) { | ||
1098 | name_len = strnlen(p, buf_len); | ||
1099 | if (name_len == 0 || name_len >= 64 || name_len == buf_len) { | ||
1100 | kfree(names); | ||
1101 | return -EINVAL; | ||
1102 | } | ||
1103 | p += name_len + 1; | ||
1104 | buf_len -= name_len + 1; | ||
1105 | } | ||
1106 | |||
1107 | ue->priv_data = names; | ||
1108 | ue->info.value.enumerated.names_ptr = 0; | ||
1109 | |||
1110 | return 0; | ||
1111 | } | ||
1112 | |||
1058 | static void snd_ctl_elem_user_free(struct snd_kcontrol *kcontrol) | 1113 | static void snd_ctl_elem_user_free(struct snd_kcontrol *kcontrol) |
1059 | { | 1114 | { |
1060 | struct user_element *ue = kcontrol->private_data; | 1115 | struct user_element *ue = kcontrol->private_data; |
1061 | if (ue->tlv_data) | 1116 | |
1062 | kfree(ue->tlv_data); | 1117 | kfree(ue->tlv_data); |
1118 | kfree(ue->priv_data); | ||
1063 | kfree(ue); | 1119 | kfree(ue); |
1064 | } | 1120 | } |
1065 | 1121 | ||
@@ -1072,8 +1128,8 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file, | |||
1072 | long private_size; | 1128 | long private_size; |
1073 | struct user_element *ue; | 1129 | struct user_element *ue; |
1074 | int idx, err; | 1130 | int idx, err; |
1075 | 1131 | ||
1076 | if (card->user_ctl_count >= MAX_USER_CONTROLS) | 1132 | if (!replace && card->user_ctl_count >= MAX_USER_CONTROLS) |
1077 | return -ENOMEM; | 1133 | return -ENOMEM; |
1078 | if (info->count < 1) | 1134 | if (info->count < 1) |
1079 | return -EINVAL; | 1135 | return -EINVAL; |
@@ -1101,7 +1157,10 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file, | |||
1101 | memcpy(&kctl.id, &info->id, sizeof(info->id)); | 1157 | memcpy(&kctl.id, &info->id, sizeof(info->id)); |
1102 | kctl.count = info->owner ? info->owner : 1; | 1158 | kctl.count = info->owner ? info->owner : 1; |
1103 | access |= SNDRV_CTL_ELEM_ACCESS_USER; | 1159 | access |= SNDRV_CTL_ELEM_ACCESS_USER; |
1104 | kctl.info = snd_ctl_elem_user_info; | 1160 | if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) |
1161 | kctl.info = snd_ctl_elem_user_enum_info; | ||
1162 | else | ||
1163 | kctl.info = snd_ctl_elem_user_info; | ||
1105 | if (access & SNDRV_CTL_ELEM_ACCESS_READ) | 1164 | if (access & SNDRV_CTL_ELEM_ACCESS_READ) |
1106 | kctl.get = snd_ctl_elem_user_get; | 1165 | kctl.get = snd_ctl_elem_user_get; |
1107 | if (access & SNDRV_CTL_ELEM_ACCESS_WRITE) | 1166 | if (access & SNDRV_CTL_ELEM_ACCESS_WRITE) |
@@ -1122,6 +1181,11 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file, | |||
1122 | if (info->count > 64) | 1181 | if (info->count > 64) |
1123 | return -EINVAL; | 1182 | return -EINVAL; |
1124 | break; | 1183 | break; |
1184 | case SNDRV_CTL_ELEM_TYPE_ENUMERATED: | ||
1185 | private_size = sizeof(unsigned int); | ||
1186 | if (info->count > 128 || info->value.enumerated.items == 0) | ||
1187 | return -EINVAL; | ||
1188 | break; | ||
1125 | case SNDRV_CTL_ELEM_TYPE_BYTES: | 1189 | case SNDRV_CTL_ELEM_TYPE_BYTES: |
1126 | private_size = sizeof(unsigned char); | 1190 | private_size = sizeof(unsigned char); |
1127 | if (info->count > 512) | 1191 | if (info->count > 512) |
@@ -1143,9 +1207,17 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file, | |||
1143 | ue->info.access = 0; | 1207 | ue->info.access = 0; |
1144 | ue->elem_data = (char *)ue + sizeof(*ue); | 1208 | ue->elem_data = (char *)ue + sizeof(*ue); |
1145 | ue->elem_data_size = private_size; | 1209 | ue->elem_data_size = private_size; |
1210 | if (ue->info.type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) { | ||
1211 | err = snd_ctl_elem_init_enum_names(ue); | ||
1212 | if (err < 0) { | ||
1213 | kfree(ue); | ||
1214 | return err; | ||
1215 | } | ||
1216 | } | ||
1146 | kctl.private_free = snd_ctl_elem_user_free; | 1217 | kctl.private_free = snd_ctl_elem_user_free; |
1147 | _kctl = snd_ctl_new(&kctl, access); | 1218 | _kctl = snd_ctl_new(&kctl, access); |
1148 | if (_kctl == NULL) { | 1219 | if (_kctl == NULL) { |
1220 | kfree(ue->priv_data); | ||
1149 | kfree(ue); | 1221 | kfree(ue); |
1150 | return -ENOMEM; | 1222 | return -ENOMEM; |
1151 | } | 1223 | } |
diff --git a/sound/core/control_compat.c b/sound/core/control_compat.c index 426874429a5e..2bb95a7a8809 100644 --- a/sound/core/control_compat.c +++ b/sound/core/control_compat.c | |||
@@ -83,6 +83,8 @@ struct snd_ctl_elem_info32 { | |||
83 | u32 items; | 83 | u32 items; |
84 | u32 item; | 84 | u32 item; |
85 | char name[64]; | 85 | char name[64]; |
86 | u64 names_ptr; | ||
87 | u32 names_length; | ||
86 | } enumerated; | 88 | } enumerated; |
87 | unsigned char reserved[128]; | 89 | unsigned char reserved[128]; |
88 | } value; | 90 | } value; |
@@ -372,6 +374,8 @@ static int snd_ctl_elem_add_compat(struct snd_ctl_file *file, | |||
372 | &data32->value.enumerated, | 374 | &data32->value.enumerated, |
373 | sizeof(data->value.enumerated))) | 375 | sizeof(data->value.enumerated))) |
374 | goto error; | 376 | goto error; |
377 | data->value.enumerated.names_ptr = | ||
378 | (uintptr_t)compat_ptr(data->value.enumerated.names_ptr); | ||
375 | break; | 379 | break; |
376 | default: | 380 | default: |
377 | break; | 381 | break; |
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c index d8359cfeca15..1b5e0c49a0ad 100644 --- a/sound/core/oss/mixer_oss.c +++ b/sound/core/oss/mixer_oss.c | |||
@@ -499,7 +499,7 @@ static struct snd_kcontrol *snd_mixer_oss_test_id(struct snd_mixer_oss *mixer, c | |||
499 | 499 | ||
500 | memset(&id, 0, sizeof(id)); | 500 | memset(&id, 0, sizeof(id)); |
501 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | 501 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
502 | strcpy(id.name, name); | 502 | strlcpy(id.name, name, sizeof(id.name)); |
503 | id.index = index; | 503 | id.index = index; |
504 | return snd_ctl_find_id(card, &id); | 504 | return snd_ctl_find_id(card, &id); |
505 | } | 505 | } |
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 62e90b862a0d..95d1e789715f 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c | |||
@@ -1399,6 +1399,32 @@ int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime, | |||
1399 | 1399 | ||
1400 | EXPORT_SYMBOL(snd_pcm_hw_constraint_pow2); | 1400 | EXPORT_SYMBOL(snd_pcm_hw_constraint_pow2); |
1401 | 1401 | ||
1402 | static int snd_pcm_hw_rule_noresample_func(struct snd_pcm_hw_params *params, | ||
1403 | struct snd_pcm_hw_rule *rule) | ||
1404 | { | ||
1405 | unsigned int base_rate = (unsigned int)(uintptr_t)rule->private; | ||
1406 | struct snd_interval *rate; | ||
1407 | |||
1408 | rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); | ||
1409 | return snd_interval_list(rate, 1, &base_rate, 0); | ||
1410 | } | ||
1411 | |||
1412 | /** | ||
1413 | * snd_pcm_hw_rule_noresample - add a rule to allow disabling hw resampling | ||
1414 | * @runtime: PCM runtime instance | ||
1415 | * @base_rate: the rate at which the hardware does not resample | ||
1416 | */ | ||
1417 | int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime, | ||
1418 | unsigned int base_rate) | ||
1419 | { | ||
1420 | return snd_pcm_hw_rule_add(runtime, SNDRV_PCM_HW_PARAMS_NORESAMPLE, | ||
1421 | SNDRV_PCM_HW_PARAM_RATE, | ||
1422 | snd_pcm_hw_rule_noresample_func, | ||
1423 | (void *)(uintptr_t)base_rate, | ||
1424 | SNDRV_PCM_HW_PARAM_RATE, -1); | ||
1425 | } | ||
1426 | EXPORT_SYMBOL(snd_pcm_hw_rule_noresample); | ||
1427 | |||
1402 | static void _snd_pcm_hw_param_any(struct snd_pcm_hw_params *params, | 1428 | static void _snd_pcm_hw_param_any(struct snd_pcm_hw_params *params, |
1403 | snd_pcm_hw_param_t var) | 1429 | snd_pcm_hw_param_t var) |
1404 | { | 1430 | { |
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index b4bf4a4d94a9..77d7df22e7c8 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c | |||
@@ -2058,16 +2058,12 @@ EXPORT_SYMBOL(snd_pcm_open_substream); | |||
2058 | 2058 | ||
2059 | static int snd_pcm_open_file(struct file *file, | 2059 | static int snd_pcm_open_file(struct file *file, |
2060 | struct snd_pcm *pcm, | 2060 | struct snd_pcm *pcm, |
2061 | int stream, | 2061 | int stream) |
2062 | struct snd_pcm_file **rpcm_file) | ||
2063 | { | 2062 | { |
2064 | struct snd_pcm_file *pcm_file; | 2063 | struct snd_pcm_file *pcm_file; |
2065 | struct snd_pcm_substream *substream; | 2064 | struct snd_pcm_substream *substream; |
2066 | int err; | 2065 | int err; |
2067 | 2066 | ||
2068 | if (rpcm_file) | ||
2069 | *rpcm_file = NULL; | ||
2070 | |||
2071 | err = snd_pcm_open_substream(pcm, stream, file, &substream); | 2067 | err = snd_pcm_open_substream(pcm, stream, file, &substream); |
2072 | if (err < 0) | 2068 | if (err < 0) |
2073 | return err; | 2069 | return err; |
@@ -2083,8 +2079,7 @@ static int snd_pcm_open_file(struct file *file, | |||
2083 | substream->pcm_release = pcm_release_private; | 2079 | substream->pcm_release = pcm_release_private; |
2084 | } | 2080 | } |
2085 | file->private_data = pcm_file; | 2081 | file->private_data = pcm_file; |
2086 | if (rpcm_file) | 2082 | |
2087 | *rpcm_file = pcm_file; | ||
2088 | return 0; | 2083 | return 0; |
2089 | } | 2084 | } |
2090 | 2085 | ||
@@ -2113,7 +2108,6 @@ static int snd_pcm_capture_open(struct inode *inode, struct file *file) | |||
2113 | static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream) | 2108 | static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream) |
2114 | { | 2109 | { |
2115 | int err; | 2110 | int err; |
2116 | struct snd_pcm_file *pcm_file; | ||
2117 | wait_queue_t wait; | 2111 | wait_queue_t wait; |
2118 | 2112 | ||
2119 | if (pcm == NULL) { | 2113 | if (pcm == NULL) { |
@@ -2131,7 +2125,7 @@ static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream) | |||
2131 | add_wait_queue(&pcm->open_wait, &wait); | 2125 | add_wait_queue(&pcm->open_wait, &wait); |
2132 | mutex_lock(&pcm->open_mutex); | 2126 | mutex_lock(&pcm->open_mutex); |
2133 | while (1) { | 2127 | while (1) { |
2134 | err = snd_pcm_open_file(file, pcm, stream, &pcm_file); | 2128 | err = snd_pcm_open_file(file, pcm, stream); |
2135 | if (err >= 0) | 2129 | if (err >= 0) |
2136 | break; | 2130 | break; |
2137 | if (err == -EAGAIN) { | 2131 | if (err == -EAGAIN) { |
diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c index a0da7755fcea..4067f1548949 100644 --- a/sound/drivers/aloop.c +++ b/sound/drivers/aloop.c | |||
@@ -575,7 +575,8 @@ static void loopback_runtime_free(struct snd_pcm_runtime *runtime) | |||
575 | static int loopback_hw_params(struct snd_pcm_substream *substream, | 575 | static int loopback_hw_params(struct snd_pcm_substream *substream, |
576 | struct snd_pcm_hw_params *params) | 576 | struct snd_pcm_hw_params *params) |
577 | { | 577 | { |
578 | return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); | 578 | return snd_pcm_lib_alloc_vmalloc_buffer(substream, |
579 | params_buffer_bytes(params)); | ||
579 | } | 580 | } |
580 | 581 | ||
581 | static int loopback_hw_free(struct snd_pcm_substream *substream) | 582 | static int loopback_hw_free(struct snd_pcm_substream *substream) |
@@ -587,7 +588,7 @@ static int loopback_hw_free(struct snd_pcm_substream *substream) | |||
587 | mutex_lock(&dpcm->loopback->cable_lock); | 588 | mutex_lock(&dpcm->loopback->cable_lock); |
588 | cable->valid &= ~(1 << substream->stream); | 589 | cable->valid &= ~(1 << substream->stream); |
589 | mutex_unlock(&dpcm->loopback->cable_lock); | 590 | mutex_unlock(&dpcm->loopback->cable_lock); |
590 | return snd_pcm_lib_free_pages(substream); | 591 | return snd_pcm_lib_free_vmalloc_buffer(substream); |
591 | } | 592 | } |
592 | 593 | ||
593 | static unsigned int get_cable_index(struct snd_pcm_substream *substream) | 594 | static unsigned int get_cable_index(struct snd_pcm_substream *substream) |
@@ -740,6 +741,8 @@ static struct snd_pcm_ops loopback_playback_ops = { | |||
740 | .prepare = loopback_prepare, | 741 | .prepare = loopback_prepare, |
741 | .trigger = loopback_trigger, | 742 | .trigger = loopback_trigger, |
742 | .pointer = loopback_pointer, | 743 | .pointer = loopback_pointer, |
744 | .page = snd_pcm_lib_get_vmalloc_page, | ||
745 | .mmap = snd_pcm_lib_mmap_vmalloc, | ||
743 | }; | 746 | }; |
744 | 747 | ||
745 | static struct snd_pcm_ops loopback_capture_ops = { | 748 | static struct snd_pcm_ops loopback_capture_ops = { |
@@ -751,6 +754,8 @@ static struct snd_pcm_ops loopback_capture_ops = { | |||
751 | .prepare = loopback_prepare, | 754 | .prepare = loopback_prepare, |
752 | .trigger = loopback_trigger, | 755 | .trigger = loopback_trigger, |
753 | .pointer = loopback_pointer, | 756 | .pointer = loopback_pointer, |
757 | .page = snd_pcm_lib_get_vmalloc_page, | ||
758 | .mmap = snd_pcm_lib_mmap_vmalloc, | ||
754 | }; | 759 | }; |
755 | 760 | ||
756 | static int __devinit loopback_pcm_new(struct loopback *loopback, | 761 | static int __devinit loopback_pcm_new(struct loopback *loopback, |
@@ -771,10 +776,6 @@ static int __devinit loopback_pcm_new(struct loopback *loopback, | |||
771 | strcpy(pcm->name, "Loopback PCM"); | 776 | strcpy(pcm->name, "Loopback PCM"); |
772 | 777 | ||
773 | loopback->pcm[device] = pcm; | 778 | loopback->pcm[device] = pcm; |
774 | |||
775 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, | ||
776 | snd_dma_continuous_data(GFP_KERNEL), | ||
777 | 0, 2 * 1024 * 1024); | ||
778 | return 0; | 779 | return 0; |
779 | } | 780 | } |
780 | 781 | ||
diff --git a/sound/drivers/mpu401/mpu401.c b/sound/drivers/mpu401/mpu401.c index 149d05a8202d..1c02852aceea 100644 --- a/sound/drivers/mpu401/mpu401.c +++ b/sound/drivers/mpu401/mpu401.c | |||
@@ -86,8 +86,7 @@ static int snd_mpu401_create(int dev, struct snd_card **rcard) | |||
86 | } | 86 | } |
87 | 87 | ||
88 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port[dev], 0, | 88 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port[dev], 0, |
89 | irq[dev], irq[dev] >= 0 ? IRQF_DISABLED : 0, | 89 | irq[dev], NULL); |
90 | NULL); | ||
91 | if (err < 0) { | 90 | if (err < 0) { |
92 | printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]); | 91 | printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]); |
93 | goto _err; | 92 | goto _err; |
diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c index 2af09996a3d0..9d01c181feca 100644 --- a/sound/drivers/mpu401/mpu401_uart.c +++ b/sound/drivers/mpu401/mpu401_uart.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * Routines for control of MPU-401 in UART mode | 3 | * Routines for control of MPU-401 in UART mode |
4 | * | 4 | * |
5 | * MPU-401 supports UART mode which is not capable generate transmit | 5 | * MPU-401 supports UART mode which is not capable generate transmit |
6 | * interrupts thus output is done via polling. Also, if irq < 0, then | 6 | * interrupts thus output is done via polling. Without interrupt, |
7 | * input is done also via polling. Do not expect good performance. | 7 | * input is done also via polling. Do not expect good performance. |
8 | * | 8 | * |
9 | * | 9 | * |
@@ -374,7 +374,7 @@ snd_mpu401_uart_input_trigger(struct snd_rawmidi_substream *substream, int up) | |||
374 | /* first time - flush FIFO */ | 374 | /* first time - flush FIFO */ |
375 | while (max-- > 0) | 375 | while (max-- > 0) |
376 | mpu->read(mpu, MPU401D(mpu)); | 376 | mpu->read(mpu, MPU401D(mpu)); |
377 | if (mpu->irq < 0) | 377 | if (mpu->info_flags & MPU401_INFO_USE_TIMER) |
378 | snd_mpu401_uart_add_timer(mpu, 1); | 378 | snd_mpu401_uart_add_timer(mpu, 1); |
379 | } | 379 | } |
380 | 380 | ||
@@ -383,7 +383,7 @@ snd_mpu401_uart_input_trigger(struct snd_rawmidi_substream *substream, int up) | |||
383 | snd_mpu401_uart_input_read(mpu); | 383 | snd_mpu401_uart_input_read(mpu); |
384 | spin_unlock_irqrestore(&mpu->input_lock, flags); | 384 | spin_unlock_irqrestore(&mpu->input_lock, flags); |
385 | } else { | 385 | } else { |
386 | if (mpu->irq < 0) | 386 | if (mpu->info_flags & MPU401_INFO_USE_TIMER) |
387 | snd_mpu401_uart_remove_timer(mpu, 1); | 387 | snd_mpu401_uart_remove_timer(mpu, 1); |
388 | clear_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode); | 388 | clear_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode); |
389 | } | 389 | } |
@@ -496,7 +496,7 @@ static struct snd_rawmidi_ops snd_mpu401_uart_input = | |||
496 | static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi) | 496 | static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi) |
497 | { | 497 | { |
498 | struct snd_mpu401 *mpu = rmidi->private_data; | 498 | struct snd_mpu401 *mpu = rmidi->private_data; |
499 | if (mpu->irq_flags && mpu->irq >= 0) | 499 | if (mpu->irq >= 0) |
500 | free_irq(mpu->irq, (void *) mpu); | 500 | free_irq(mpu->irq, (void *) mpu); |
501 | release_and_free_resource(mpu->res); | 501 | release_and_free_resource(mpu->res); |
502 | kfree(mpu); | 502 | kfree(mpu); |
@@ -509,8 +509,7 @@ static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi) | |||
509 | * @hardware: the hardware type, MPU401_HW_XXXX | 509 | * @hardware: the hardware type, MPU401_HW_XXXX |
510 | * @port: the base address of MPU401 port | 510 | * @port: the base address of MPU401 port |
511 | * @info_flags: bitflags MPU401_INFO_XXX | 511 | * @info_flags: bitflags MPU401_INFO_XXX |
512 | * @irq: the irq number, -1 if no interrupt for mpu | 512 | * @irq: the ISA irq number, -1 if not to be allocated |
513 | * @irq_flags: the irq request flags (SA_XXX), 0 if irq was already reserved. | ||
514 | * @rrawmidi: the pointer to store the new rawmidi instance | 513 | * @rrawmidi: the pointer to store the new rawmidi instance |
515 | * | 514 | * |
516 | * Creates a new MPU-401 instance. | 515 | * Creates a new MPU-401 instance. |
@@ -525,7 +524,7 @@ int snd_mpu401_uart_new(struct snd_card *card, int device, | |||
525 | unsigned short hardware, | 524 | unsigned short hardware, |
526 | unsigned long port, | 525 | unsigned long port, |
527 | unsigned int info_flags, | 526 | unsigned int info_flags, |
528 | int irq, int irq_flags, | 527 | int irq, |
529 | struct snd_rawmidi ** rrawmidi) | 528 | struct snd_rawmidi ** rrawmidi) |
530 | { | 529 | { |
531 | struct snd_mpu401 *mpu; | 530 | struct snd_mpu401 *mpu; |
@@ -577,8 +576,8 @@ int snd_mpu401_uart_new(struct snd_card *card, int device, | |||
577 | mpu->cport = port + 2; | 576 | mpu->cport = port + 2; |
578 | else | 577 | else |
579 | mpu->cport = port + 1; | 578 | mpu->cport = port + 1; |
580 | if (irq >= 0 && irq_flags) { | 579 | if (irq >= 0) { |
581 | if (request_irq(irq, snd_mpu401_uart_interrupt, irq_flags, | 580 | if (request_irq(irq, snd_mpu401_uart_interrupt, IRQF_DISABLED, |
582 | "MPU401 UART", (void *) mpu)) { | 581 | "MPU401 UART", (void *) mpu)) { |
583 | snd_printk(KERN_ERR "mpu401_uart: " | 582 | snd_printk(KERN_ERR "mpu401_uart: " |
584 | "unable to grab IRQ %d\n", irq); | 583 | "unable to grab IRQ %d\n", irq); |
@@ -586,9 +585,10 @@ int snd_mpu401_uart_new(struct snd_card *card, int device, | |||
586 | return -EBUSY; | 585 | return -EBUSY; |
587 | } | 586 | } |
588 | } | 587 | } |
588 | if (irq < 0 && !(info_flags & MPU401_INFO_IRQ_HOOK)) | ||
589 | info_flags |= MPU401_INFO_USE_TIMER; | ||
589 | mpu->info_flags = info_flags; | 590 | mpu->info_flags = info_flags; |
590 | mpu->irq = irq; | 591 | mpu->irq = irq; |
591 | mpu->irq_flags = irq_flags; | ||
592 | if (card->shortname[0]) | 592 | if (card->shortname[0]) |
593 | snprintf(rmidi->name, sizeof(rmidi->name), "%s MIDI", | 593 | snprintf(rmidi->name, sizeof(rmidi->name), "%s MIDI", |
594 | card->shortname); | 594 | card->shortname); |
diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c index 440030818db7..cd094ecaca3b 100644 --- a/sound/firewire/isight.c +++ b/sound/firewire/isight.c | |||
@@ -51,7 +51,6 @@ struct isight { | |||
51 | struct fw_unit *unit; | 51 | struct fw_unit *unit; |
52 | struct fw_device *device; | 52 | struct fw_device *device; |
53 | u64 audio_base; | 53 | u64 audio_base; |
54 | struct fw_address_handler iris_handler; | ||
55 | struct snd_pcm_substream *pcm; | 54 | struct snd_pcm_substream *pcm; |
56 | struct mutex mutex; | 55 | struct mutex mutex; |
57 | struct iso_packets_buffer buffer; | 56 | struct iso_packets_buffer buffer; |
diff --git a/sound/firewire/speakers.c b/sound/firewire/speakers.c index 3fc257da180c..cbe6bb9e53b6 100644 --- a/sound/firewire/speakers.c +++ b/sound/firewire/speakers.c | |||
@@ -778,9 +778,10 @@ static int __devexit fwspk_remove(struct device *dev) | |||
778 | { | 778 | { |
779 | struct fwspk *fwspk = dev_get_drvdata(dev); | 779 | struct fwspk *fwspk = dev_get_drvdata(dev); |
780 | 780 | ||
781 | mutex_lock(&fwspk->mutex); | ||
782 | amdtp_out_stream_pcm_abort(&fwspk->stream); | 781 | amdtp_out_stream_pcm_abort(&fwspk->stream); |
783 | snd_card_disconnect(fwspk->card); | 782 | snd_card_disconnect(fwspk->card); |
783 | |||
784 | mutex_lock(&fwspk->mutex); | ||
784 | fwspk_stop_stream(fwspk); | 785 | fwspk_stop_stream(fwspk); |
785 | mutex_unlock(&fwspk->mutex); | 786 | mutex_unlock(&fwspk->mutex); |
786 | 787 | ||
@@ -796,8 +797,8 @@ static void fwspk_bus_reset(struct fw_unit *unit) | |||
796 | fcp_bus_reset(fwspk->unit); | 797 | fcp_bus_reset(fwspk->unit); |
797 | 798 | ||
798 | if (cmp_connection_update(&fwspk->connection) < 0) { | 799 | if (cmp_connection_update(&fwspk->connection) < 0) { |
799 | mutex_lock(&fwspk->mutex); | ||
800 | amdtp_out_stream_pcm_abort(&fwspk->stream); | 800 | amdtp_out_stream_pcm_abort(&fwspk->stream); |
801 | mutex_lock(&fwspk->mutex); | ||
801 | fwspk_stop_stream(fwspk); | 802 | fwspk_stop_stream(fwspk); |
802 | mutex_unlock(&fwspk->mutex); | 803 | mutex_unlock(&fwspk->mutex); |
803 | return; | 804 | return; |
diff --git a/sound/isa/ad1816a/ad1816a.c b/sound/isa/ad1816a/ad1816a.c index 3cb75bc97699..a87a2b566e19 100644 --- a/sound/isa/ad1816a/ad1816a.c +++ b/sound/isa/ad1816a/ad1816a.c | |||
@@ -204,7 +204,7 @@ static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard | |||
204 | 204 | ||
205 | if (mpu_port[dev] > 0) { | 205 | if (mpu_port[dev] > 0) { |
206 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, | 206 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, |
207 | mpu_port[dev], 0, mpu_irq[dev], IRQF_DISABLED, | 207 | mpu_port[dev], 0, mpu_irq[dev], |
208 | NULL) < 0) | 208 | NULL) < 0) |
209 | printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]); | 209 | printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]); |
210 | } | 210 | } |
diff --git a/sound/isa/als100.c b/sound/isa/als100.c index 20becc89f6f6..706effd6b3cd 100644 --- a/sound/isa/als100.c +++ b/sound/isa/als100.c | |||
@@ -256,7 +256,6 @@ static int __devinit snd_card_als100_probe(int dev, | |||
256 | mpu_type, | 256 | mpu_type, |
257 | mpu_port[dev], 0, | 257 | mpu_port[dev], 0, |
258 | mpu_irq[dev], | 258 | mpu_irq[dev], |
259 | mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, | ||
260 | NULL) < 0) | 259 | NULL) < 0) |
261 | snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]); | 260 | snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]); |
262 | } | 261 | } |
diff --git a/sound/isa/azt2320.c b/sound/isa/azt2320.c index aac8dc15c2fe..b7bdbf307740 100644 --- a/sound/isa/azt2320.c +++ b/sound/isa/azt2320.c | |||
@@ -234,8 +234,7 @@ static int __devinit snd_card_azt2320_probe(int dev, | |||
234 | if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { | 234 | if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { |
235 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_AZT2320, | 235 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_AZT2320, |
236 | mpu_port[dev], 0, | 236 | mpu_port[dev], 0, |
237 | mpu_irq[dev], IRQF_DISABLED, | 237 | mpu_irq[dev], NULL) < 0) |
238 | NULL) < 0) | ||
239 | snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]); | 238 | snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]); |
240 | } | 239 | } |
241 | 240 | ||
diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c index fe79a169acb5..dca69f80305f 100644 --- a/sound/isa/cmi8330.c +++ b/sound/isa/cmi8330.c | |||
@@ -597,7 +597,7 @@ static int __devinit snd_cmi8330_probe(struct snd_card *card, int dev) | |||
597 | if (mpuport[dev] != SNDRV_AUTO_PORT) { | 597 | if (mpuport[dev] != SNDRV_AUTO_PORT) { |
598 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, | 598 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, |
599 | mpuport[dev], 0, mpuirq[dev], | 599 | mpuport[dev], 0, mpuirq[dev], |
600 | IRQF_DISABLED, NULL) < 0) | 600 | NULL) < 0) |
601 | printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", | 601 | printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", |
602 | mpuport[dev]); | 602 | mpuport[dev]); |
603 | } | 603 | } |
diff --git a/sound/isa/cs423x/cs4231.c b/sound/isa/cs423x/cs4231.c index cb9153e75b82..409fa0ad7843 100644 --- a/sound/isa/cs423x/cs4231.c +++ b/sound/isa/cs423x/cs4231.c | |||
@@ -131,7 +131,6 @@ static int __devinit snd_cs4231_probe(struct device *dev, unsigned int n) | |||
131 | mpu_irq[n] = -1; | 131 | mpu_irq[n] = -1; |
132 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232, | 132 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232, |
133 | mpu_port[n], 0, mpu_irq[n], | 133 | mpu_port[n], 0, mpu_irq[n], |
134 | mpu_irq[n] >= 0 ? IRQF_DISABLED : 0, | ||
135 | NULL) < 0) | 134 | NULL) < 0) |
136 | dev_warn(dev, "MPU401 not detected\n"); | 135 | dev_warn(dev, "MPU401 not detected\n"); |
137 | } | 136 | } |
diff --git a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c index 999dc1e0fdbd..0dbde461e6c1 100644 --- a/sound/isa/cs423x/cs4236.c +++ b/sound/isa/cs423x/cs4236.c | |||
@@ -449,8 +449,7 @@ static int __devinit snd_cs423x_probe(struct snd_card *card, int dev) | |||
449 | mpu_irq[dev] = -1; | 449 | mpu_irq[dev] = -1; |
450 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232, | 450 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232, |
451 | mpu_port[dev], 0, | 451 | mpu_port[dev], 0, |
452 | mpu_irq[dev], | 452 | mpu_irq[dev], NULL) < 0) |
453 | mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, NULL) < 0) | ||
454 | printk(KERN_WARNING IDENT ": MPU401 not detected\n"); | 453 | printk(KERN_WARNING IDENT ": MPU401 not detected\n"); |
455 | } | 454 | } |
456 | 455 | ||
diff --git a/sound/isa/es1688/es1688.c b/sound/isa/es1688/es1688.c index 0cde8131a575..5493e9e4bcd5 100644 --- a/sound/isa/es1688/es1688.c +++ b/sound/isa/es1688/es1688.c | |||
@@ -174,7 +174,7 @@ static int __devinit snd_es1688_probe(struct snd_card *card, unsigned int n) | |||
174 | chip->mpu_port > 0) { | 174 | chip->mpu_port > 0) { |
175 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, | 175 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, |
176 | chip->mpu_port, 0, | 176 | chip->mpu_port, 0, |
177 | mpu_irq[n], IRQF_DISABLED, NULL); | 177 | mpu_irq[n], NULL); |
178 | if (error < 0) | 178 | if (error < 0) |
179 | return error; | 179 | return error; |
180 | } | 180 | } |
diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c index fb4d6b34bbca..aeee8f8bf5e9 100644 --- a/sound/isa/es18xx.c +++ b/sound/isa/es18xx.c | |||
@@ -2160,8 +2160,8 @@ static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev) | |||
2160 | 2160 | ||
2161 | if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { | 2161 | if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { |
2162 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX, | 2162 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX, |
2163 | mpu_port[dev], 0, | 2163 | mpu_port[dev], MPU401_INFO_IRQ_HOOK, |
2164 | irq[dev], 0, &chip->rmidi); | 2164 | -1, &chip->rmidi); |
2165 | if (err < 0) | 2165 | if (err < 0) |
2166 | return err; | 2166 | return err; |
2167 | } | 2167 | } |
diff --git a/sound/isa/galaxy/galaxy.c b/sound/isa/galaxy/galaxy.c index ee54df082b9c..e51d3244742a 100644 --- a/sound/isa/galaxy/galaxy.c +++ b/sound/isa/galaxy/galaxy.c | |||
@@ -585,8 +585,7 @@ static int __devinit snd_galaxy_probe(struct device *dev, unsigned int n) | |||
585 | 585 | ||
586 | if (mpu_port[n] >= 0) { | 586 | if (mpu_port[n] >= 0) { |
587 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, | 587 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, |
588 | mpu_port[n], 0, mpu_irq[n], | 588 | mpu_port[n], 0, mpu_irq[n], NULL); |
589 | IRQF_DISABLED, NULL); | ||
590 | if (err < 0) | 589 | if (err < 0) |
591 | goto error; | 590 | goto error; |
592 | } | 591 | } |
diff --git a/sound/isa/gus/gusextreme.c b/sound/isa/gus/gusextreme.c index 008e8e5bfa37..c4733c08b60b 100644 --- a/sound/isa/gus/gusextreme.c +++ b/sound/isa/gus/gusextreme.c | |||
@@ -317,8 +317,7 @@ static int __devinit snd_gusextreme_probe(struct device *dev, unsigned int n) | |||
317 | 317 | ||
318 | if (es1688->mpu_port >= 0x300) { | 318 | if (es1688->mpu_port >= 0x300) { |
319 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, | 319 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, |
320 | es1688->mpu_port, 0, | 320 | es1688->mpu_port, 0, mpu_irq[n], NULL); |
321 | mpu_irq[n], IRQF_DISABLED, NULL); | ||
322 | if (error < 0) | 321 | if (error < 0) |
323 | goto out; | 322 | goto out; |
324 | } | 323 | } |
diff --git a/sound/isa/msnd/msnd_pinnacle.c b/sound/isa/msnd/msnd_pinnacle.c index 91d6023a63e5..0961e2cf20ca 100644 --- a/sound/isa/msnd/msnd_pinnacle.c +++ b/sound/isa/msnd/msnd_pinnacle.c | |||
@@ -600,7 +600,7 @@ static int __devinit snd_msnd_attach(struct snd_card *card) | |||
600 | mpu_io[0], | 600 | mpu_io[0], |
601 | MPU401_MODE_INPUT | | 601 | MPU401_MODE_INPUT | |
602 | MPU401_MODE_OUTPUT, | 602 | MPU401_MODE_OUTPUT, |
603 | mpu_irq[0], IRQF_DISABLED, | 603 | mpu_irq[0], |
604 | &chip->rmidi); | 604 | &chip->rmidi); |
605 | if (err < 0) { | 605 | if (err < 0) { |
606 | printk(KERN_ERR LOGNAME | 606 | printk(KERN_ERR LOGNAME |
diff --git a/sound/isa/opl3sa2.c b/sound/isa/opl3sa2.c index 9b915e27b5bd..de99f47770bf 100644 --- a/sound/isa/opl3sa2.c +++ b/sound/isa/opl3sa2.c | |||
@@ -707,8 +707,9 @@ static int __devinit snd_opl3sa2_probe(struct snd_card *card, int dev) | |||
707 | } | 707 | } |
708 | if (midi_port[dev] >= 0x300 && midi_port[dev] < 0x340) { | 708 | if (midi_port[dev] >= 0x300 && midi_port[dev] < 0x340) { |
709 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_OPL3SA2, | 709 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_OPL3SA2, |
710 | midi_port[dev], 0, | 710 | midi_port[dev], |
711 | xirq, 0, &chip->rmidi)) < 0) | 711 | MPU401_INFO_IRQ_HOOK, -1, |
712 | &chip->rmidi)) < 0) | ||
712 | return err; | 713 | return err; |
713 | } | 714 | } |
714 | sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", | 715 | sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", |
diff --git a/sound/isa/opti9xx/miro.c b/sound/isa/opti9xx/miro.c index 8c24102d0d93..d94d0f35cb76 100644 --- a/sound/isa/opti9xx/miro.c +++ b/sound/isa/opti9xx/miro.c | |||
@@ -1377,8 +1377,7 @@ static int __devinit snd_miro_probe(struct snd_card *card) | |||
1377 | rmidi = NULL; | 1377 | rmidi = NULL; |
1378 | else { | 1378 | else { |
1379 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, | 1379 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, |
1380 | mpu_port, 0, miro->mpu_irq, IRQF_DISABLED, | 1380 | mpu_port, 0, miro->mpu_irq, &rmidi); |
1381 | &rmidi); | ||
1382 | if (error < 0) | 1381 | if (error < 0) |
1383 | snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", | 1382 | snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", |
1384 | mpu_port); | 1383 | mpu_port); |
diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c index c35dc68930dc..346e12baa98e 100644 --- a/sound/isa/opti9xx/opti92x-ad1848.c +++ b/sound/isa/opti9xx/opti92x-ad1848.c | |||
@@ -914,7 +914,7 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card) | |||
914 | rmidi = NULL; | 914 | rmidi = NULL; |
915 | else { | 915 | else { |
916 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, | 916 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, |
917 | mpu_port, 0, mpu_irq, IRQF_DISABLED, &rmidi); | 917 | mpu_port, 0, mpu_irq, &rmidi); |
918 | if (error) | 918 | if (error) |
919 | snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", | 919 | snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", |
920 | mpu_port); | 920 | mpu_port); |
diff --git a/sound/isa/sb/jazz16.c b/sound/isa/sb/jazz16.c index 8ccbcddf08e1..54e3c2c18060 100644 --- a/sound/isa/sb/jazz16.c +++ b/sound/isa/sb/jazz16.c | |||
@@ -322,7 +322,6 @@ static int __devinit snd_jazz16_probe(struct device *devptr, unsigned int dev) | |||
322 | MPU401_HW_MPU401, | 322 | MPU401_HW_MPU401, |
323 | mpu_port[dev], 0, | 323 | mpu_port[dev], 0, |
324 | mpu_irq[dev], | 324 | mpu_irq[dev], |
325 | mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, | ||
326 | NULL) < 0) | 325 | NULL) < 0) |
327 | snd_printk(KERN_ERR "no MPU-401 device at 0x%lx\n", | 326 | snd_printk(KERN_ERR "no MPU-401 device at 0x%lx\n", |
328 | mpu_port[dev]); | 327 | mpu_port[dev]); |
diff --git a/sound/isa/sb/sb16.c b/sound/isa/sb/sb16.c index 4d1c5a300ff8..237f8bd7fbe4 100644 --- a/sound/isa/sb/sb16.c +++ b/sound/isa/sb/sb16.c | |||
@@ -394,8 +394,9 @@ static int __devinit snd_sb16_probe(struct snd_card *card, int dev) | |||
394 | 394 | ||
395 | if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) { | 395 | if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) { |
396 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SB, | 396 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SB, |
397 | chip->mpu_port, 0, | 397 | chip->mpu_port, |
398 | xirq, 0, &chip->rmidi)) < 0) | 398 | MPU401_INFO_IRQ_HOOK, -1, |
399 | &chip->rmidi)) < 0) | ||
399 | return err; | 400 | return err; |
400 | chip->rmidi_callback = snd_mpu401_uart_interrupt; | 401 | chip->rmidi_callback = snd_mpu401_uart_interrupt; |
401 | } | 402 | } |
diff --git a/sound/isa/sc6000.c b/sound/isa/sc6000.c index 9a8bbf6dd62a..207c161f100c 100644 --- a/sound/isa/sc6000.c +++ b/sound/isa/sc6000.c | |||
@@ -658,8 +658,7 @@ static int __devinit snd_sc6000_probe(struct device *devptr, unsigned int dev) | |||
658 | if (snd_mpu401_uart_new(card, 0, | 658 | if (snd_mpu401_uart_new(card, 0, |
659 | MPU401_HW_MPU401, | 659 | MPU401_HW_MPU401, |
660 | mpu_port[dev], 0, | 660 | mpu_port[dev], 0, |
661 | mpu_irq[dev], IRQF_DISABLED, | 661 | mpu_irq[dev], NULL) < 0) |
662 | NULL) < 0) | ||
663 | snd_printk(KERN_ERR "no MPU-401 device at 0x%lx ?\n", | 662 | snd_printk(KERN_ERR "no MPU-401 device at 0x%lx ?\n", |
664 | mpu_port[dev]); | 663 | mpu_port[dev]); |
665 | } | 664 | } |
diff --git a/sound/isa/sscape.c b/sound/isa/sscape.c index e2d5d2d3ed96..f2379e102b63 100644 --- a/sound/isa/sscape.c +++ b/sound/isa/sscape.c | |||
@@ -825,8 +825,7 @@ static int __devinit create_mpu401(struct snd_card *card, int devnum, | |||
825 | int err; | 825 | int err; |
826 | 826 | ||
827 | err = snd_mpu401_uart_new(card, devnum, MPU401_HW_MPU401, port, | 827 | err = snd_mpu401_uart_new(card, devnum, MPU401_HW_MPU401, port, |
828 | MPU401_INFO_INTEGRATED, irq, IRQF_DISABLED, | 828 | MPU401_INFO_INTEGRATED, irq, &rawmidi); |
829 | &rawmidi); | ||
830 | if (err == 0) { | 829 | if (err == 0) { |
831 | struct snd_mpu401 *mpu = rawmidi->private_data; | 830 | struct snd_mpu401 *mpu = rawmidi->private_data; |
832 | mpu->open_input = mpu401_open; | 831 | mpu->open_input = mpu401_open; |
diff --git a/sound/isa/wavefront/wavefront.c b/sound/isa/wavefront/wavefront.c index 711670e4a425..83f291d89a95 100644 --- a/sound/isa/wavefront/wavefront.c +++ b/sound/isa/wavefront/wavefront.c | |||
@@ -449,8 +449,7 @@ snd_wavefront_probe (struct snd_card *card, int dev) | |||
449 | if (cs4232_mpu_port[dev] > 0 && cs4232_mpu_port[dev] != SNDRV_AUTO_PORT) { | 449 | if (cs4232_mpu_port[dev] > 0 && cs4232_mpu_port[dev] != SNDRV_AUTO_PORT) { |
450 | err = snd_mpu401_uart_new(card, midi_dev, MPU401_HW_CS4232, | 450 | err = snd_mpu401_uart_new(card, midi_dev, MPU401_HW_CS4232, |
451 | cs4232_mpu_port[dev], 0, | 451 | cs4232_mpu_port[dev], 0, |
452 | cs4232_mpu_irq[dev], IRQF_DISABLED, | 452 | cs4232_mpu_irq[dev], NULL); |
453 | NULL); | ||
454 | if (err < 0) { | 453 | if (err < 0) { |
455 | snd_printk (KERN_ERR "can't allocate CS4232 MPU-401 device\n"); | 454 | snd_printk (KERN_ERR "can't allocate CS4232 MPU-401 device\n"); |
456 | return err; | 455 | return err; |
diff --git a/sound/oss/sound_timer.c b/sound/oss/sound_timer.c index 48cda6c4c257..8021c85f076d 100644 --- a/sound/oss/sound_timer.c +++ b/sound/oss/sound_timer.c | |||
@@ -320,7 +320,7 @@ void sound_timer_init(struct sound_lowlev_timer *t, char *name) | |||
320 | n = sound_alloc_timerdev(); | 320 | n = sound_alloc_timerdev(); |
321 | if (n == -1) | 321 | if (n == -1) |
322 | n = 0; /* Overwrite the system timer */ | 322 | n = 0; /* Overwrite the system timer */ |
323 | strcpy(sound_timer.info.name, name); | 323 | strlcpy(sound_timer.info.name, name, sizeof(sound_timer.info.name)); |
324 | sound_timer_devs[n] = &sound_timer; | 324 | sound_timer_devs[n] = &sound_timer; |
325 | } | 325 | } |
326 | EXPORT_SYMBOL(sound_timer_init); | 326 | EXPORT_SYMBOL(sound_timer_init); |
diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c index a9c1af33f276..04628696eb08 100644 --- a/sound/pci/als4000.c +++ b/sound/pci/als4000.c | |||
@@ -931,8 +931,9 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci, | |||
931 | 931 | ||
932 | if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000, | 932 | if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000, |
933 | iobase + ALS4K_IOB_30_MIDI_DATA, | 933 | iobase + ALS4K_IOB_30_MIDI_DATA, |
934 | MPU401_INFO_INTEGRATED, | 934 | MPU401_INFO_INTEGRATED | |
935 | pci->irq, 0, &chip->rmidi)) < 0) { | 935 | MPU401_INFO_IRQ_HOOK, |
936 | -1, &chip->rmidi)) < 0) { | ||
936 | printk(KERN_ERR "als4000: no MPU-401 device at 0x%lx?\n", | 937 | printk(KERN_ERR "als4000: no MPU-401 device at 0x%lx?\n", |
937 | iobase + ALS4K_IOB_30_MIDI_DATA); | 938 | iobase + ALS4K_IOB_30_MIDI_DATA); |
938 | goto out_err; | 939 | goto out_err; |
diff --git a/sound/pci/au88x0/au88x0_mpu401.c b/sound/pci/au88x0/au88x0_mpu401.c index 0dc8d259d1ed..e6c6a0febb75 100644 --- a/sound/pci/au88x0/au88x0_mpu401.c +++ b/sound/pci/au88x0/au88x0_mpu401.c | |||
@@ -84,7 +84,7 @@ static int __devinit snd_vortex_midi(vortex_t * vortex) | |||
84 | #ifdef VORTEX_MPU401_LEGACY | 84 | #ifdef VORTEX_MPU401_LEGACY |
85 | if ((temp = | 85 | if ((temp = |
86 | snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_MPU401, 0x330, | 86 | snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_MPU401, 0x330, |
87 | 0, 0, 0, &rmidi)) != 0) { | 87 | MPU401_INFO_IRQ_HOOK, -1, &rmidi)) != 0) { |
88 | hwwrite(vortex->mmio, VORTEX_CTRL, | 88 | hwwrite(vortex->mmio, VORTEX_CTRL, |
89 | (hwread(vortex->mmio, VORTEX_CTRL) & | 89 | (hwread(vortex->mmio, VORTEX_CTRL) & |
90 | ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN); | 90 | ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN); |
@@ -94,8 +94,8 @@ static int __devinit snd_vortex_midi(vortex_t * vortex) | |||
94 | port = (unsigned long)(vortex->mmio + VORTEX_MIDI_DATA); | 94 | port = (unsigned long)(vortex->mmio + VORTEX_MIDI_DATA); |
95 | if ((temp = | 95 | if ((temp = |
96 | snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_AUREAL, port, | 96 | snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_AUREAL, port, |
97 | MPU401_INFO_INTEGRATED | MPU401_INFO_MMIO, | 97 | MPU401_INFO_INTEGRATED | MPU401_INFO_MMIO | |
98 | 0, 0, &rmidi)) != 0) { | 98 | MPU401_INFO_IRQ_HOOK, -1, &rmidi)) != 0) { |
99 | hwwrite(vortex->mmio, VORTEX_CTRL, | 99 | hwwrite(vortex->mmio, VORTEX_CTRL, |
100 | (hwread(vortex->mmio, VORTEX_CTRL) & | 100 | (hwread(vortex->mmio, VORTEX_CTRL) & |
101 | ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN); | 101 | ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN); |
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c index 579fc0dce128..d24fe425e87f 100644 --- a/sound/pci/azt3328.c +++ b/sound/pci/azt3328.c | |||
@@ -2652,8 +2652,9 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) | |||
2652 | since our hardware ought to be similar, thus use same ID. */ | 2652 | since our hardware ought to be similar, thus use same ID. */ |
2653 | err = snd_mpu401_uart_new( | 2653 | err = snd_mpu401_uart_new( |
2654 | card, 0, | 2654 | card, 0, |
2655 | MPU401_HW_AZT2320, chip->mpu_io, MPU401_INFO_INTEGRATED, | 2655 | MPU401_HW_AZT2320, chip->mpu_io, |
2656 | pci->irq, 0, &chip->rmidi | 2656 | MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, |
2657 | -1, &chip->rmidi | ||
2657 | ); | 2658 | ); |
2658 | if (err < 0) { | 2659 | if (err < 0) { |
2659 | snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n", | 2660 | snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n", |
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c index 9cf99fb7eb9c..da9c73211eca 100644 --- a/sound/pci/cmipci.c +++ b/sound/pci/cmipci.c | |||
@@ -3228,8 +3228,9 @@ static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pc | |||
3228 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI, | 3228 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI, |
3229 | iomidi, | 3229 | iomidi, |
3230 | (integrated_midi ? | 3230 | (integrated_midi ? |
3231 | MPU401_INFO_INTEGRATED : 0), | 3231 | MPU401_INFO_INTEGRATED : 0) | |
3232 | cm->irq, 0, &cm->rmidi)) < 0) { | 3232 | MPU401_INFO_IRQ_HOOK, |
3233 | -1, &cm->rmidi)) < 0) { | ||
3233 | printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi); | 3234 | printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi); |
3234 | } | 3235 | } |
3235 | } | 3236 | } |
diff --git a/sound/pci/ctxfi/ctpcm.c b/sound/pci/ctxfi/ctpcm.c index 457d21189b0d..2c8622617c8c 100644 --- a/sound/pci/ctxfi/ctpcm.c +++ b/sound/pci/ctxfi/ctpcm.c | |||
@@ -404,7 +404,7 @@ int ct_alsa_pcm_create(struct ct_atc *atc, | |||
404 | int err; | 404 | int err; |
405 | int playback_count, capture_count; | 405 | int playback_count, capture_count; |
406 | 406 | ||
407 | playback_count = (IEC958 == device) ? 1 : 8; | 407 | playback_count = (IEC958 == device) ? 1 : 256; |
408 | capture_count = (FRONT == device) ? 1 : 0; | 408 | capture_count = (FRONT == device) ? 1 : 0; |
409 | err = snd_pcm_new(atc->card, "ctxfi", device, | 409 | err = snd_pcm_new(atc->card, "ctxfi", device, |
410 | playback_count, capture_count, &pcm); | 410 | playback_count, capture_count, &pcm); |
diff --git a/sound/pci/ctxfi/ctsrc.c b/sound/pci/ctxfi/ctsrc.c index c749fa720889..e134b3a5780d 100644 --- a/sound/pci/ctxfi/ctsrc.c +++ b/sound/pci/ctxfi/ctsrc.c | |||
@@ -20,7 +20,7 @@ | |||
20 | #include "cthardware.h" | 20 | #include "cthardware.h" |
21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
22 | 22 | ||
23 | #define SRC_RESOURCE_NUM 64 | 23 | #define SRC_RESOURCE_NUM 256 |
24 | #define SRCIMP_RESOURCE_NUM 256 | 24 | #define SRCIMP_RESOURCE_NUM 256 |
25 | 25 | ||
26 | static unsigned int conj_mask; | 26 | static unsigned int conj_mask; |
diff --git a/sound/pci/ctxfi/ctvmem.h b/sound/pci/ctxfi/ctvmem.h index b23adfca4de6..e6da60eb19ce 100644 --- a/sound/pci/ctxfi/ctvmem.h +++ b/sound/pci/ctxfi/ctvmem.h | |||
@@ -18,7 +18,7 @@ | |||
18 | #ifndef CTVMEM_H | 18 | #ifndef CTVMEM_H |
19 | #define CTVMEM_H | 19 | #define CTVMEM_H |
20 | 20 | ||
21 | #define CT_PTP_NUM 1 /* num of device page table pages */ | 21 | #define CT_PTP_NUM 4 /* num of device page table pages */ |
22 | 22 | ||
23 | #include <linux/mutex.h> | 23 | #include <linux/mutex.h> |
24 | #include <linux/list.h> | 24 | #include <linux/list.h> |
diff --git a/sound/pci/emu10k1/emupcm.c b/sound/pci/emu10k1/emupcm.c index 622bace148e3..e22b8e2bbd88 100644 --- a/sound/pci/emu10k1/emupcm.c +++ b/sound/pci/emu10k1/emupcm.c | |||
@@ -1146,6 +1146,11 @@ static int snd_emu10k1_playback_open(struct snd_pcm_substream *substream) | |||
1146 | kfree(epcm); | 1146 | kfree(epcm); |
1147 | return err; | 1147 | return err; |
1148 | } | 1148 | } |
1149 | err = snd_pcm_hw_rule_noresample(runtime, 48000); | ||
1150 | if (err < 0) { | ||
1151 | kfree(epcm); | ||
1152 | return err; | ||
1153 | } | ||
1149 | mix = &emu->pcm_mixer[substream->number]; | 1154 | mix = &emu->pcm_mixer[substream->number]; |
1150 | for (i = 0; i < 4; i++) | 1155 | for (i = 0; i < 4; i++) |
1151 | mix->send_routing[0][i] = mix->send_routing[1][i] = mix->send_routing[2][i] = i; | 1156 | mix->send_routing[0][i] = mix->send_routing[1][i] = mix->send_routing[2][i] = i; |
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c index 26a5a2f25d4b..718a2643474e 100644 --- a/sound/pci/es1938.c +++ b/sound/pci/es1938.c | |||
@@ -1854,8 +1854,9 @@ static int __devinit snd_es1938_probe(struct pci_dev *pci, | |||
1854 | } | 1854 | } |
1855 | } | 1855 | } |
1856 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, | 1856 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, |
1857 | chip->mpu_port, MPU401_INFO_INTEGRATED, | 1857 | chip->mpu_port, |
1858 | chip->irq, 0, &chip->rmidi) < 0) { | 1858 | MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, |
1859 | -1, &chip->rmidi) < 0) { | ||
1859 | printk(KERN_ERR "es1938: unable to initialize MPU-401\n"); | 1860 | printk(KERN_ERR "es1938: unable to initialize MPU-401\n"); |
1860 | } else { | 1861 | } else { |
1861 | // this line is vital for MIDI interrupt handling on ess-solo1 | 1862 | // this line is vital for MIDI interrupt handling on ess-solo1 |
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c index 99ea9320c6b5..407e4abc4356 100644 --- a/sound/pci/es1968.c +++ b/sound/pci/es1968.c | |||
@@ -2843,8 +2843,9 @@ static int __devinit snd_es1968_probe(struct pci_dev *pci, | |||
2843 | if (enable_mpu[dev]) { | 2843 | if (enable_mpu[dev]) { |
2844 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, | 2844 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, |
2845 | chip->io_port + ESM_MPU401_PORT, | 2845 | chip->io_port + ESM_MPU401_PORT, |
2846 | MPU401_INFO_INTEGRATED, | 2846 | MPU401_INFO_INTEGRATED | |
2847 | chip->irq, 0, &chip->rmidi)) < 0) { | 2847 | MPU401_INFO_IRQ_HOOK, |
2848 | -1, &chip->rmidi)) < 0) { | ||
2848 | printk(KERN_WARNING "es1968: skipping MPU-401 MIDI support..\n"); | 2849 | printk(KERN_WARNING "es1968: skipping MPU-401 MIDI support..\n"); |
2849 | } | 2850 | } |
2850 | } | 2851 | } |
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c index 32b02d906703..136f7232bb7c 100644 --- a/sound/pci/fm801.c +++ b/sound/pci/fm801.c | |||
@@ -729,11 +729,14 @@ static struct snd_fm801_tea575x_gpio snd_fm801_tea575x_gpios[] = { | |||
729 | { .data = 2, .clk = 0, .wren = 1, .most = 3, .name = "SF64-PCR" }, | 729 | { .data = 2, .clk = 0, .wren = 1, .most = 3, .name = "SF64-PCR" }, |
730 | }; | 730 | }; |
731 | 731 | ||
732 | #define get_tea575x_gpio(chip) \ | ||
733 | (&snd_fm801_tea575x_gpios[((chip)->tea575x_tuner & TUNER_TYPE_MASK) - 1]) | ||
734 | |||
732 | static void snd_fm801_tea575x_set_pins(struct snd_tea575x *tea, u8 pins) | 735 | static void snd_fm801_tea575x_set_pins(struct snd_tea575x *tea, u8 pins) |
733 | { | 736 | { |
734 | struct fm801 *chip = tea->private_data; | 737 | struct fm801 *chip = tea->private_data; |
735 | unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL)); | 738 | unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL)); |
736 | struct snd_fm801_tea575x_gpio gpio = snd_fm801_tea575x_gpios[(chip->tea575x_tuner & TUNER_TYPE_MASK) - 1]; | 739 | struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip); |
737 | 740 | ||
738 | reg &= ~(FM801_GPIO_GP(gpio.data) | | 741 | reg &= ~(FM801_GPIO_GP(gpio.data) | |
739 | FM801_GPIO_GP(gpio.clk) | | 742 | FM801_GPIO_GP(gpio.clk) | |
@@ -751,7 +754,7 @@ static u8 snd_fm801_tea575x_get_pins(struct snd_tea575x *tea) | |||
751 | { | 754 | { |
752 | struct fm801 *chip = tea->private_data; | 755 | struct fm801 *chip = tea->private_data; |
753 | unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL)); | 756 | unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL)); |
754 | struct snd_fm801_tea575x_gpio gpio = snd_fm801_tea575x_gpios[(chip->tea575x_tuner & TUNER_TYPE_MASK) - 1]; | 757 | struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip); |
755 | 758 | ||
756 | return (reg & FM801_GPIO_GP(gpio.data)) ? TEA575X_DATA : 0 | | 759 | return (reg & FM801_GPIO_GP(gpio.data)) ? TEA575X_DATA : 0 | |
757 | (reg & FM801_GPIO_GP(gpio.most)) ? TEA575X_MOST : 0; | 760 | (reg & FM801_GPIO_GP(gpio.most)) ? TEA575X_MOST : 0; |
@@ -761,7 +764,7 @@ static void snd_fm801_tea575x_set_direction(struct snd_tea575x *tea, bool output | |||
761 | { | 764 | { |
762 | struct fm801 *chip = tea->private_data; | 765 | struct fm801 *chip = tea->private_data; |
763 | unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL)); | 766 | unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL)); |
764 | struct snd_fm801_tea575x_gpio gpio = snd_fm801_tea575x_gpios[(chip->tea575x_tuner & TUNER_TYPE_MASK) - 1]; | 767 | struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip); |
765 | 768 | ||
766 | /* use GPIO lines and set write enable bit */ | 769 | /* use GPIO lines and set write enable bit */ |
767 | reg |= FM801_GPIO_GS(gpio.data) | | 770 | reg |= FM801_GPIO_GS(gpio.data) | |
@@ -1246,7 +1249,7 @@ static int __devinit snd_fm801_create(struct snd_card *card, | |||
1246 | chip->tea575x_tuner = tea575x_tuner; | 1249 | chip->tea575x_tuner = tea575x_tuner; |
1247 | if (!snd_tea575x_init(&chip->tea)) { | 1250 | if (!snd_tea575x_init(&chip->tea)) { |
1248 | snd_printk(KERN_INFO "detected TEA575x radio type %s\n", | 1251 | snd_printk(KERN_INFO "detected TEA575x radio type %s\n", |
1249 | snd_fm801_tea575x_gpios[tea575x_tuner - 1].name); | 1252 | get_tea575x_gpio(chip)->name); |
1250 | break; | 1253 | break; |
1251 | } | 1254 | } |
1252 | } | 1255 | } |
@@ -1256,9 +1259,7 @@ static int __devinit snd_fm801_create(struct snd_card *card, | |||
1256 | } | 1259 | } |
1257 | } | 1260 | } |
1258 | if (!(chip->tea575x_tuner & TUNER_DISABLED)) { | 1261 | if (!(chip->tea575x_tuner & TUNER_DISABLED)) { |
1259 | strlcpy(chip->tea.card, | 1262 | strlcpy(chip->tea.card, get_tea575x_gpio(chip)->name, |
1260 | snd_fm801_tea575x_gpios[(tea575x_tuner & | ||
1261 | TUNER_TYPE_MASK) - 1].name, | ||
1262 | sizeof(chip->tea.card)); | 1263 | sizeof(chip->tea.card)); |
1263 | } | 1264 | } |
1264 | #endif | 1265 | #endif |
@@ -1311,8 +1312,9 @@ static int __devinit snd_card_fm801_probe(struct pci_dev *pci, | |||
1311 | } | 1312 | } |
1312 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801, | 1313 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801, |
1313 | FM801_REG(chip, MPU401_DATA), | 1314 | FM801_REG(chip, MPU401_DATA), |
1314 | MPU401_INFO_INTEGRATED, | 1315 | MPU401_INFO_INTEGRATED | |
1315 | chip->irq, 0, &chip->rmidi)) < 0) { | 1316 | MPU401_INFO_IRQ_HOOK, |
1317 | -1, &chip->rmidi)) < 0) { | ||
1316 | snd_card_free(card); | 1318 | snd_card_free(card); |
1317 | return err; | 1319 | return err; |
1318 | } | 1320 | } |
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c index 0ccc0eb75775..8531b983f3af 100644 --- a/sound/pci/ice1712/ice1712.c +++ b/sound/pci/ice1712/ice1712.c | |||
@@ -2748,8 +2748,9 @@ static int __devinit snd_ice1712_probe(struct pci_dev *pci, | |||
2748 | if (!c->no_mpu401) { | 2748 | if (!c->no_mpu401) { |
2749 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712, | 2749 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712, |
2750 | ICEREG(ice, MPU1_CTRL), | 2750 | ICEREG(ice, MPU1_CTRL), |
2751 | (c->mpu401_1_info_flags | MPU401_INFO_INTEGRATED), | 2751 | c->mpu401_1_info_flags | |
2752 | ice->irq, 0, &ice->rmidi[0]); | 2752 | MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, |
2753 | -1, &ice->rmidi[0]); | ||
2753 | if (err < 0) { | 2754 | if (err < 0) { |
2754 | snd_card_free(card); | 2755 | snd_card_free(card); |
2755 | return err; | 2756 | return err; |
@@ -2764,8 +2765,9 @@ static int __devinit snd_ice1712_probe(struct pci_dev *pci, | |||
2764 | /* 2nd port used */ | 2765 | /* 2nd port used */ |
2765 | err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712, | 2766 | err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712, |
2766 | ICEREG(ice, MPU2_CTRL), | 2767 | ICEREG(ice, MPU2_CTRL), |
2767 | (c->mpu401_2_info_flags | MPU401_INFO_INTEGRATED), | 2768 | c->mpu401_2_info_flags | |
2768 | ice->irq, 0, &ice->rmidi[1]); | 2769 | MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, |
2770 | -1, &ice->rmidi[1]); | ||
2769 | 2771 | ||
2770 | if (err < 0) { | 2772 | if (err < 0) { |
2771 | snd_card_free(card); | 2773 | snd_card_free(card); |
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c index 0378126e6272..2fd4bf2d6653 100644 --- a/sound/pci/maestro3.c +++ b/sound/pci/maestro3.c | |||
@@ -2820,8 +2820,8 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) | |||
2820 | /* TODO enable MIDI IRQ and I/O */ | 2820 | /* TODO enable MIDI IRQ and I/O */ |
2821 | err = snd_mpu401_uart_new(chip->card, 0, MPU401_HW_MPU401, | 2821 | err = snd_mpu401_uart_new(chip->card, 0, MPU401_HW_MPU401, |
2822 | chip->iobase + MPU401_DATA_PORT, | 2822 | chip->iobase + MPU401_DATA_PORT, |
2823 | MPU401_INFO_INTEGRATED, | 2823 | MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, |
2824 | chip->irq, 0, &chip->rmidi); | 2824 | -1, &chip->rmidi); |
2825 | if (err < 0) | 2825 | if (err < 0) |
2826 | printk(KERN_WARNING "maestro3: no MIDI support.\n"); | 2826 | printk(KERN_WARNING "maestro3: no MIDI support.\n"); |
2827 | #endif | 2827 | #endif |
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c index 82311fcb86f6..53e5508abcbf 100644 --- a/sound/pci/oxygen/oxygen_lib.c +++ b/sound/pci/oxygen/oxygen_lib.c | |||
@@ -678,15 +678,15 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, | |||
678 | goto err_card; | 678 | goto err_card; |
679 | 679 | ||
680 | if (chip->model.device_config & (MIDI_OUTPUT | MIDI_INPUT)) { | 680 | if (chip->model.device_config & (MIDI_OUTPUT | MIDI_INPUT)) { |
681 | unsigned int info_flags = MPU401_INFO_INTEGRATED; | 681 | unsigned int info_flags = |
682 | MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK; | ||
682 | if (chip->model.device_config & MIDI_OUTPUT) | 683 | if (chip->model.device_config & MIDI_OUTPUT) |
683 | info_flags |= MPU401_INFO_OUTPUT; | 684 | info_flags |= MPU401_INFO_OUTPUT; |
684 | if (chip->model.device_config & MIDI_INPUT) | 685 | if (chip->model.device_config & MIDI_INPUT) |
685 | info_flags |= MPU401_INFO_INPUT; | 686 | info_flags |= MPU401_INFO_INPUT; |
686 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI, | 687 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI, |
687 | chip->addr + OXYGEN_MPU401, | 688 | chip->addr + OXYGEN_MPU401, |
688 | info_flags, 0, 0, | 689 | info_flags, -1, &chip->midi); |
689 | &chip->midi); | ||
690 | if (err < 0) | 690 | if (err < 0) |
691 | goto err_card; | 691 | goto err_card; |
692 | } | 692 | } |
diff --git a/sound/pci/oxygen/xonar_pcm179x.c b/sound/pci/oxygen/xonar_pcm179x.c index 32d096c98f5b..8433aa7c3d75 100644 --- a/sound/pci/oxygen/xonar_pcm179x.c +++ b/sound/pci/oxygen/xonar_pcm179x.c | |||
@@ -1074,6 +1074,7 @@ static const struct oxygen_model model_xonar_st = { | |||
1074 | .device_config = PLAYBACK_0_TO_I2S | | 1074 | .device_config = PLAYBACK_0_TO_I2S | |
1075 | PLAYBACK_1_TO_SPDIF | | 1075 | PLAYBACK_1_TO_SPDIF | |
1076 | CAPTURE_0_FROM_I2S_2 | | 1076 | CAPTURE_0_FROM_I2S_2 | |
1077 | CAPTURE_1_FROM_SPDIF | | ||
1077 | AC97_FMIC_SWITCH, | 1078 | AC97_FMIC_SWITCH, |
1078 | .dac_channels_pcm = 2, | 1079 | .dac_channels_pcm = 2, |
1079 | .dac_channels_mixer = 2, | 1080 | .dac_channels_mixer = 2, |
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c index e34ae14908b3..88cc776aa38b 100644 --- a/sound/pci/riptide/riptide.c +++ b/sound/pci/riptide/riptide.c | |||
@@ -2109,7 +2109,7 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) | |||
2109 | val = mpu_port[dev]; | 2109 | val = mpu_port[dev]; |
2110 | pci_write_config_word(chip->pci, PCI_EXT_MPU_Base, val); | 2110 | pci_write_config_word(chip->pci, PCI_EXT_MPU_Base, val); |
2111 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_RIPTIDE, | 2111 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_RIPTIDE, |
2112 | val, 0, chip->irq, 0, | 2112 | val, MPU401_INFO_IRQ_HOOK, -1, |
2113 | &chip->rmidi); | 2113 | &chip->rmidi); |
2114 | if (err < 0) | 2114 | if (err < 0) |
2115 | snd_printk(KERN_WARNING | 2115 | snd_printk(KERN_WARNING |
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index 493e3946756f..6e2f7ef7ddb1 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c | |||
@@ -1241,10 +1241,30 @@ static int hdspm_external_sample_rate(struct hdspm *hdspm) | |||
1241 | return rate; | 1241 | return rate; |
1242 | } | 1242 | } |
1243 | 1243 | ||
1244 | /* return latency in samples per period */ | ||
1245 | static int hdspm_get_latency(struct hdspm *hdspm) | ||
1246 | { | ||
1247 | int n; | ||
1248 | |||
1249 | n = hdspm_decode_latency(hdspm->control_register); | ||
1250 | |||
1251 | /* Special case for new RME cards with 32 samples period size. | ||
1252 | * The three latency bits in the control register | ||
1253 | * (HDSP_LatencyMask) encode latency values of 64 samples as | ||
1254 | * 0, 128 samples as 1 ... 4096 samples as 6. For old cards, 7 | ||
1255 | * denotes 8192 samples, but on new cards like RayDAT or AIO, | ||
1256 | * it corresponds to 32 samples. | ||
1257 | */ | ||
1258 | if ((7 == n) && (RayDAT == hdspm->io_type || AIO == hdspm->io_type)) | ||
1259 | n = -1; | ||
1260 | |||
1261 | return 1 << (n + 6); | ||
1262 | } | ||
1263 | |||
1244 | /* Latency function */ | 1264 | /* Latency function */ |
1245 | static inline void hdspm_compute_period_size(struct hdspm *hdspm) | 1265 | static inline void hdspm_compute_period_size(struct hdspm *hdspm) |
1246 | { | 1266 | { |
1247 | hdspm->period_bytes = 1 << ((hdspm_decode_latency(hdspm->control_register) + 8)); | 1267 | hdspm->period_bytes = 4 * hdspm_get_latency(hdspm); |
1248 | } | 1268 | } |
1249 | 1269 | ||
1250 | 1270 | ||
@@ -1303,12 +1323,27 @@ static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames) | |||
1303 | 1323 | ||
1304 | spin_lock_irq(&s->lock); | 1324 | spin_lock_irq(&s->lock); |
1305 | 1325 | ||
1306 | frames >>= 7; | 1326 | if (32 == frames) { |
1307 | n = 0; | 1327 | /* Special case for new RME cards like RayDAT/AIO which |
1308 | while (frames) { | 1328 | * support period sizes of 32 samples. Since latency is |
1309 | n++; | 1329 | * encoded in the three bits of HDSP_LatencyMask, we can only |
1310 | frames >>= 1; | 1330 | * have values from 0 .. 7. While 0 still means 64 samples and |
1331 | * 6 represents 4096 samples on all cards, 7 represents 8192 | ||
1332 | * on older cards and 32 samples on new cards. | ||
1333 | * | ||
1334 | * In other words, period size in samples is calculated by | ||
1335 | * 2^(n+6) with n ranging from 0 .. 7. | ||
1336 | */ | ||
1337 | n = 7; | ||
1338 | } else { | ||
1339 | frames >>= 7; | ||
1340 | n = 0; | ||
1341 | while (frames) { | ||
1342 | n++; | ||
1343 | frames >>= 1; | ||
1344 | } | ||
1311 | } | 1345 | } |
1346 | |||
1312 | s->control_register &= ~HDSPM_LatencyMask; | 1347 | s->control_register &= ~HDSPM_LatencyMask; |
1313 | s->control_register |= hdspm_encode_latency(n); | 1348 | s->control_register |= hdspm_encode_latency(n); |
1314 | 1349 | ||
@@ -4801,8 +4836,7 @@ snd_hdspm_proc_read_madi(struct snd_info_entry * entry, | |||
4801 | 4836 | ||
4802 | snd_iprintf(buffer, "--- Settings ---\n"); | 4837 | snd_iprintf(buffer, "--- Settings ---\n"); |
4803 | 4838 | ||
4804 | x = 1 << (6 + hdspm_decode_latency(hdspm->control_register & | 4839 | x = hdspm_get_latency(hdspm); |
4805 | HDSPM_LatencyMask)); | ||
4806 | 4840 | ||
4807 | snd_iprintf(buffer, | 4841 | snd_iprintf(buffer, |
4808 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", | 4842 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", |
@@ -4965,8 +4999,7 @@ snd_hdspm_proc_read_aes32(struct snd_info_entry * entry, | |||
4965 | 4999 | ||
4966 | snd_iprintf(buffer, "--- Settings ---\n"); | 5000 | snd_iprintf(buffer, "--- Settings ---\n"); |
4967 | 5001 | ||
4968 | x = 1 << (6 + hdspm_decode_latency(hdspm->control_register & | 5002 | x = hdspm_get_latency(hdspm); |
4969 | HDSPM_LatencyMask)); | ||
4970 | 5003 | ||
4971 | snd_iprintf(buffer, | 5004 | snd_iprintf(buffer, |
4972 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", | 5005 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", |
@@ -5672,19 +5705,6 @@ static int snd_hdspm_prepare(struct snd_pcm_substream *substream) | |||
5672 | return 0; | 5705 | return 0; |
5673 | } | 5706 | } |
5674 | 5707 | ||
5675 | static unsigned int period_sizes_old[] = { | ||
5676 | 64, 128, 256, 512, 1024, 2048, 4096 | ||
5677 | }; | ||
5678 | |||
5679 | static unsigned int period_sizes_new[] = { | ||
5680 | 32, 64, 128, 256, 512, 1024, 2048, 4096 | ||
5681 | }; | ||
5682 | |||
5683 | /* RayDAT and AIO always have a buffer of 16384 samples per channel */ | ||
5684 | static unsigned int raydat_aio_buffer_sizes[] = { | ||
5685 | 16384 | ||
5686 | }; | ||
5687 | |||
5688 | static struct snd_pcm_hardware snd_hdspm_playback_subinfo = { | 5708 | static struct snd_pcm_hardware snd_hdspm_playback_subinfo = { |
5689 | .info = (SNDRV_PCM_INFO_MMAP | | 5709 | .info = (SNDRV_PCM_INFO_MMAP | |
5690 | SNDRV_PCM_INFO_MMAP_VALID | | 5710 | SNDRV_PCM_INFO_MMAP_VALID | |
@@ -5703,8 +5723,8 @@ static struct snd_pcm_hardware snd_hdspm_playback_subinfo = { | |||
5703 | .channels_max = HDSPM_MAX_CHANNELS, | 5723 | .channels_max = HDSPM_MAX_CHANNELS, |
5704 | .buffer_bytes_max = | 5724 | .buffer_bytes_max = |
5705 | HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, | 5725 | HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, |
5706 | .period_bytes_min = (64 * 4), | 5726 | .period_bytes_min = (32 * 4), |
5707 | .period_bytes_max = (4096 * 4) * HDSPM_MAX_CHANNELS, | 5727 | .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS, |
5708 | .periods_min = 2, | 5728 | .periods_min = 2, |
5709 | .periods_max = 512, | 5729 | .periods_max = 512, |
5710 | .fifo_size = 0 | 5730 | .fifo_size = 0 |
@@ -5728,31 +5748,13 @@ static struct snd_pcm_hardware snd_hdspm_capture_subinfo = { | |||
5728 | .channels_max = HDSPM_MAX_CHANNELS, | 5748 | .channels_max = HDSPM_MAX_CHANNELS, |
5729 | .buffer_bytes_max = | 5749 | .buffer_bytes_max = |
5730 | HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, | 5750 | HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, |
5731 | .period_bytes_min = (64 * 4), | 5751 | .period_bytes_min = (32 * 4), |
5732 | .period_bytes_max = (4096 * 4) * HDSPM_MAX_CHANNELS, | 5752 | .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS, |
5733 | .periods_min = 2, | 5753 | .periods_min = 2, |
5734 | .periods_max = 512, | 5754 | .periods_max = 512, |
5735 | .fifo_size = 0 | 5755 | .fifo_size = 0 |
5736 | }; | 5756 | }; |
5737 | 5757 | ||
5738 | static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_old = { | ||
5739 | .count = ARRAY_SIZE(period_sizes_old), | ||
5740 | .list = period_sizes_old, | ||
5741 | .mask = 0 | ||
5742 | }; | ||
5743 | |||
5744 | static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_new = { | ||
5745 | .count = ARRAY_SIZE(period_sizes_new), | ||
5746 | .list = period_sizes_new, | ||
5747 | .mask = 0 | ||
5748 | }; | ||
5749 | |||
5750 | static struct snd_pcm_hw_constraint_list hw_constraints_raydat_io_buffer = { | ||
5751 | .count = ARRAY_SIZE(raydat_aio_buffer_sizes), | ||
5752 | .list = raydat_aio_buffer_sizes, | ||
5753 | .mask = 0 | ||
5754 | }; | ||
5755 | |||
5756 | static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params, | 5758 | static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params, |
5757 | struct snd_pcm_hw_rule *rule) | 5759 | struct snd_pcm_hw_rule *rule) |
5758 | { | 5760 | { |
@@ -5953,26 +5955,29 @@ static int snd_hdspm_playback_open(struct snd_pcm_substream *substream) | |||
5953 | spin_unlock_irq(&hdspm->lock); | 5955 | spin_unlock_irq(&hdspm->lock); |
5954 | 5956 | ||
5955 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); | 5957 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
5958 | snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); | ||
5956 | 5959 | ||
5957 | switch (hdspm->io_type) { | 5960 | switch (hdspm->io_type) { |
5958 | case AIO: | 5961 | case AIO: |
5959 | case RayDAT: | 5962 | case RayDAT: |
5960 | snd_pcm_hw_constraint_list(runtime, 0, | 5963 | snd_pcm_hw_constraint_minmax(runtime, |
5961 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, | 5964 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
5962 | &hw_constraints_period_sizes_new); | 5965 | 32, 4096); |
5963 | snd_pcm_hw_constraint_list(runtime, 0, | 5966 | /* RayDAT & AIO have a fixed buffer of 16384 samples per channel */ |
5964 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, | 5967 | snd_pcm_hw_constraint_minmax(runtime, |
5965 | &hw_constraints_raydat_io_buffer); | 5968 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, |
5966 | 5969 | 16384, 16384); | |
5967 | break; | 5970 | break; |
5968 | 5971 | ||
5969 | default: | 5972 | default: |
5970 | snd_pcm_hw_constraint_list(runtime, 0, | 5973 | snd_pcm_hw_constraint_minmax(runtime, |
5971 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, | 5974 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
5972 | &hw_constraints_period_sizes_old); | 5975 | 64, 8192); |
5976 | break; | ||
5973 | } | 5977 | } |
5974 | 5978 | ||
5975 | if (AES32 == hdspm->io_type) { | 5979 | if (AES32 == hdspm->io_type) { |
5980 | runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; | ||
5976 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, | 5981 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
5977 | &hdspm_hw_constraints_aes32_sample_rates); | 5982 | &hdspm_hw_constraints_aes32_sample_rates); |
5978 | } else { | 5983 | } else { |
@@ -6025,24 +6030,28 @@ static int snd_hdspm_capture_open(struct snd_pcm_substream *substream) | |||
6025 | spin_unlock_irq(&hdspm->lock); | 6030 | spin_unlock_irq(&hdspm->lock); |
6026 | 6031 | ||
6027 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); | 6032 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
6033 | snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); | ||
6034 | |||
6028 | switch (hdspm->io_type) { | 6035 | switch (hdspm->io_type) { |
6029 | case AIO: | 6036 | case AIO: |
6030 | case RayDAT: | 6037 | case RayDAT: |
6031 | snd_pcm_hw_constraint_list(runtime, 0, | 6038 | snd_pcm_hw_constraint_minmax(runtime, |
6032 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, | 6039 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
6033 | &hw_constraints_period_sizes_new); | 6040 | 32, 4096); |
6034 | snd_pcm_hw_constraint_list(runtime, 0, | 6041 | snd_pcm_hw_constraint_minmax(runtime, |
6035 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, | 6042 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, |
6036 | &hw_constraints_raydat_io_buffer); | 6043 | 16384, 16384); |
6037 | break; | 6044 | break; |
6038 | 6045 | ||
6039 | default: | 6046 | default: |
6040 | snd_pcm_hw_constraint_list(runtime, 0, | 6047 | snd_pcm_hw_constraint_minmax(runtime, |
6041 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, | 6048 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
6042 | &hw_constraints_period_sizes_old); | 6049 | 64, 8192); |
6050 | break; | ||
6043 | } | 6051 | } |
6044 | 6052 | ||
6045 | if (AES32 == hdspm->io_type) { | 6053 | if (AES32 == hdspm->io_type) { |
6054 | runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; | ||
6046 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, | 6055 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
6047 | &hdspm_hw_constraints_aes32_sample_rates); | 6056 | &hdspm_hw_constraints_aes32_sample_rates); |
6048 | } else { | 6057 | } else { |
@@ -6088,7 +6097,7 @@ static inline int copy_u32_le(void __user *dest, void __iomem *src) | |||
6088 | } | 6097 | } |
6089 | 6098 | ||
6090 | static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, | 6099 | static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, |
6091 | unsigned int cmd, unsigned long __user arg) | 6100 | unsigned int cmd, unsigned long arg) |
6092 | { | 6101 | { |
6093 | void __user *argp = (void __user *)arg; | 6102 | void __user *argp = (void __user *)arg; |
6094 | struct hdspm *hdspm = hw->private_data; | 6103 | struct hdspm *hdspm = hw->private_data; |
@@ -6213,11 +6222,13 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, | |||
6213 | info.line_out = hdspm_line_out(hdspm); | 6222 | info.line_out = hdspm_line_out(hdspm); |
6214 | info.passthru = 0; | 6223 | info.passthru = 0; |
6215 | spin_unlock_irq(&hdspm->lock); | 6224 | spin_unlock_irq(&hdspm->lock); |
6216 | if (copy_to_user((void __user *) arg, &info, sizeof(info))) | 6225 | if (copy_to_user(argp, &info, sizeof(info))) |
6217 | return -EFAULT; | 6226 | return -EFAULT; |
6218 | break; | 6227 | break; |
6219 | 6228 | ||
6220 | case SNDRV_HDSPM_IOCTL_GET_STATUS: | 6229 | case SNDRV_HDSPM_IOCTL_GET_STATUS: |
6230 | memset(&status, 0, sizeof(status)); | ||
6231 | |||
6221 | status.card_type = hdspm->io_type; | 6232 | status.card_type = hdspm->io_type; |
6222 | 6233 | ||
6223 | status.autosync_source = hdspm_autosync_ref(hdspm); | 6234 | status.autosync_source = hdspm_autosync_ref(hdspm); |
@@ -6250,13 +6261,15 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, | |||
6250 | break; | 6261 | break; |
6251 | } | 6262 | } |
6252 | 6263 | ||
6253 | if (copy_to_user((void __user *) arg, &status, sizeof(status))) | 6264 | if (copy_to_user(argp, &status, sizeof(status))) |
6254 | return -EFAULT; | 6265 | return -EFAULT; |
6255 | 6266 | ||
6256 | 6267 | ||
6257 | break; | 6268 | break; |
6258 | 6269 | ||
6259 | case SNDRV_HDSPM_IOCTL_GET_VERSION: | 6270 | case SNDRV_HDSPM_IOCTL_GET_VERSION: |
6271 | memset(&hdspm_version, 0, sizeof(hdspm_version)); | ||
6272 | |||
6260 | hdspm_version.card_type = hdspm->io_type; | 6273 | hdspm_version.card_type = hdspm->io_type; |
6261 | strncpy(hdspm_version.cardname, hdspm->card_name, | 6274 | strncpy(hdspm_version.cardname, hdspm->card_name, |
6262 | sizeof(hdspm_version.cardname)); | 6275 | sizeof(hdspm_version.cardname)); |
@@ -6267,13 +6280,13 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, | |||
6267 | if (hdspm->tco) | 6280 | if (hdspm->tco) |
6268 | hdspm_version.addons |= HDSPM_ADDON_TCO; | 6281 | hdspm_version.addons |= HDSPM_ADDON_TCO; |
6269 | 6282 | ||
6270 | if (copy_to_user((void __user *) arg, &hdspm_version, | 6283 | if (copy_to_user(argp, &hdspm_version, |
6271 | sizeof(hdspm_version))) | 6284 | sizeof(hdspm_version))) |
6272 | return -EFAULT; | 6285 | return -EFAULT; |
6273 | break; | 6286 | break; |
6274 | 6287 | ||
6275 | case SNDRV_HDSPM_IOCTL_GET_MIXER: | 6288 | case SNDRV_HDSPM_IOCTL_GET_MIXER: |
6276 | if (copy_from_user(&mixer, (void __user *)arg, sizeof(mixer))) | 6289 | if (copy_from_user(&mixer, argp, sizeof(mixer))) |
6277 | return -EFAULT; | 6290 | return -EFAULT; |
6278 | if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer, | 6291 | if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer, |
6279 | sizeof(struct hdspm_mixer))) | 6292 | sizeof(struct hdspm_mixer))) |
diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c index 2571a67b389a..c5008166cf1f 100644 --- a/sound/pci/sonicvibes.c +++ b/sound/pci/sonicvibes.c | |||
@@ -1493,9 +1493,10 @@ static int __devinit snd_sonic_probe(struct pci_dev *pci, | |||
1493 | return err; | 1493 | return err; |
1494 | } | 1494 | } |
1495 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SONICVIBES, | 1495 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SONICVIBES, |
1496 | sonic->midi_port, MPU401_INFO_INTEGRATED, | 1496 | sonic->midi_port, |
1497 | sonic->irq, 0, | 1497 | MPU401_INFO_INTEGRATED | |
1498 | &midi_uart)) < 0) { | 1498 | MPU401_INFO_IRQ_HOOK, |
1499 | -1, &midi_uart)) < 0) { | ||
1499 | snd_card_free(card); | 1500 | snd_card_free(card); |
1500 | return err; | 1501 | return err; |
1501 | } | 1502 | } |
diff --git a/sound/pci/trident/trident.c b/sound/pci/trident/trident.c index d8a128f6fc02..5e707effdc7c 100644 --- a/sound/pci/trident/trident.c +++ b/sound/pci/trident/trident.c | |||
@@ -148,8 +148,9 @@ static int __devinit snd_trident_probe(struct pci_dev *pci, | |||
148 | if (trident->device != TRIDENT_DEVICE_ID_SI7018 && | 148 | if (trident->device != TRIDENT_DEVICE_ID_SI7018 && |
149 | (err = snd_mpu401_uart_new(card, 0, MPU401_HW_TRID4DWAVE, | 149 | (err = snd_mpu401_uart_new(card, 0, MPU401_HW_TRID4DWAVE, |
150 | trident->midi_port, | 150 | trident->midi_port, |
151 | MPU401_INFO_INTEGRATED, | 151 | MPU401_INFO_INTEGRATED | |
152 | trident->irq, 0, &trident->rmidi)) < 0) { | 152 | MPU401_INFO_IRQ_HOOK, |
153 | -1, &trident->rmidi)) < 0) { | ||
153 | snd_card_free(card); | 154 | snd_card_free(card); |
154 | return err; | 155 | return err; |
155 | } | 156 | } |
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c index f03fd620a2a0..c3656fffdb50 100644 --- a/sound/pci/via82xx.c +++ b/sound/pci/via82xx.c | |||
@@ -1175,6 +1175,7 @@ static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev, | |||
1175 | struct snd_pcm_runtime *runtime = substream->runtime; | 1175 | struct snd_pcm_runtime *runtime = substream->runtime; |
1176 | int err; | 1176 | int err; |
1177 | struct via_rate_lock *ratep; | 1177 | struct via_rate_lock *ratep; |
1178 | bool use_src = false; | ||
1178 | 1179 | ||
1179 | runtime->hw = snd_via82xx_hw; | 1180 | runtime->hw = snd_via82xx_hw; |
1180 | 1181 | ||
@@ -1196,6 +1197,7 @@ static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev, | |||
1196 | SNDRV_PCM_RATE_8000_48000); | 1197 | SNDRV_PCM_RATE_8000_48000); |
1197 | runtime->hw.rate_min = 8000; | 1198 | runtime->hw.rate_min = 8000; |
1198 | runtime->hw.rate_max = 48000; | 1199 | runtime->hw.rate_max = 48000; |
1200 | use_src = true; | ||
1199 | } else if (! ratep->rate) { | 1201 | } else if (! ratep->rate) { |
1200 | int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC; | 1202 | int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC; |
1201 | runtime->hw.rates = chip->ac97->rates[idx]; | 1203 | runtime->hw.rates = chip->ac97->rates[idx]; |
@@ -1212,6 +1214,12 @@ static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev, | |||
1212 | if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) | 1214 | if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) |
1213 | return err; | 1215 | return err; |
1214 | 1216 | ||
1217 | if (use_src) { | ||
1218 | err = snd_pcm_hw_rule_noresample(runtime, 48000); | ||
1219 | if (err < 0) | ||
1220 | return err; | ||
1221 | } | ||
1222 | |||
1215 | runtime->private_data = viadev; | 1223 | runtime->private_data = viadev; |
1216 | viadev->substream = substream; | 1224 | viadev->substream = substream; |
1217 | 1225 | ||
@@ -2068,8 +2076,9 @@ static int __devinit snd_via686_init_misc(struct via82xx *chip) | |||
2068 | pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg); | 2076 | pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg); |
2069 | if (chip->mpu_res) { | 2077 | if (chip->mpu_res) { |
2070 | if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A, | 2078 | if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A, |
2071 | mpu_port, MPU401_INFO_INTEGRATED, | 2079 | mpu_port, MPU401_INFO_INTEGRATED | |
2072 | chip->irq, 0, &chip->rmidi) < 0) { | 2080 | MPU401_INFO_IRQ_HOOK, -1, |
2081 | &chip->rmidi) < 0) { | ||
2073 | printk(KERN_WARNING "unable to initialize MPU-401" | 2082 | printk(KERN_WARNING "unable to initialize MPU-401" |
2074 | " at 0x%lx, skipping\n", mpu_port); | 2083 | " at 0x%lx, skipping\n", mpu_port); |
2075 | legacy &= ~VIA_FUNC_ENABLE_MIDI; | 2084 | legacy &= ~VIA_FUNC_ENABLE_MIDI; |
diff --git a/sound/pci/ymfpci/ymfpci.c b/sound/pci/ymfpci/ymfpci.c index 511d57653124..3253b04da184 100644 --- a/sound/pci/ymfpci/ymfpci.c +++ b/sound/pci/ymfpci/ymfpci.c | |||
@@ -305,8 +305,9 @@ static int __devinit snd_card_ymfpci_probe(struct pci_dev *pci, | |||
305 | if (chip->mpu_res) { | 305 | if (chip->mpu_res) { |
306 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_YMFPCI, | 306 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_YMFPCI, |
307 | mpu_port[dev], | 307 | mpu_port[dev], |
308 | MPU401_INFO_INTEGRATED, | 308 | MPU401_INFO_INTEGRATED | |
309 | pci->irq, 0, &chip->rawmidi)) < 0) { | 309 | MPU401_INFO_IRQ_HOOK, |
310 | -1, &chip->rawmidi)) < 0) { | ||
310 | printk(KERN_WARNING "ymfpci: cannot initialize MPU401 at 0x%lx, skipping...\n", mpu_port[dev]); | 311 | printk(KERN_WARNING "ymfpci: cannot initialize MPU401 at 0x%lx, skipping...\n", mpu_port[dev]); |
311 | legacy_ctrl &= ~YMFPCI_LEGACY_MIEN; /* disable MPU401 irq */ | 312 | legacy_ctrl &= ~YMFPCI_LEGACY_MIEN; /* disable MPU401 irq */ |
312 | pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl); | 313 | pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl); |
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c index f3260e658b8a..66ea71b2a70d 100644 --- a/sound/pci/ymfpci/ymfpci_main.c +++ b/sound/pci/ymfpci/ymfpci_main.c | |||
@@ -897,6 +897,18 @@ static int snd_ymfpci_playback_open_1(struct snd_pcm_substream *substream) | |||
897 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); | 897 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
898 | struct snd_pcm_runtime *runtime = substream->runtime; | 898 | struct snd_pcm_runtime *runtime = substream->runtime; |
899 | struct snd_ymfpci_pcm *ypcm; | 899 | struct snd_ymfpci_pcm *ypcm; |
900 | int err; | ||
901 | |||
902 | runtime->hw = snd_ymfpci_playback; | ||
903 | /* FIXME? True value is 256/48 = 5.33333 ms */ | ||
904 | err = snd_pcm_hw_constraint_minmax(runtime, | ||
905 | SNDRV_PCM_HW_PARAM_PERIOD_TIME, | ||
906 | 5334, UINT_MAX); | ||
907 | if (err < 0) | ||
908 | return err; | ||
909 | err = snd_pcm_hw_rule_noresample(runtime, 48000); | ||
910 | if (err < 0) | ||
911 | return err; | ||
900 | 912 | ||
901 | ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL); | 913 | ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL); |
902 | if (ypcm == NULL) | 914 | if (ypcm == NULL) |
@@ -904,11 +916,8 @@ static int snd_ymfpci_playback_open_1(struct snd_pcm_substream *substream) | |||
904 | ypcm->chip = chip; | 916 | ypcm->chip = chip; |
905 | ypcm->type = PLAYBACK_VOICE; | 917 | ypcm->type = PLAYBACK_VOICE; |
906 | ypcm->substream = substream; | 918 | ypcm->substream = substream; |
907 | runtime->hw = snd_ymfpci_playback; | ||
908 | runtime->private_data = ypcm; | 919 | runtime->private_data = ypcm; |
909 | runtime->private_free = snd_ymfpci_pcm_free_substream; | 920 | runtime->private_free = snd_ymfpci_pcm_free_substream; |
910 | /* FIXME? True value is 256/48 = 5.33333 ms */ | ||
911 | snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 5333, UINT_MAX); | ||
912 | return 0; | 921 | return 0; |
913 | } | 922 | } |
914 | 923 | ||
@@ -1013,6 +1022,18 @@ static int snd_ymfpci_capture_open(struct snd_pcm_substream *substream, | |||
1013 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); | 1022 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
1014 | struct snd_pcm_runtime *runtime = substream->runtime; | 1023 | struct snd_pcm_runtime *runtime = substream->runtime; |
1015 | struct snd_ymfpci_pcm *ypcm; | 1024 | struct snd_ymfpci_pcm *ypcm; |
1025 | int err; | ||
1026 | |||
1027 | runtime->hw = snd_ymfpci_capture; | ||
1028 | /* FIXME? True value is 256/48 = 5.33333 ms */ | ||
1029 | err = snd_pcm_hw_constraint_minmax(runtime, | ||
1030 | SNDRV_PCM_HW_PARAM_PERIOD_TIME, | ||
1031 | 5334, UINT_MAX); | ||
1032 | if (err < 0) | ||
1033 | return err; | ||
1034 | err = snd_pcm_hw_rule_noresample(runtime, 48000); | ||
1035 | if (err < 0) | ||
1036 | return err; | ||
1016 | 1037 | ||
1017 | ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL); | 1038 | ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL); |
1018 | if (ypcm == NULL) | 1039 | if (ypcm == NULL) |
@@ -1022,9 +1043,6 @@ static int snd_ymfpci_capture_open(struct snd_pcm_substream *substream, | |||
1022 | ypcm->substream = substream; | 1043 | ypcm->substream = substream; |
1023 | ypcm->capture_bank_number = capture_bank_number; | 1044 | ypcm->capture_bank_number = capture_bank_number; |
1024 | chip->capture_substream[capture_bank_number] = substream; | 1045 | chip->capture_substream[capture_bank_number] = substream; |
1025 | runtime->hw = snd_ymfpci_capture; | ||
1026 | /* FIXME? True value is 256/48 = 5.33333 ms */ | ||
1027 | snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 5333, UINT_MAX); | ||
1028 | runtime->private_data = ypcm; | 1046 | runtime->private_data = ypcm; |
1029 | runtime->private_free = snd_ymfpci_pcm_free_substream; | 1047 | runtime->private_free = snd_ymfpci_pcm_free_substream; |
1030 | snd_ymfpci_hw_start(chip); | 1048 | snd_ymfpci_hw_start(chip); |
@@ -1615,7 +1633,7 @@ YMFPCI_DOUBLE("ADC Playback Volume", 0, YDSXGR_PRIADCOUTVOL), | |||
1615 | YMFPCI_DOUBLE("ADC Capture Volume", 0, YDSXGR_PRIADCLOOPVOL), | 1633 | YMFPCI_DOUBLE("ADC Capture Volume", 0, YDSXGR_PRIADCLOOPVOL), |
1616 | YMFPCI_DOUBLE("ADC Playback Volume", 1, YDSXGR_SECADCOUTVOL), | 1634 | YMFPCI_DOUBLE("ADC Playback Volume", 1, YDSXGR_SECADCOUTVOL), |
1617 | YMFPCI_DOUBLE("ADC Capture Volume", 1, YDSXGR_SECADCLOOPVOL), | 1635 | YMFPCI_DOUBLE("ADC Capture Volume", 1, YDSXGR_SECADCLOOPVOL), |
1618 | YMFPCI_DOUBLE("FM Legacy Volume", 0, YDSXGR_LEGACYOUTVOL), | 1636 | YMFPCI_DOUBLE("FM Legacy Playback Volume", 0, YDSXGR_LEGACYOUTVOL), |
1619 | YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ", PLAYBACK,VOLUME), 0, YDSXGR_ZVOUTVOL), | 1637 | YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ", PLAYBACK,VOLUME), 0, YDSXGR_ZVOUTVOL), |
1620 | YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("", CAPTURE,VOLUME), 0, YDSXGR_ZVLOOPVOL), | 1638 | YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("", CAPTURE,VOLUME), 0, YDSXGR_ZVLOOPVOL), |
1621 | YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ",PLAYBACK,VOLUME), 1, YDSXGR_SPDIFOUTVOL), | 1639 | YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ",PLAYBACK,VOLUME), 1, YDSXGR_SPDIFOUTVOL), |
diff --git a/sound/ppc/keywest.c b/sound/ppc/keywest.c index 8f064c7ce745..4080becf4cef 100644 --- a/sound/ppc/keywest.c +++ b/sound/ppc/keywest.c | |||
@@ -82,7 +82,6 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter) | |||
82 | 82 | ||
83 | static int keywest_remove(struct i2c_client *client) | 83 | static int keywest_remove(struct i2c_client *client) |
84 | { | 84 | { |
85 | i2c_set_clientdata(client, NULL); | ||
86 | if (! keywest_ctx) | 85 | if (! keywest_ctx) |
87 | return 0; | 86 | return 0; |
88 | if (client == keywest_ctx->client) | 87 | if (client == keywest_ctx->client) |
diff --git a/sound/usb/6fire/firmware.c b/sound/usb/6fire/firmware.c index 1e3ae3327dd3..07bcfe4d18a7 100644 --- a/sound/usb/6fire/firmware.c +++ b/sound/usb/6fire/firmware.c | |||
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | #include <linux/firmware.h> | 17 | #include <linux/firmware.h> |
18 | #include <linux/bitrev.h> | 18 | #include <linux/bitrev.h> |
19 | #include <linux/kernel.h> | ||
19 | 20 | ||
20 | #include "firmware.h" | 21 | #include "firmware.h" |
21 | #include "chip.h" | 22 | #include "chip.h" |
@@ -59,21 +60,19 @@ struct ihex_record { | |||
59 | unsigned int txt_offset; /* current position in txt_data */ | 60 | unsigned int txt_offset; /* current position in txt_data */ |
60 | }; | 61 | }; |
61 | 62 | ||
62 | static u8 usb6fire_fw_ihex_nibble(const u8 n) | ||
63 | { | ||
64 | if (n >= '0' && n <= '9') | ||
65 | return n - '0'; | ||
66 | else if (n >= 'A' && n <= 'F') | ||
67 | return n - ('A' - 10); | ||
68 | else if (n >= 'a' && n <= 'f') | ||
69 | return n - ('a' - 10); | ||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | static u8 usb6fire_fw_ihex_hex(const u8 *data, u8 *crc) | 63 | static u8 usb6fire_fw_ihex_hex(const u8 *data, u8 *crc) |
74 | { | 64 | { |
75 | u8 val = (usb6fire_fw_ihex_nibble(data[0]) << 4) | | 65 | u8 val = 0; |
76 | usb6fire_fw_ihex_nibble(data[1]); | 66 | int hval; |
67 | |||
68 | hval = hex_to_bin(data[0]); | ||
69 | if (hval >= 0) | ||
70 | val |= (hval << 4); | ||
71 | |||
72 | hval = hex_to_bin(data[1]); | ||
73 | if (hval >= 0) | ||
74 | val |= hval; | ||
75 | |||
77 | *crc += val; | 76 | *crc += val; |
78 | return val; | 77 | return val; |
79 | } | 78 | } |
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig index 8beb77563da2..3efc21c3d67c 100644 --- a/sound/usb/Kconfig +++ b/sound/usb/Kconfig | |||
@@ -67,6 +67,7 @@ config SND_USB_CAIAQ | |||
67 | * Native Instruments Guitar Rig mobile | 67 | * Native Instruments Guitar Rig mobile |
68 | * Native Instruments Traktor Kontrol X1 | 68 | * Native Instruments Traktor Kontrol X1 |
69 | * Native Instruments Traktor Kontrol S4 | 69 | * Native Instruments Traktor Kontrol S4 |
70 | * Native Instruments Maschine Controller | ||
70 | 71 | ||
71 | To compile this driver as a module, choose M here: the module | 72 | To compile this driver as a module, choose M here: the module |
72 | will be called snd-usb-caiaq. | 73 | will be called snd-usb-caiaq. |
@@ -85,6 +86,7 @@ config SND_USB_CAIAQ_INPUT | |||
85 | * Native Instruments Kore Controller 2 | 86 | * Native Instruments Kore Controller 2 |
86 | * Native Instruments Audio Kontrol 1 | 87 | * Native Instruments Audio Kontrol 1 |
87 | * Native Instruments Traktor Kontrol S4 | 88 | * Native Instruments Traktor Kontrol S4 |
89 | * Native Instruments Maschine Controller | ||
88 | 90 | ||
89 | config SND_USB_US122L | 91 | config SND_USB_US122L |
90 | tristate "Tascam US-122L USB driver" | 92 | tristate "Tascam US-122L USB driver" |
diff --git a/sound/usb/Makefile b/sound/usb/Makefile index cf9ed66445fa..ac256dc4c6be 100644 --- a/sound/usb/Makefile +++ b/sound/usb/Makefile | |||
@@ -3,16 +3,16 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | snd-usb-audio-objs := card.o \ | 5 | snd-usb-audio-objs := card.o \ |
6 | clock.o \ | ||
7 | endpoint.o \ | ||
8 | format.o \ | ||
9 | helper.o \ | ||
6 | mixer.o \ | 10 | mixer.o \ |
7 | mixer_quirks.o \ | 11 | mixer_quirks.o \ |
12 | pcm.o \ | ||
8 | proc.o \ | 13 | proc.o \ |
9 | quirks.o \ | 14 | quirks.o \ |
10 | format.o \ | 15 | stream.o |
11 | endpoint.o \ | ||
12 | urb.o \ | ||
13 | pcm.o \ | ||
14 | helper.o \ | ||
15 | clock.o | ||
16 | 16 | ||
17 | snd-usbmidi-lib-objs := midi.o | 17 | snd-usbmidi-lib-objs := midi.o |
18 | 18 | ||
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c index 45bc4a2dc6f0..3eb605bd9503 100644 --- a/sound/usb/caiaq/device.c +++ b/sound/usb/caiaq/device.c | |||
@@ -50,7 +50,8 @@ MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2}," | |||
50 | "{Native Instruments, Session I/O}," | 50 | "{Native Instruments, Session I/O}," |
51 | "{Native Instruments, GuitarRig mobile}" | 51 | "{Native Instruments, GuitarRig mobile}" |
52 | "{Native Instruments, Traktor Kontrol X1}" | 52 | "{Native Instruments, Traktor Kontrol X1}" |
53 | "{Native Instruments, Traktor Kontrol S4}"); | 53 | "{Native Instruments, Traktor Kontrol S4}" |
54 | "{Native Instruments, Maschine Controller}"); | ||
54 | 55 | ||
55 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */ | 56 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */ |
56 | static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */ | 57 | static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */ |
@@ -146,6 +147,11 @@ static struct usb_device_id snd_usb_id_table[] = { | |||
146 | .idVendor = USB_VID_NATIVEINSTRUMENTS, | 147 | .idVendor = USB_VID_NATIVEINSTRUMENTS, |
147 | .idProduct = USB_PID_TRAKTORAUDIO2 | 148 | .idProduct = USB_PID_TRAKTORAUDIO2 |
148 | }, | 149 | }, |
150 | { | ||
151 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, | ||
152 | .idVendor = USB_VID_NATIVEINSTRUMENTS, | ||
153 | .idProduct = USB_PID_MASCHINECONTROLLER | ||
154 | }, | ||
149 | { /* terminator */ } | 155 | { /* terminator */ } |
150 | }; | 156 | }; |
151 | 157 | ||
diff --git a/sound/usb/caiaq/device.h b/sound/usb/caiaq/device.h index 3f9c6339ae90..562b0bff9c41 100644 --- a/sound/usb/caiaq/device.h +++ b/sound/usb/caiaq/device.h | |||
@@ -18,6 +18,7 @@ | |||
18 | #define USB_PID_TRAKTORKONTROLX1 0x2305 | 18 | #define USB_PID_TRAKTORKONTROLX1 0x2305 |
19 | #define USB_PID_TRAKTORKONTROLS4 0xbaff | 19 | #define USB_PID_TRAKTORKONTROLS4 0xbaff |
20 | #define USB_PID_TRAKTORAUDIO2 0x041d | 20 | #define USB_PID_TRAKTORAUDIO2 0x041d |
21 | #define USB_PID_MASCHINECONTROLLER 0x0808 | ||
21 | 22 | ||
22 | #define EP1_BUFSIZE 64 | 23 | #define EP1_BUFSIZE 64 |
23 | #define EP4_BUFSIZE 512 | 24 | #define EP4_BUFSIZE 512 |
diff --git a/sound/usb/caiaq/input.c b/sound/usb/caiaq/input.c index a213813487bd..26a121b42c3c 100644 --- a/sound/usb/caiaq/input.c +++ b/sound/usb/caiaq/input.c | |||
@@ -67,6 +67,61 @@ static unsigned short keycode_kore[] = { | |||
67 | KEY_BRL_DOT5 | 67 | KEY_BRL_DOT5 |
68 | }; | 68 | }; |
69 | 69 | ||
70 | #define MASCHINE_BUTTONS (42) | ||
71 | #define MASCHINE_BUTTON(X) ((X) + BTN_MISC) | ||
72 | #define MASCHINE_PADS (16) | ||
73 | #define MASCHINE_PAD(X) ((X) + ABS_PRESSURE) | ||
74 | |||
75 | static unsigned short keycode_maschine[] = { | ||
76 | MASCHINE_BUTTON(40), /* mute */ | ||
77 | MASCHINE_BUTTON(39), /* solo */ | ||
78 | MASCHINE_BUTTON(38), /* select */ | ||
79 | MASCHINE_BUTTON(37), /* duplicate */ | ||
80 | MASCHINE_BUTTON(36), /* navigate */ | ||
81 | MASCHINE_BUTTON(35), /* pad mode */ | ||
82 | MASCHINE_BUTTON(34), /* pattern */ | ||
83 | MASCHINE_BUTTON(33), /* scene */ | ||
84 | KEY_RESERVED, /* spacer */ | ||
85 | |||
86 | MASCHINE_BUTTON(30), /* rec */ | ||
87 | MASCHINE_BUTTON(31), /* erase */ | ||
88 | MASCHINE_BUTTON(32), /* shift */ | ||
89 | MASCHINE_BUTTON(28), /* grid */ | ||
90 | MASCHINE_BUTTON(27), /* > */ | ||
91 | MASCHINE_BUTTON(26), /* < */ | ||
92 | MASCHINE_BUTTON(25), /* restart */ | ||
93 | |||
94 | MASCHINE_BUTTON(21), /* E */ | ||
95 | MASCHINE_BUTTON(22), /* F */ | ||
96 | MASCHINE_BUTTON(23), /* G */ | ||
97 | MASCHINE_BUTTON(24), /* H */ | ||
98 | MASCHINE_BUTTON(20), /* D */ | ||
99 | MASCHINE_BUTTON(19), /* C */ | ||
100 | MASCHINE_BUTTON(18), /* B */ | ||
101 | MASCHINE_BUTTON(17), /* A */ | ||
102 | |||
103 | MASCHINE_BUTTON(0), /* control */ | ||
104 | MASCHINE_BUTTON(2), /* browse */ | ||
105 | MASCHINE_BUTTON(4), /* < */ | ||
106 | MASCHINE_BUTTON(6), /* snap */ | ||
107 | MASCHINE_BUTTON(7), /* autowrite */ | ||
108 | MASCHINE_BUTTON(5), /* > */ | ||
109 | MASCHINE_BUTTON(3), /* sampling */ | ||
110 | MASCHINE_BUTTON(1), /* step */ | ||
111 | |||
112 | MASCHINE_BUTTON(15), /* 8 softkeys */ | ||
113 | MASCHINE_BUTTON(14), | ||
114 | MASCHINE_BUTTON(13), | ||
115 | MASCHINE_BUTTON(12), | ||
116 | MASCHINE_BUTTON(11), | ||
117 | MASCHINE_BUTTON(10), | ||
118 | MASCHINE_BUTTON(9), | ||
119 | MASCHINE_BUTTON(8), | ||
120 | |||
121 | MASCHINE_BUTTON(16), /* note repeat */ | ||
122 | MASCHINE_BUTTON(29) /* play */ | ||
123 | }; | ||
124 | |||
70 | #define KONTROLX1_INPUTS (40) | 125 | #define KONTROLX1_INPUTS (40) |
71 | #define KONTROLS4_BUTTONS (12 * 8) | 126 | #define KONTROLS4_BUTTONS (12 * 8) |
72 | #define KONTROLS4_AXIS (46) | 127 | #define KONTROLS4_AXIS (46) |
@@ -218,6 +273,29 @@ static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev, | |||
218 | input_report_abs(input_dev, ABS_HAT3Y, i); | 273 | input_report_abs(input_dev, ABS_HAT3Y, i); |
219 | input_sync(input_dev); | 274 | input_sync(input_dev); |
220 | break; | 275 | break; |
276 | |||
277 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER): | ||
278 | /* 4 under the left screen */ | ||
279 | input_report_abs(input_dev, ABS_HAT0X, decode_erp(buf[21], buf[20])); | ||
280 | input_report_abs(input_dev, ABS_HAT0Y, decode_erp(buf[15], buf[14])); | ||
281 | input_report_abs(input_dev, ABS_HAT1X, decode_erp(buf[9], buf[8])); | ||
282 | input_report_abs(input_dev, ABS_HAT1Y, decode_erp(buf[3], buf[2])); | ||
283 | |||
284 | /* 4 under the right screen */ | ||
285 | input_report_abs(input_dev, ABS_HAT2X, decode_erp(buf[19], buf[18])); | ||
286 | input_report_abs(input_dev, ABS_HAT2Y, decode_erp(buf[13], buf[12])); | ||
287 | input_report_abs(input_dev, ABS_HAT3X, decode_erp(buf[7], buf[6])); | ||
288 | input_report_abs(input_dev, ABS_HAT3Y, decode_erp(buf[1], buf[0])); | ||
289 | |||
290 | /* volume */ | ||
291 | input_report_abs(input_dev, ABS_RX, decode_erp(buf[17], buf[16])); | ||
292 | /* tempo */ | ||
293 | input_report_abs(input_dev, ABS_RY, decode_erp(buf[11], buf[10])); | ||
294 | /* swing */ | ||
295 | input_report_abs(input_dev, ABS_RZ, decode_erp(buf[5], buf[4])); | ||
296 | |||
297 | input_sync(input_dev); | ||
298 | break; | ||
221 | } | 299 | } |
222 | } | 300 | } |
223 | 301 | ||
@@ -400,6 +478,25 @@ static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev *dev, | |||
400 | input_sync(dev->input_dev); | 478 | input_sync(dev->input_dev); |
401 | } | 479 | } |
402 | 480 | ||
481 | #define MASCHINE_MSGBLOCK_SIZE 2 | ||
482 | |||
483 | static void snd_usb_caiaq_maschine_dispatch(struct snd_usb_caiaqdev *dev, | ||
484 | const unsigned char *buf, | ||
485 | unsigned int len) | ||
486 | { | ||
487 | unsigned int i, pad_id; | ||
488 | uint16_t pressure; | ||
489 | |||
490 | for (i = 0; i < MASCHINE_PADS; i++) { | ||
491 | pressure = be16_to_cpu(buf[i * 2] << 8 | buf[(i * 2) + 1]); | ||
492 | pad_id = pressure >> 12; | ||
493 | |||
494 | input_report_abs(dev->input_dev, MASCHINE_PAD(pad_id), pressure & 0xfff); | ||
495 | } | ||
496 | |||
497 | input_sync(dev->input_dev); | ||
498 | } | ||
499 | |||
403 | static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb) | 500 | static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb) |
404 | { | 501 | { |
405 | struct snd_usb_caiaqdev *dev = urb->context; | 502 | struct snd_usb_caiaqdev *dev = urb->context; |
@@ -425,6 +522,13 @@ static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb) | |||
425 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): | 522 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): |
426 | snd_usb_caiaq_tks4_dispatch(dev, buf, urb->actual_length); | 523 | snd_usb_caiaq_tks4_dispatch(dev, buf, urb->actual_length); |
427 | break; | 524 | break; |
525 | |||
526 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER): | ||
527 | if (urb->actual_length < (MASCHINE_PADS * MASCHINE_MSGBLOCK_SIZE)) | ||
528 | goto requeue; | ||
529 | |||
530 | snd_usb_caiaq_maschine_dispatch(dev, buf, urb->actual_length); | ||
531 | break; | ||
428 | } | 532 | } |
429 | 533 | ||
430 | requeue: | 534 | requeue: |
@@ -444,6 +548,7 @@ static int snd_usb_caiaq_input_open(struct input_dev *idev) | |||
444 | switch (dev->chip.usb_id) { | 548 | switch (dev->chip.usb_id) { |
445 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): | 549 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): |
446 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): | 550 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): |
551 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER): | ||
447 | if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0) | 552 | if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0) |
448 | return -EIO; | 553 | return -EIO; |
449 | break; | 554 | break; |
@@ -462,6 +567,7 @@ static void snd_usb_caiaq_input_close(struct input_dev *idev) | |||
462 | switch (dev->chip.usb_id) { | 567 | switch (dev->chip.usb_id) { |
463 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): | 568 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): |
464 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): | 569 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): |
570 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER): | ||
465 | usb_kill_urb(dev->ep4_in_urb); | 571 | usb_kill_urb(dev->ep4_in_urb); |
466 | break; | 572 | break; |
467 | } | 573 | } |
@@ -652,6 +758,50 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev) | |||
652 | 758 | ||
653 | break; | 759 | break; |
654 | 760 | ||
761 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER): | ||
762 | input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); | ||
763 | input->absbit[0] = BIT_MASK(ABS_HAT0X) | BIT_MASK(ABS_HAT0Y) | | ||
764 | BIT_MASK(ABS_HAT1X) | BIT_MASK(ABS_HAT1Y) | | ||
765 | BIT_MASK(ABS_HAT2X) | BIT_MASK(ABS_HAT2Y) | | ||
766 | BIT_MASK(ABS_HAT3X) | BIT_MASK(ABS_HAT3Y) | | ||
767 | BIT_MASK(ABS_RX) | BIT_MASK(ABS_RY) | | ||
768 | BIT_MASK(ABS_RZ); | ||
769 | |||
770 | BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_maschine)); | ||
771 | memcpy(dev->keycode, keycode_maschine, sizeof(keycode_maschine)); | ||
772 | input->keycodemax = ARRAY_SIZE(keycode_maschine); | ||
773 | |||
774 | for (i = 0; i < MASCHINE_PADS; i++) { | ||
775 | input->absbit[0] |= MASCHINE_PAD(i); | ||
776 | input_set_abs_params(input, MASCHINE_PAD(i), 0, 0xfff, 5, 10); | ||
777 | } | ||
778 | |||
779 | input_set_abs_params(input, ABS_HAT0X, 0, 999, 0, 10); | ||
780 | input_set_abs_params(input, ABS_HAT0Y, 0, 999, 0, 10); | ||
781 | input_set_abs_params(input, ABS_HAT1X, 0, 999, 0, 10); | ||
782 | input_set_abs_params(input, ABS_HAT1Y, 0, 999, 0, 10); | ||
783 | input_set_abs_params(input, ABS_HAT2X, 0, 999, 0, 10); | ||
784 | input_set_abs_params(input, ABS_HAT2Y, 0, 999, 0, 10); | ||
785 | input_set_abs_params(input, ABS_HAT3X, 0, 999, 0, 10); | ||
786 | input_set_abs_params(input, ABS_HAT3Y, 0, 999, 0, 10); | ||
787 | input_set_abs_params(input, ABS_RX, 0, 999, 0, 10); | ||
788 | input_set_abs_params(input, ABS_RY, 0, 999, 0, 10); | ||
789 | input_set_abs_params(input, ABS_RZ, 0, 999, 0, 10); | ||
790 | |||
791 | dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
792 | if (!dev->ep4_in_urb) { | ||
793 | ret = -ENOMEM; | ||
794 | goto exit_free_idev; | ||
795 | } | ||
796 | |||
797 | usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev, | ||
798 | usb_rcvbulkpipe(usb_dev, 0x4), | ||
799 | dev->ep4_in_buf, EP4_BUFSIZE, | ||
800 | snd_usb_caiaq_ep4_reply_dispatch, dev); | ||
801 | |||
802 | snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5); | ||
803 | break; | ||
804 | |||
655 | default: | 805 | default: |
656 | /* no input methods supported on this device */ | 806 | /* no input methods supported on this device */ |
657 | goto exit_free_idev; | 807 | goto exit_free_idev; |
@@ -664,15 +814,17 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev) | |||
664 | for (i = 0; i < input->keycodemax; i++) | 814 | for (i = 0; i < input->keycodemax; i++) |
665 | __set_bit(dev->keycode[i], input->keybit); | 815 | __set_bit(dev->keycode[i], input->keybit); |
666 | 816 | ||
817 | dev->input_dev = input; | ||
818 | |||
667 | ret = input_register_device(input); | 819 | ret = input_register_device(input); |
668 | if (ret < 0) | 820 | if (ret < 0) |
669 | goto exit_free_idev; | 821 | goto exit_free_idev; |
670 | 822 | ||
671 | dev->input_dev = input; | ||
672 | return 0; | 823 | return 0; |
673 | 824 | ||
674 | exit_free_idev: | 825 | exit_free_idev: |
675 | input_free_device(input); | 826 | input_free_device(input); |
827 | dev->input_dev = NULL; | ||
676 | return ret; | 828 | return ret; |
677 | } | 829 | } |
678 | 830 | ||
@@ -688,4 +840,3 @@ void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *dev) | |||
688 | input_unregister_device(dev->input_dev); | 840 | input_unregister_device(dev->input_dev); |
689 | dev->input_dev = NULL; | 841 | dev->input_dev = NULL; |
690 | } | 842 | } |
691 | |||
diff --git a/sound/usb/card.c b/sound/usb/card.c index d8f2bf401458..c1575eafff12 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c | |||
@@ -65,9 +65,9 @@ | |||
65 | #include "helper.h" | 65 | #include "helper.h" |
66 | #include "debug.h" | 66 | #include "debug.h" |
67 | #include "pcm.h" | 67 | #include "pcm.h" |
68 | #include "urb.h" | ||
69 | #include "format.h" | 68 | #include "format.h" |
70 | #include "power.h" | 69 | #include "power.h" |
70 | #include "stream.h" | ||
71 | 71 | ||
72 | MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); | 72 | MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); |
73 | MODULE_DESCRIPTION("USB Audio"); | 73 | MODULE_DESCRIPTION("USB Audio"); |
@@ -185,7 +185,7 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int | |||
185 | return -EINVAL; | 185 | return -EINVAL; |
186 | } | 186 | } |
187 | 187 | ||
188 | if (! snd_usb_parse_audio_endpoints(chip, interface)) { | 188 | if (! snd_usb_parse_audio_interface(chip, interface)) { |
189 | usb_set_interface(dev, interface, 0); /* reset the current interface */ | 189 | usb_set_interface(dev, interface, 0); /* reset the current interface */ |
190 | usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L); | 190 | usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L); |
191 | return -EINVAL; | 191 | return -EINVAL; |
diff --git a/sound/usb/card.h b/sound/usb/card.h index ae4251d5abf7..a39edcc32a93 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h | |||
@@ -94,6 +94,8 @@ struct snd_usb_substream { | |||
94 | spinlock_t lock; | 94 | spinlock_t lock; |
95 | 95 | ||
96 | struct snd_urb_ops ops; /* callbacks (must be filled at init) */ | 96 | struct snd_urb_ops ops; /* callbacks (must be filled at init) */ |
97 | int last_frame_number; /* stored frame number */ | ||
98 | int last_delay; /* stored delay */ | ||
97 | }; | 99 | }; |
98 | 100 | ||
99 | struct snd_usb_stream { | 101 | struct snd_usb_stream { |
diff --git a/sound/usb/clock.c b/sound/usb/clock.c index 075195e8661a..379baad3d5ad 100644 --- a/sound/usb/clock.c +++ b/sound/usb/clock.c | |||
@@ -91,7 +91,7 @@ static int uac_clock_selector_get_val(struct snd_usb_audio *chip, int selector_i | |||
91 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, | 91 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, |
92 | UAC2_CX_CLOCK_SELECTOR << 8, | 92 | UAC2_CX_CLOCK_SELECTOR << 8, |
93 | snd_usb_ctrl_intf(chip) | (selector_id << 8), | 93 | snd_usb_ctrl_intf(chip) | (selector_id << 8), |
94 | &buf, sizeof(buf), 1000); | 94 | &buf, sizeof(buf)); |
95 | 95 | ||
96 | if (ret < 0) | 96 | if (ret < 0) |
97 | return ret; | 97 | return ret; |
@@ -118,7 +118,7 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id) | |||
118 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, | 118 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, |
119 | UAC2_CS_CONTROL_CLOCK_VALID << 8, | 119 | UAC2_CS_CONTROL_CLOCK_VALID << 8, |
120 | snd_usb_ctrl_intf(chip) | (source_id << 8), | 120 | snd_usb_ctrl_intf(chip) | (source_id << 8), |
121 | &data, sizeof(data), 1000); | 121 | &data, sizeof(data)); |
122 | 122 | ||
123 | if (err < 0) { | 123 | if (err < 0) { |
124 | snd_printk(KERN_WARNING "%s(): cannot get clock validity for id %d\n", | 124 | snd_printk(KERN_WARNING "%s(): cannot get clock validity for id %d\n", |
@@ -222,7 +222,7 @@ static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface, | |||
222 | if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, | 222 | if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, |
223 | USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT, | 223 | USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
224 | UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, | 224 | UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, |
225 | data, sizeof(data), 1000)) < 0) { | 225 | data, sizeof(data))) < 0) { |
226 | snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n", | 226 | snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n", |
227 | dev->devnum, iface, fmt->altsetting, rate, ep); | 227 | dev->devnum, iface, fmt->altsetting, rate, ep); |
228 | return err; | 228 | return err; |
@@ -231,7 +231,7 @@ static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface, | |||
231 | if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR, | 231 | if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR, |
232 | USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN, | 232 | USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN, |
233 | UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, | 233 | UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, |
234 | data, sizeof(data), 1000)) < 0) { | 234 | data, sizeof(data))) < 0) { |
235 | snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n", | 235 | snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n", |
236 | dev->devnum, iface, fmt->altsetting, ep); | 236 | dev->devnum, iface, fmt->altsetting, ep); |
237 | return 0; /* some devices don't support reading */ | 237 | return 0; /* some devices don't support reading */ |
@@ -273,7 +273,7 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, | |||
273 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT, | 273 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT, |
274 | UAC2_CS_CONTROL_SAM_FREQ << 8, | 274 | UAC2_CS_CONTROL_SAM_FREQ << 8, |
275 | snd_usb_ctrl_intf(chip) | (clock << 8), | 275 | snd_usb_ctrl_intf(chip) | (clock << 8), |
276 | data, sizeof(data), 1000)) < 0) { | 276 | data, sizeof(data))) < 0) { |
277 | snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2)\n", | 277 | snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2)\n", |
278 | dev->devnum, iface, fmt->altsetting, rate); | 278 | dev->devnum, iface, fmt->altsetting, rate); |
279 | return err; | 279 | return err; |
@@ -283,7 +283,7 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, | |||
283 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, | 283 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, |
284 | UAC2_CS_CONTROL_SAM_FREQ << 8, | 284 | UAC2_CS_CONTROL_SAM_FREQ << 8, |
285 | snd_usb_ctrl_intf(chip) | (clock << 8), | 285 | snd_usb_ctrl_intf(chip) | (clock << 8), |
286 | data, sizeof(data), 1000)) < 0) { | 286 | data, sizeof(data))) < 0) { |
287 | snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n", | 287 | snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n", |
288 | dev->devnum, iface, fmt->altsetting); | 288 | dev->devnum, iface, fmt->altsetting); |
289 | return err; | 289 | return err; |
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c index 7d46e482375d..81c6edecd862 100644 --- a/sound/usb/endpoint.c +++ b/sound/usb/endpoint.c | |||
@@ -15,436 +15,951 @@ | |||
15 | * | 15 | * |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <linux/gfp.h> | ||
18 | #include <linux/init.h> | 19 | #include <linux/init.h> |
19 | #include <linux/slab.h> | ||
20 | #include <linux/usb.h> | 20 | #include <linux/usb.h> |
21 | #include <linux/usb/audio.h> | 21 | #include <linux/usb/audio.h> |
22 | #include <linux/usb/audio-v2.h> | ||
23 | 22 | ||
24 | #include <sound/core.h> | 23 | #include <sound/core.h> |
25 | #include <sound/pcm.h> | 24 | #include <sound/pcm.h> |
26 | 25 | ||
27 | #include "usbaudio.h" | 26 | #include "usbaudio.h" |
27 | #include "helper.h" | ||
28 | #include "card.h" | 28 | #include "card.h" |
29 | #include "proc.h" | ||
30 | #include "quirks.h" | ||
31 | #include "endpoint.h" | 29 | #include "endpoint.h" |
32 | #include "urb.h" | ||
33 | #include "pcm.h" | 30 | #include "pcm.h" |
34 | #include "helper.h" | ||
35 | #include "format.h" | ||
36 | #include "clock.h" | ||
37 | 31 | ||
38 | /* | 32 | /* |
39 | * free a substream | 33 | * convert a sampling rate into our full speed format (fs/1000 in Q16.16) |
34 | * this will overflow at approx 524 kHz | ||
40 | */ | 35 | */ |
41 | static void free_substream(struct snd_usb_substream *subs) | 36 | static inline unsigned get_usb_full_speed_rate(unsigned int rate) |
42 | { | 37 | { |
43 | struct list_head *p, *n; | 38 | return ((rate << 13) + 62) / 125; |
44 | |||
45 | if (!subs->num_formats) | ||
46 | return; /* not initialized */ | ||
47 | list_for_each_safe(p, n, &subs->fmt_list) { | ||
48 | struct audioformat *fp = list_entry(p, struct audioformat, list); | ||
49 | kfree(fp->rate_table); | ||
50 | kfree(fp); | ||
51 | } | ||
52 | kfree(subs->rate_list.list); | ||
53 | } | 39 | } |
54 | 40 | ||
41 | /* | ||
42 | * convert a sampling rate into USB high speed format (fs/8000 in Q16.16) | ||
43 | * this will overflow at approx 4 MHz | ||
44 | */ | ||
45 | static inline unsigned get_usb_high_speed_rate(unsigned int rate) | ||
46 | { | ||
47 | return ((rate << 10) + 62) / 125; | ||
48 | } | ||
55 | 49 | ||
56 | /* | 50 | /* |
57 | * free a usb stream instance | 51 | * unlink active urbs. |
58 | */ | 52 | */ |
59 | static void snd_usb_audio_stream_free(struct snd_usb_stream *stream) | 53 | static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sleep) |
60 | { | 54 | { |
61 | free_substream(&stream->substream[0]); | 55 | struct snd_usb_audio *chip = subs->stream->chip; |
62 | free_substream(&stream->substream[1]); | 56 | unsigned int i; |
63 | list_del(&stream->list); | 57 | int async; |
64 | kfree(stream); | 58 | |
59 | subs->running = 0; | ||
60 | |||
61 | if (!force && subs->stream->chip->shutdown) /* to be sure... */ | ||
62 | return -EBADFD; | ||
63 | |||
64 | async = !can_sleep && chip->async_unlink; | ||
65 | |||
66 | if (!async && in_interrupt()) | ||
67 | return 0; | ||
68 | |||
69 | for (i = 0; i < subs->nurbs; i++) { | ||
70 | if (test_bit(i, &subs->active_mask)) { | ||
71 | if (!test_and_set_bit(i, &subs->unlink_mask)) { | ||
72 | struct urb *u = subs->dataurb[i].urb; | ||
73 | if (async) | ||
74 | usb_unlink_urb(u); | ||
75 | else | ||
76 | usb_kill_urb(u); | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | if (subs->syncpipe) { | ||
81 | for (i = 0; i < SYNC_URBS; i++) { | ||
82 | if (test_bit(i+16, &subs->active_mask)) { | ||
83 | if (!test_and_set_bit(i+16, &subs->unlink_mask)) { | ||
84 | struct urb *u = subs->syncurb[i].urb; | ||
85 | if (async) | ||
86 | usb_unlink_urb(u); | ||
87 | else | ||
88 | usb_kill_urb(u); | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | return 0; | ||
65 | } | 94 | } |
66 | 95 | ||
67 | static void snd_usb_audio_pcm_free(struct snd_pcm *pcm) | 96 | |
97 | /* | ||
98 | * release a urb data | ||
99 | */ | ||
100 | static void release_urb_ctx(struct snd_urb_ctx *u) | ||
68 | { | 101 | { |
69 | struct snd_usb_stream *stream = pcm->private_data; | 102 | if (u->urb) { |
70 | if (stream) { | 103 | if (u->buffer_size) |
71 | stream->pcm = NULL; | 104 | usb_free_coherent(u->subs->dev, u->buffer_size, |
72 | snd_usb_audio_stream_free(stream); | 105 | u->urb->transfer_buffer, |
106 | u->urb->transfer_dma); | ||
107 | usb_free_urb(u->urb); | ||
108 | u->urb = NULL; | ||
73 | } | 109 | } |
74 | } | 110 | } |
75 | 111 | ||
112 | /* | ||
113 | * wait until all urbs are processed. | ||
114 | */ | ||
115 | static int wait_clear_urbs(struct snd_usb_substream *subs) | ||
116 | { | ||
117 | unsigned long end_time = jiffies + msecs_to_jiffies(1000); | ||
118 | unsigned int i; | ||
119 | int alive; | ||
120 | |||
121 | do { | ||
122 | alive = 0; | ||
123 | for (i = 0; i < subs->nurbs; i++) { | ||
124 | if (test_bit(i, &subs->active_mask)) | ||
125 | alive++; | ||
126 | } | ||
127 | if (subs->syncpipe) { | ||
128 | for (i = 0; i < SYNC_URBS; i++) { | ||
129 | if (test_bit(i + 16, &subs->active_mask)) | ||
130 | alive++; | ||
131 | } | ||
132 | } | ||
133 | if (! alive) | ||
134 | break; | ||
135 | schedule_timeout_uninterruptible(1); | ||
136 | } while (time_before(jiffies, end_time)); | ||
137 | if (alive) | ||
138 | snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive); | ||
139 | return 0; | ||
140 | } | ||
76 | 141 | ||
77 | /* | 142 | /* |
78 | * add this endpoint to the chip instance. | 143 | * release a substream |
79 | * if a stream with the same endpoint already exists, append to it. | ||
80 | * if not, create a new pcm stream. | ||
81 | */ | 144 | */ |
82 | int snd_usb_add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct audioformat *fp) | 145 | void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force) |
83 | { | 146 | { |
84 | struct list_head *p; | 147 | int i; |
85 | struct snd_usb_stream *as; | 148 | |
86 | struct snd_usb_substream *subs; | 149 | /* stop urbs (to be sure) */ |
87 | struct snd_pcm *pcm; | 150 | deactivate_urbs(subs, force, 1); |
88 | int err; | 151 | wait_clear_urbs(subs); |
152 | |||
153 | for (i = 0; i < MAX_URBS; i++) | ||
154 | release_urb_ctx(&subs->dataurb[i]); | ||
155 | for (i = 0; i < SYNC_URBS; i++) | ||
156 | release_urb_ctx(&subs->syncurb[i]); | ||
157 | usb_free_coherent(subs->dev, SYNC_URBS * 4, | ||
158 | subs->syncbuf, subs->sync_dma); | ||
159 | subs->syncbuf = NULL; | ||
160 | subs->nurbs = 0; | ||
161 | } | ||
89 | 162 | ||
90 | list_for_each(p, &chip->pcm_list) { | 163 | /* |
91 | as = list_entry(p, struct snd_usb_stream, list); | 164 | * complete callback from data urb |
92 | if (as->fmt_type != fp->fmt_type) | 165 | */ |
93 | continue; | 166 | static void snd_complete_urb(struct urb *urb) |
94 | subs = &as->substream[stream]; | 167 | { |
95 | if (!subs->endpoint) | 168 | struct snd_urb_ctx *ctx = urb->context; |
96 | continue; | 169 | struct snd_usb_substream *subs = ctx->subs; |
97 | if (subs->endpoint == fp->endpoint) { | 170 | struct snd_pcm_substream *substream = ctx->subs->pcm_substream; |
98 | list_add_tail(&fp->list, &subs->fmt_list); | 171 | int err = 0; |
99 | subs->num_formats++; | 172 | |
100 | subs->formats |= fp->formats; | 173 | if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) || |
101 | return 0; | 174 | !subs->running || /* can be stopped during retire callback */ |
175 | (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 || | ||
176 | (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | ||
177 | clear_bit(ctx->index, &subs->active_mask); | ||
178 | if (err < 0) { | ||
179 | snd_printd(KERN_ERR "cannot submit urb (err = %d)\n", err); | ||
180 | snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); | ||
102 | } | 181 | } |
103 | } | 182 | } |
104 | /* look for an empty stream */ | 183 | } |
105 | list_for_each(p, &chip->pcm_list) { | 184 | |
106 | as = list_entry(p, struct snd_usb_stream, list); | 185 | |
107 | if (as->fmt_type != fp->fmt_type) | 186 | /* |
108 | continue; | 187 | * complete callback from sync urb |
109 | subs = &as->substream[stream]; | 188 | */ |
110 | if (subs->endpoint) | 189 | static void snd_complete_sync_urb(struct urb *urb) |
111 | continue; | 190 | { |
112 | err = snd_pcm_new_stream(as->pcm, stream, 1); | 191 | struct snd_urb_ctx *ctx = urb->context; |
113 | if (err < 0) | 192 | struct snd_usb_substream *subs = ctx->subs; |
114 | return err; | 193 | struct snd_pcm_substream *substream = ctx->subs->pcm_substream; |
115 | snd_usb_init_substream(as, stream, fp); | 194 | int err = 0; |
116 | return 0; | 195 | |
196 | if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) || | ||
197 | !subs->running || /* can be stopped during retire callback */ | ||
198 | (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 || | ||
199 | (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | ||
200 | clear_bit(ctx->index + 16, &subs->active_mask); | ||
201 | if (err < 0) { | ||
202 | snd_printd(KERN_ERR "cannot submit sync urb (err = %d)\n", err); | ||
203 | snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); | ||
204 | } | ||
117 | } | 205 | } |
206 | } | ||
207 | |||
118 | 208 | ||
119 | /* create a new pcm */ | 209 | /* |
120 | as = kzalloc(sizeof(*as), GFP_KERNEL); | 210 | * initialize a substream for plaback/capture |
121 | if (!as) | 211 | */ |
122 | return -ENOMEM; | 212 | int snd_usb_init_substream_urbs(struct snd_usb_substream *subs, |
123 | as->pcm_index = chip->pcm_devs; | 213 | unsigned int period_bytes, |
124 | as->chip = chip; | 214 | unsigned int rate, |
125 | as->fmt_type = fp->fmt_type; | 215 | unsigned int frame_bits) |
126 | err = snd_pcm_new(chip->card, "USB Audio", chip->pcm_devs, | 216 | { |
127 | stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : 0, | 217 | unsigned int maxsize, i; |
128 | stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1, | 218 | int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK; |
129 | &pcm); | 219 | unsigned int urb_packs, total_packs, packs_per_ms; |
130 | if (err < 0) { | 220 | struct snd_usb_audio *chip = subs->stream->chip; |
131 | kfree(as); | 221 | |
132 | return err; | 222 | /* calculate the frequency in 16.16 format */ |
223 | if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) | ||
224 | subs->freqn = get_usb_full_speed_rate(rate); | ||
225 | else | ||
226 | subs->freqn = get_usb_high_speed_rate(rate); | ||
227 | subs->freqm = subs->freqn; | ||
228 | subs->freqshift = INT_MIN; | ||
229 | /* calculate max. frequency */ | ||
230 | if (subs->maxpacksize) { | ||
231 | /* whatever fits into a max. size packet */ | ||
232 | maxsize = subs->maxpacksize; | ||
233 | subs->freqmax = (maxsize / (frame_bits >> 3)) | ||
234 | << (16 - subs->datainterval); | ||
235 | } else { | ||
236 | /* no max. packet size: just take 25% higher than nominal */ | ||
237 | subs->freqmax = subs->freqn + (subs->freqn >> 2); | ||
238 | maxsize = ((subs->freqmax + 0xffff) * (frame_bits >> 3)) | ||
239 | >> (16 - subs->datainterval); | ||
133 | } | 240 | } |
134 | as->pcm = pcm; | 241 | subs->phase = 0; |
135 | pcm->private_data = as; | 242 | |
136 | pcm->private_free = snd_usb_audio_pcm_free; | 243 | if (subs->fill_max) |
137 | pcm->info_flags = 0; | 244 | subs->curpacksize = subs->maxpacksize; |
138 | if (chip->pcm_devs > 0) | ||
139 | sprintf(pcm->name, "USB Audio #%d", chip->pcm_devs); | ||
140 | else | 245 | else |
141 | strcpy(pcm->name, "USB Audio"); | 246 | subs->curpacksize = maxsize; |
142 | 247 | ||
143 | snd_usb_init_substream(as, stream, fp); | 248 | if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL) |
249 | packs_per_ms = 8 >> subs->datainterval; | ||
250 | else | ||
251 | packs_per_ms = 1; | ||
252 | |||
253 | if (is_playback) { | ||
254 | urb_packs = max(chip->nrpacks, 1); | ||
255 | urb_packs = min(urb_packs, (unsigned int)MAX_PACKS); | ||
256 | } else | ||
257 | urb_packs = 1; | ||
258 | urb_packs *= packs_per_ms; | ||
259 | if (subs->syncpipe) | ||
260 | urb_packs = min(urb_packs, 1U << subs->syncinterval); | ||
261 | |||
262 | /* decide how many packets to be used */ | ||
263 | if (is_playback) { | ||
264 | unsigned int minsize, maxpacks; | ||
265 | /* determine how small a packet can be */ | ||
266 | minsize = (subs->freqn >> (16 - subs->datainterval)) | ||
267 | * (frame_bits >> 3); | ||
268 | /* with sync from device, assume it can be 12% lower */ | ||
269 | if (subs->syncpipe) | ||
270 | minsize -= minsize >> 3; | ||
271 | minsize = max(minsize, 1u); | ||
272 | total_packs = (period_bytes + minsize - 1) / minsize; | ||
273 | /* we need at least two URBs for queueing */ | ||
274 | if (total_packs < 2) { | ||
275 | total_packs = 2; | ||
276 | } else { | ||
277 | /* and we don't want too long a queue either */ | ||
278 | maxpacks = max(MAX_QUEUE * packs_per_ms, urb_packs * 2); | ||
279 | total_packs = min(total_packs, maxpacks); | ||
280 | } | ||
281 | } else { | ||
282 | while (urb_packs > 1 && urb_packs * maxsize >= period_bytes) | ||
283 | urb_packs >>= 1; | ||
284 | total_packs = MAX_URBS * urb_packs; | ||
285 | } | ||
286 | subs->nurbs = (total_packs + urb_packs - 1) / urb_packs; | ||
287 | if (subs->nurbs > MAX_URBS) { | ||
288 | /* too much... */ | ||
289 | subs->nurbs = MAX_URBS; | ||
290 | total_packs = MAX_URBS * urb_packs; | ||
291 | } else if (subs->nurbs < 2) { | ||
292 | /* too little - we need at least two packets | ||
293 | * to ensure contiguous playback/capture | ||
294 | */ | ||
295 | subs->nurbs = 2; | ||
296 | } | ||
144 | 297 | ||
145 | list_add(&as->list, &chip->pcm_list); | 298 | /* allocate and initialize data urbs */ |
146 | chip->pcm_devs++; | 299 | for (i = 0; i < subs->nurbs; i++) { |
300 | struct snd_urb_ctx *u = &subs->dataurb[i]; | ||
301 | u->index = i; | ||
302 | u->subs = subs; | ||
303 | u->packets = (i + 1) * total_packs / subs->nurbs | ||
304 | - i * total_packs / subs->nurbs; | ||
305 | u->buffer_size = maxsize * u->packets; | ||
306 | if (subs->fmt_type == UAC_FORMAT_TYPE_II) | ||
307 | u->packets++; /* for transfer delimiter */ | ||
308 | u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); | ||
309 | if (!u->urb) | ||
310 | goto out_of_memory; | ||
311 | u->urb->transfer_buffer = | ||
312 | usb_alloc_coherent(subs->dev, u->buffer_size, | ||
313 | GFP_KERNEL, &u->urb->transfer_dma); | ||
314 | if (!u->urb->transfer_buffer) | ||
315 | goto out_of_memory; | ||
316 | u->urb->pipe = subs->datapipe; | ||
317 | u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; | ||
318 | u->urb->interval = 1 << subs->datainterval; | ||
319 | u->urb->context = u; | ||
320 | u->urb->complete = snd_complete_urb; | ||
321 | } | ||
322 | |||
323 | if (subs->syncpipe) { | ||
324 | /* allocate and initialize sync urbs */ | ||
325 | subs->syncbuf = usb_alloc_coherent(subs->dev, SYNC_URBS * 4, | ||
326 | GFP_KERNEL, &subs->sync_dma); | ||
327 | if (!subs->syncbuf) | ||
328 | goto out_of_memory; | ||
329 | for (i = 0; i < SYNC_URBS; i++) { | ||
330 | struct snd_urb_ctx *u = &subs->syncurb[i]; | ||
331 | u->index = i; | ||
332 | u->subs = subs; | ||
333 | u->packets = 1; | ||
334 | u->urb = usb_alloc_urb(1, GFP_KERNEL); | ||
335 | if (!u->urb) | ||
336 | goto out_of_memory; | ||
337 | u->urb->transfer_buffer = subs->syncbuf + i * 4; | ||
338 | u->urb->transfer_dma = subs->sync_dma + i * 4; | ||
339 | u->urb->transfer_buffer_length = 4; | ||
340 | u->urb->pipe = subs->syncpipe; | ||
341 | u->urb->transfer_flags = URB_ISO_ASAP | | ||
342 | URB_NO_TRANSFER_DMA_MAP; | ||
343 | u->urb->number_of_packets = 1; | ||
344 | u->urb->interval = 1 << subs->syncinterval; | ||
345 | u->urb->context = u; | ||
346 | u->urb->complete = snd_complete_sync_urb; | ||
347 | } | ||
348 | } | ||
349 | return 0; | ||
147 | 350 | ||
148 | snd_usb_proc_pcm_format_add(as); | 351 | out_of_memory: |
352 | snd_usb_release_substream_urbs(subs, 0); | ||
353 | return -ENOMEM; | ||
354 | } | ||
149 | 355 | ||
356 | /* | ||
357 | * prepare urb for full speed capture sync pipe | ||
358 | * | ||
359 | * fill the length and offset of each urb descriptor. | ||
360 | * the fixed 10.14 frequency is passed through the pipe. | ||
361 | */ | ||
362 | static int prepare_capture_sync_urb(struct snd_usb_substream *subs, | ||
363 | struct snd_pcm_runtime *runtime, | ||
364 | struct urb *urb) | ||
365 | { | ||
366 | unsigned char *cp = urb->transfer_buffer; | ||
367 | struct snd_urb_ctx *ctx = urb->context; | ||
368 | |||
369 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | ||
370 | urb->iso_frame_desc[0].length = 3; | ||
371 | urb->iso_frame_desc[0].offset = 0; | ||
372 | cp[0] = subs->freqn >> 2; | ||
373 | cp[1] = subs->freqn >> 10; | ||
374 | cp[2] = subs->freqn >> 18; | ||
150 | return 0; | 375 | return 0; |
151 | } | 376 | } |
152 | 377 | ||
153 | static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip, | 378 | /* |
154 | struct usb_host_interface *alts, | 379 | * prepare urb for high speed capture sync pipe |
155 | int protocol, int iface_no) | 380 | * |
381 | * fill the length and offset of each urb descriptor. | ||
382 | * the fixed 12.13 frequency is passed as 16.16 through the pipe. | ||
383 | */ | ||
384 | static int prepare_capture_sync_urb_hs(struct snd_usb_substream *subs, | ||
385 | struct snd_pcm_runtime *runtime, | ||
386 | struct urb *urb) | ||
156 | { | 387 | { |
157 | /* parsed with a v1 header here. that's ok as we only look at the | 388 | unsigned char *cp = urb->transfer_buffer; |
158 | * header first which is the same for both versions */ | 389 | struct snd_urb_ctx *ctx = urb->context; |
159 | struct uac_iso_endpoint_descriptor *csep; | 390 | |
160 | struct usb_interface_descriptor *altsd = get_iface_desc(alts); | 391 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ |
161 | int attributes = 0; | 392 | urb->iso_frame_desc[0].length = 4; |
162 | 393 | urb->iso_frame_desc[0].offset = 0; | |
163 | csep = snd_usb_find_desc(alts->endpoint[0].extra, alts->endpoint[0].extralen, NULL, USB_DT_CS_ENDPOINT); | 394 | cp[0] = subs->freqn; |
164 | 395 | cp[1] = subs->freqn >> 8; | |
165 | /* Creamware Noah has this descriptor after the 2nd endpoint */ | 396 | cp[2] = subs->freqn >> 16; |
166 | if (!csep && altsd->bNumEndpoints >= 2) | 397 | cp[3] = subs->freqn >> 24; |
167 | csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT); | 398 | return 0; |
168 | 399 | } | |
169 | if (!csep || csep->bLength < 7 || | ||
170 | csep->bDescriptorSubtype != UAC_EP_GENERAL) { | ||
171 | snd_printk(KERN_WARNING "%d:%u:%d : no or invalid" | ||
172 | " class specific endpoint descriptor\n", | ||
173 | chip->dev->devnum, iface_no, | ||
174 | altsd->bAlternateSetting); | ||
175 | return 0; | ||
176 | } | ||
177 | 400 | ||
178 | if (protocol == UAC_VERSION_1) { | 401 | /* |
179 | attributes = csep->bmAttributes; | 402 | * process after capture sync complete |
180 | } else { | 403 | * - nothing to do |
181 | struct uac2_iso_endpoint_descriptor *csep2 = | 404 | */ |
182 | (struct uac2_iso_endpoint_descriptor *) csep; | 405 | static int retire_capture_sync_urb(struct snd_usb_substream *subs, |
406 | struct snd_pcm_runtime *runtime, | ||
407 | struct urb *urb) | ||
408 | { | ||
409 | return 0; | ||
410 | } | ||
183 | 411 | ||
184 | attributes = csep->bmAttributes & UAC_EP_CS_ATTR_FILL_MAX; | 412 | /* |
413 | * prepare urb for capture data pipe | ||
414 | * | ||
415 | * fill the offset and length of each descriptor. | ||
416 | * | ||
417 | * we use a temporary buffer to write the captured data. | ||
418 | * since the length of written data is determined by host, we cannot | ||
419 | * write onto the pcm buffer directly... the data is thus copied | ||
420 | * later at complete callback to the global buffer. | ||
421 | */ | ||
422 | static int prepare_capture_urb(struct snd_usb_substream *subs, | ||
423 | struct snd_pcm_runtime *runtime, | ||
424 | struct urb *urb) | ||
425 | { | ||
426 | int i, offs; | ||
427 | struct snd_urb_ctx *ctx = urb->context; | ||
428 | |||
429 | offs = 0; | ||
430 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | ||
431 | for (i = 0; i < ctx->packets; i++) { | ||
432 | urb->iso_frame_desc[i].offset = offs; | ||
433 | urb->iso_frame_desc[i].length = subs->curpacksize; | ||
434 | offs += subs->curpacksize; | ||
435 | } | ||
436 | urb->transfer_buffer_length = offs; | ||
437 | urb->number_of_packets = ctx->packets; | ||
438 | return 0; | ||
439 | } | ||
185 | 440 | ||
186 | /* emulate the endpoint attributes of a v1 device */ | 441 | /* |
187 | if (csep2->bmControls & UAC2_CONTROL_PITCH) | 442 | * process after capture complete |
188 | attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL; | 443 | * |
444 | * copy the data from each desctiptor to the pcm buffer, and | ||
445 | * update the current position. | ||
446 | */ | ||
447 | static int retire_capture_urb(struct snd_usb_substream *subs, | ||
448 | struct snd_pcm_runtime *runtime, | ||
449 | struct urb *urb) | ||
450 | { | ||
451 | unsigned long flags; | ||
452 | unsigned char *cp; | ||
453 | int i; | ||
454 | unsigned int stride, frames, bytes, oldptr; | ||
455 | int period_elapsed = 0; | ||
456 | |||
457 | stride = runtime->frame_bits >> 3; | ||
458 | |||
459 | for (i = 0; i < urb->number_of_packets; i++) { | ||
460 | cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset; | ||
461 | if (urb->iso_frame_desc[i].status) { | ||
462 | snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status); | ||
463 | // continue; | ||
464 | } | ||
465 | bytes = urb->iso_frame_desc[i].actual_length; | ||
466 | frames = bytes / stride; | ||
467 | if (!subs->txfr_quirk) | ||
468 | bytes = frames * stride; | ||
469 | if (bytes % (runtime->sample_bits >> 3) != 0) { | ||
470 | #ifdef CONFIG_SND_DEBUG_VERBOSE | ||
471 | int oldbytes = bytes; | ||
472 | #endif | ||
473 | bytes = frames * stride; | ||
474 | snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n", | ||
475 | oldbytes, bytes); | ||
476 | } | ||
477 | /* update the current pointer */ | ||
478 | spin_lock_irqsave(&subs->lock, flags); | ||
479 | oldptr = subs->hwptr_done; | ||
480 | subs->hwptr_done += bytes; | ||
481 | if (subs->hwptr_done >= runtime->buffer_size * stride) | ||
482 | subs->hwptr_done -= runtime->buffer_size * stride; | ||
483 | frames = (bytes + (oldptr % stride)) / stride; | ||
484 | subs->transfer_done += frames; | ||
485 | if (subs->transfer_done >= runtime->period_size) { | ||
486 | subs->transfer_done -= runtime->period_size; | ||
487 | period_elapsed = 1; | ||
488 | } | ||
489 | spin_unlock_irqrestore(&subs->lock, flags); | ||
490 | /* copy a data chunk */ | ||
491 | if (oldptr + bytes > runtime->buffer_size * stride) { | ||
492 | unsigned int bytes1 = | ||
493 | runtime->buffer_size * stride - oldptr; | ||
494 | memcpy(runtime->dma_area + oldptr, cp, bytes1); | ||
495 | memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1); | ||
496 | } else { | ||
497 | memcpy(runtime->dma_area + oldptr, cp, bytes); | ||
498 | } | ||
189 | } | 499 | } |
500 | if (period_elapsed) | ||
501 | snd_pcm_period_elapsed(subs->pcm_substream); | ||
502 | return 0; | ||
503 | } | ||
190 | 504 | ||
191 | return attributes; | 505 | /* |
506 | * Process after capture complete when paused. Nothing to do. | ||
507 | */ | ||
508 | static int retire_paused_capture_urb(struct snd_usb_substream *subs, | ||
509 | struct snd_pcm_runtime *runtime, | ||
510 | struct urb *urb) | ||
511 | { | ||
512 | return 0; | ||
192 | } | 513 | } |
193 | 514 | ||
194 | static struct uac2_input_terminal_descriptor * | 515 | |
195 | snd_usb_find_input_terminal_descriptor(struct usb_host_interface *ctrl_iface, | 516 | /* |
196 | int terminal_id) | 517 | * prepare urb for playback sync pipe |
518 | * | ||
519 | * set up the offset and length to receive the current frequency. | ||
520 | */ | ||
521 | static int prepare_playback_sync_urb(struct snd_usb_substream *subs, | ||
522 | struct snd_pcm_runtime *runtime, | ||
523 | struct urb *urb) | ||
197 | { | 524 | { |
198 | struct uac2_input_terminal_descriptor *term = NULL; | 525 | struct snd_urb_ctx *ctx = urb->context; |
526 | |||
527 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | ||
528 | urb->iso_frame_desc[0].length = min(4u, ctx->subs->syncmaxsize); | ||
529 | urb->iso_frame_desc[0].offset = 0; | ||
530 | return 0; | ||
531 | } | ||
199 | 532 | ||
200 | while ((term = snd_usb_find_csint_desc(ctrl_iface->extra, | 533 | /* |
201 | ctrl_iface->extralen, | 534 | * process after playback sync complete |
202 | term, UAC_INPUT_TERMINAL))) { | 535 | * |
203 | if (term->bTerminalID == terminal_id) | 536 | * Full speed devices report feedback values in 10.14 format as samples per |
204 | return term; | 537 | * frame, high speed devices in 16.16 format as samples per microframe. |
538 | * Because the Audio Class 1 spec was written before USB 2.0, many high speed | ||
539 | * devices use a wrong interpretation, some others use an entirely different | ||
540 | * format. Therefore, we cannot predict what format any particular device uses | ||
541 | * and must detect it automatically. | ||
542 | */ | ||
543 | static int retire_playback_sync_urb(struct snd_usb_substream *subs, | ||
544 | struct snd_pcm_runtime *runtime, | ||
545 | struct urb *urb) | ||
546 | { | ||
547 | unsigned int f; | ||
548 | int shift; | ||
549 | unsigned long flags; | ||
550 | |||
551 | if (urb->iso_frame_desc[0].status != 0 || | ||
552 | urb->iso_frame_desc[0].actual_length < 3) | ||
553 | return 0; | ||
554 | |||
555 | f = le32_to_cpup(urb->transfer_buffer); | ||
556 | if (urb->iso_frame_desc[0].actual_length == 3) | ||
557 | f &= 0x00ffffff; | ||
558 | else | ||
559 | f &= 0x0fffffff; | ||
560 | if (f == 0) | ||
561 | return 0; | ||
562 | |||
563 | if (unlikely(subs->freqshift == INT_MIN)) { | ||
564 | /* | ||
565 | * The first time we see a feedback value, determine its format | ||
566 | * by shifting it left or right until it matches the nominal | ||
567 | * frequency value. This assumes that the feedback does not | ||
568 | * differ from the nominal value more than +50% or -25%. | ||
569 | */ | ||
570 | shift = 0; | ||
571 | while (f < subs->freqn - subs->freqn / 4) { | ||
572 | f <<= 1; | ||
573 | shift++; | ||
574 | } | ||
575 | while (f > subs->freqn + subs->freqn / 2) { | ||
576 | f >>= 1; | ||
577 | shift--; | ||
578 | } | ||
579 | subs->freqshift = shift; | ||
580 | } | ||
581 | else if (subs->freqshift >= 0) | ||
582 | f <<= subs->freqshift; | ||
583 | else | ||
584 | f >>= -subs->freqshift; | ||
585 | |||
586 | if (likely(f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax)) { | ||
587 | /* | ||
588 | * If the frequency looks valid, set it. | ||
589 | * This value is referred to in prepare_playback_urb(). | ||
590 | */ | ||
591 | spin_lock_irqsave(&subs->lock, flags); | ||
592 | subs->freqm = f; | ||
593 | spin_unlock_irqrestore(&subs->lock, flags); | ||
594 | } else { | ||
595 | /* | ||
596 | * Out of range; maybe the shift value is wrong. | ||
597 | * Reset it so that we autodetect again the next time. | ||
598 | */ | ||
599 | subs->freqshift = INT_MIN; | ||
205 | } | 600 | } |
206 | 601 | ||
207 | return NULL; | 602 | return 0; |
208 | } | 603 | } |
209 | 604 | ||
210 | static struct uac2_output_terminal_descriptor * | 605 | /* determine the number of frames in the next packet */ |
211 | snd_usb_find_output_terminal_descriptor(struct usb_host_interface *ctrl_iface, | 606 | static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs) |
212 | int terminal_id) | ||
213 | { | 607 | { |
214 | struct uac2_output_terminal_descriptor *term = NULL; | 608 | if (subs->fill_max) |
215 | 609 | return subs->maxframesize; | |
216 | while ((term = snd_usb_find_csint_desc(ctrl_iface->extra, | 610 | else { |
217 | ctrl_iface->extralen, | 611 | subs->phase = (subs->phase & 0xffff) |
218 | term, UAC_OUTPUT_TERMINAL))) { | 612 | + (subs->freqm << subs->datainterval); |
219 | if (term->bTerminalID == terminal_id) | 613 | return min(subs->phase >> 16, subs->maxframesize); |
220 | return term; | ||
221 | } | 614 | } |
615 | } | ||
222 | 616 | ||
223 | return NULL; | 617 | /* |
618 | * Prepare urb for streaming before playback starts or when paused. | ||
619 | * | ||
620 | * We don't have any data, so we send silence. | ||
621 | */ | ||
622 | static int prepare_nodata_playback_urb(struct snd_usb_substream *subs, | ||
623 | struct snd_pcm_runtime *runtime, | ||
624 | struct urb *urb) | ||
625 | { | ||
626 | unsigned int i, offs, counts; | ||
627 | struct snd_urb_ctx *ctx = urb->context; | ||
628 | int stride = runtime->frame_bits >> 3; | ||
629 | |||
630 | offs = 0; | ||
631 | urb->dev = ctx->subs->dev; | ||
632 | for (i = 0; i < ctx->packets; ++i) { | ||
633 | counts = snd_usb_audio_next_packet_size(subs); | ||
634 | urb->iso_frame_desc[i].offset = offs * stride; | ||
635 | urb->iso_frame_desc[i].length = counts * stride; | ||
636 | offs += counts; | ||
637 | } | ||
638 | urb->number_of_packets = ctx->packets; | ||
639 | urb->transfer_buffer_length = offs * stride; | ||
640 | memset(urb->transfer_buffer, | ||
641 | runtime->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0, | ||
642 | offs * stride); | ||
643 | return 0; | ||
224 | } | 644 | } |
225 | 645 | ||
226 | int snd_usb_parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no) | 646 | /* |
647 | * prepare urb for playback data pipe | ||
648 | * | ||
649 | * Since a URB can handle only a single linear buffer, we must use double | ||
650 | * buffering when the data to be transferred overflows the buffer boundary. | ||
651 | * To avoid inconsistencies when updating hwptr_done, we use double buffering | ||
652 | * for all URBs. | ||
653 | */ | ||
654 | static int prepare_playback_urb(struct snd_usb_substream *subs, | ||
655 | struct snd_pcm_runtime *runtime, | ||
656 | struct urb *urb) | ||
227 | { | 657 | { |
228 | struct usb_device *dev; | 658 | int i, stride; |
229 | struct usb_interface *iface; | 659 | unsigned int counts, frames, bytes; |
230 | struct usb_host_interface *alts; | 660 | unsigned long flags; |
231 | struct usb_interface_descriptor *altsd; | 661 | int period_elapsed = 0; |
232 | int i, altno, err, stream; | 662 | struct snd_urb_ctx *ctx = urb->context; |
233 | int format = 0, num_channels = 0; | 663 | |
234 | struct audioformat *fp = NULL; | 664 | stride = runtime->frame_bits >> 3; |
235 | int num, protocol, clock = 0; | 665 | |
236 | struct uac_format_type_i_continuous_descriptor *fmt; | 666 | frames = 0; |
667 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | ||
668 | urb->number_of_packets = 0; | ||
669 | spin_lock_irqsave(&subs->lock, flags); | ||
670 | for (i = 0; i < ctx->packets; i++) { | ||
671 | counts = snd_usb_audio_next_packet_size(subs); | ||
672 | /* set up descriptor */ | ||
673 | urb->iso_frame_desc[i].offset = frames * stride; | ||
674 | urb->iso_frame_desc[i].length = counts * stride; | ||
675 | frames += counts; | ||
676 | urb->number_of_packets++; | ||
677 | subs->transfer_done += counts; | ||
678 | if (subs->transfer_done >= runtime->period_size) { | ||
679 | subs->transfer_done -= runtime->period_size; | ||
680 | period_elapsed = 1; | ||
681 | if (subs->fmt_type == UAC_FORMAT_TYPE_II) { | ||
682 | if (subs->transfer_done > 0) { | ||
683 | /* FIXME: fill-max mode is not | ||
684 | * supported yet */ | ||
685 | frames -= subs->transfer_done; | ||
686 | counts -= subs->transfer_done; | ||
687 | urb->iso_frame_desc[i].length = | ||
688 | counts * stride; | ||
689 | subs->transfer_done = 0; | ||
690 | } | ||
691 | i++; | ||
692 | if (i < ctx->packets) { | ||
693 | /* add a transfer delimiter */ | ||
694 | urb->iso_frame_desc[i].offset = | ||
695 | frames * stride; | ||
696 | urb->iso_frame_desc[i].length = 0; | ||
697 | urb->number_of_packets++; | ||
698 | } | ||
699 | break; | ||
700 | } | ||
701 | } | ||
702 | if (period_elapsed) /* finish at the period boundary */ | ||
703 | break; | ||
704 | } | ||
705 | bytes = frames * stride; | ||
706 | if (subs->hwptr_done + bytes > runtime->buffer_size * stride) { | ||
707 | /* err, the transferred area goes over buffer boundary. */ | ||
708 | unsigned int bytes1 = | ||
709 | runtime->buffer_size * stride - subs->hwptr_done; | ||
710 | memcpy(urb->transfer_buffer, | ||
711 | runtime->dma_area + subs->hwptr_done, bytes1); | ||
712 | memcpy(urb->transfer_buffer + bytes1, | ||
713 | runtime->dma_area, bytes - bytes1); | ||
714 | } else { | ||
715 | memcpy(urb->transfer_buffer, | ||
716 | runtime->dma_area + subs->hwptr_done, bytes); | ||
717 | } | ||
718 | subs->hwptr_done += bytes; | ||
719 | if (subs->hwptr_done >= runtime->buffer_size * stride) | ||
720 | subs->hwptr_done -= runtime->buffer_size * stride; | ||
721 | |||
722 | /* update delay with exact number of samples queued */ | ||
723 | runtime->delay = subs->last_delay; | ||
724 | runtime->delay += frames; | ||
725 | subs->last_delay = runtime->delay; | ||
726 | |||
727 | /* realign last_frame_number */ | ||
728 | subs->last_frame_number = usb_get_current_frame_number(subs->dev); | ||
729 | subs->last_frame_number &= 0xFF; /* keep 8 LSBs */ | ||
730 | |||
731 | spin_unlock_irqrestore(&subs->lock, flags); | ||
732 | urb->transfer_buffer_length = bytes; | ||
733 | if (period_elapsed) | ||
734 | snd_pcm_period_elapsed(subs->pcm_substream); | ||
735 | return 0; | ||
736 | } | ||
237 | 737 | ||
238 | dev = chip->dev; | 738 | /* |
739 | * process after playback data complete | ||
740 | * - decrease the delay count again | ||
741 | */ | ||
742 | static int retire_playback_urb(struct snd_usb_substream *subs, | ||
743 | struct snd_pcm_runtime *runtime, | ||
744 | struct urb *urb) | ||
745 | { | ||
746 | unsigned long flags; | ||
747 | int stride = runtime->frame_bits >> 3; | ||
748 | int processed = urb->transfer_buffer_length / stride; | ||
749 | int est_delay; | ||
239 | 750 | ||
240 | /* parse the interface's altsettings */ | 751 | spin_lock_irqsave(&subs->lock, flags); |
241 | iface = usb_ifnum_to_if(dev, iface_no); | ||
242 | 752 | ||
243 | num = iface->num_altsetting; | 753 | est_delay = snd_usb_pcm_delay(subs, runtime->rate); |
754 | /* update delay with exact number of samples played */ | ||
755 | if (processed > subs->last_delay) | ||
756 | subs->last_delay = 0; | ||
757 | else | ||
758 | subs->last_delay -= processed; | ||
759 | runtime->delay = subs->last_delay; | ||
244 | 760 | ||
245 | /* | 761 | /* |
246 | * Dallas DS4201 workaround: It presents 5 altsettings, but the last | 762 | * Report when delay estimate is off by more than 2ms. |
247 | * one misses syncpipe, and does not produce any sound. | 763 | * The error should be lower than 2ms since the estimate relies |
764 | * on two reads of a counter updated every ms. | ||
248 | */ | 765 | */ |
249 | if (chip->usb_id == USB_ID(0x04fa, 0x4201)) | 766 | if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2) |
250 | num = 4; | 767 | snd_printk(KERN_DEBUG "delay: estimated %d, actual %d\n", |
251 | 768 | est_delay, subs->last_delay); | |
252 | for (i = 0; i < num; i++) { | ||
253 | alts = &iface->altsetting[i]; | ||
254 | altsd = get_iface_desc(alts); | ||
255 | protocol = altsd->bInterfaceProtocol; | ||
256 | /* skip invalid one */ | ||
257 | if ((altsd->bInterfaceClass != USB_CLASS_AUDIO && | ||
258 | altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) || | ||
259 | (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING && | ||
260 | altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) || | ||
261 | altsd->bNumEndpoints < 1 || | ||
262 | le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0) | ||
263 | continue; | ||
264 | /* must be isochronous */ | ||
265 | if ((get_endpoint(alts, 0)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != | ||
266 | USB_ENDPOINT_XFER_ISOC) | ||
267 | continue; | ||
268 | /* check direction */ | ||
269 | stream = (get_endpoint(alts, 0)->bEndpointAddress & USB_DIR_IN) ? | ||
270 | SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; | ||
271 | altno = altsd->bAlternateSetting; | ||
272 | |||
273 | if (snd_usb_apply_interface_quirk(chip, iface_no, altno)) | ||
274 | continue; | ||
275 | |||
276 | /* get audio formats */ | ||
277 | switch (protocol) { | ||
278 | default: | ||
279 | snd_printdd(KERN_WARNING "%d:%u:%d: unknown interface protocol %#02x, assuming v1\n", | ||
280 | dev->devnum, iface_no, altno, protocol); | ||
281 | protocol = UAC_VERSION_1; | ||
282 | /* fall through */ | ||
283 | |||
284 | case UAC_VERSION_1: { | ||
285 | struct uac1_as_header_descriptor *as = | ||
286 | snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL); | ||
287 | |||
288 | if (!as) { | ||
289 | snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n", | ||
290 | dev->devnum, iface_no, altno); | ||
291 | continue; | ||
292 | } | ||
293 | 769 | ||
294 | if (as->bLength < sizeof(*as)) { | 770 | spin_unlock_irqrestore(&subs->lock, flags); |
295 | snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n", | 771 | return 0; |
296 | dev->devnum, iface_no, altno); | 772 | } |
297 | continue; | ||
298 | } | ||
299 | 773 | ||
300 | format = le16_to_cpu(as->wFormatTag); /* remember the format value */ | 774 | static const char *usb_error_string(int err) |
301 | break; | 775 | { |
302 | } | 776 | switch (err) { |
777 | case -ENODEV: | ||
778 | return "no device"; | ||
779 | case -ENOENT: | ||
780 | return "endpoint not enabled"; | ||
781 | case -EPIPE: | ||
782 | return "endpoint stalled"; | ||
783 | case -ENOSPC: | ||
784 | return "not enough bandwidth"; | ||
785 | case -ESHUTDOWN: | ||
786 | return "device disabled"; | ||
787 | case -EHOSTUNREACH: | ||
788 | return "device suspended"; | ||
789 | case -EINVAL: | ||
790 | case -EAGAIN: | ||
791 | case -EFBIG: | ||
792 | case -EMSGSIZE: | ||
793 | return "internal error"; | ||
794 | default: | ||
795 | return "unknown error"; | ||
796 | } | ||
797 | } | ||
303 | 798 | ||
304 | case UAC_VERSION_2: { | 799 | /* |
305 | struct uac2_input_terminal_descriptor *input_term; | 800 | * set up and start data/sync urbs |
306 | struct uac2_output_terminal_descriptor *output_term; | 801 | */ |
307 | struct uac2_as_header_descriptor *as = | 802 | static int start_urbs(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime) |
308 | snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL); | 803 | { |
804 | unsigned int i; | ||
805 | int err; | ||
309 | 806 | ||
310 | if (!as) { | 807 | if (subs->stream->chip->shutdown) |
311 | snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n", | 808 | return -EBADFD; |
312 | dev->devnum, iface_no, altno); | 809 | |
313 | continue; | 810 | for (i = 0; i < subs->nurbs; i++) { |
811 | if (snd_BUG_ON(!subs->dataurb[i].urb)) | ||
812 | return -EINVAL; | ||
813 | if (subs->ops.prepare(subs, runtime, subs->dataurb[i].urb) < 0) { | ||
814 | snd_printk(KERN_ERR "cannot prepare datapipe for urb %d\n", i); | ||
815 | goto __error; | ||
816 | } | ||
817 | } | ||
818 | if (subs->syncpipe) { | ||
819 | for (i = 0; i < SYNC_URBS; i++) { | ||
820 | if (snd_BUG_ON(!subs->syncurb[i].urb)) | ||
821 | return -EINVAL; | ||
822 | if (subs->ops.prepare_sync(subs, runtime, subs->syncurb[i].urb) < 0) { | ||
823 | snd_printk(KERN_ERR "cannot prepare syncpipe for urb %d\n", i); | ||
824 | goto __error; | ||
314 | } | 825 | } |
826 | } | ||
827 | } | ||
315 | 828 | ||
316 | if (as->bLength < sizeof(*as)) { | 829 | subs->active_mask = 0; |
317 | snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n", | 830 | subs->unlink_mask = 0; |
318 | dev->devnum, iface_no, altno); | 831 | subs->running = 1; |
319 | continue; | 832 | for (i = 0; i < subs->nurbs; i++) { |
833 | err = usb_submit_urb(subs->dataurb[i].urb, GFP_ATOMIC); | ||
834 | if (err < 0) { | ||
835 | snd_printk(KERN_ERR "cannot submit datapipe " | ||
836 | "for urb %d, error %d: %s\n", | ||
837 | i, err, usb_error_string(err)); | ||
838 | goto __error; | ||
839 | } | ||
840 | set_bit(i, &subs->active_mask); | ||
841 | } | ||
842 | if (subs->syncpipe) { | ||
843 | for (i = 0; i < SYNC_URBS; i++) { | ||
844 | err = usb_submit_urb(subs->syncurb[i].urb, GFP_ATOMIC); | ||
845 | if (err < 0) { | ||
846 | snd_printk(KERN_ERR "cannot submit syncpipe " | ||
847 | "for urb %d, error %d: %s\n", | ||
848 | i, err, usb_error_string(err)); | ||
849 | goto __error; | ||
320 | } | 850 | } |
851 | set_bit(i + 16, &subs->active_mask); | ||
852 | } | ||
853 | } | ||
854 | return 0; | ||
321 | 855 | ||
322 | num_channels = as->bNrChannels; | 856 | __error: |
323 | format = le32_to_cpu(as->bmFormats); | 857 | // snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN); |
858 | deactivate_urbs(subs, 0, 0); | ||
859 | return -EPIPE; | ||
860 | } | ||
324 | 861 | ||
325 | /* lookup the terminal associated to this interface | ||
326 | * to extract the clock */ | ||
327 | input_term = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf, | ||
328 | as->bTerminalLink); | ||
329 | if (input_term) { | ||
330 | clock = input_term->bCSourceID; | ||
331 | break; | ||
332 | } | ||
333 | 862 | ||
334 | output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf, | 863 | /* |
335 | as->bTerminalLink); | 864 | */ |
336 | if (output_term) { | 865 | static struct snd_urb_ops audio_urb_ops[2] = { |
337 | clock = output_term->bCSourceID; | 866 | { |
338 | break; | 867 | .prepare = prepare_nodata_playback_urb, |
339 | } | 868 | .retire = retire_playback_urb, |
869 | .prepare_sync = prepare_playback_sync_urb, | ||
870 | .retire_sync = retire_playback_sync_urb, | ||
871 | }, | ||
872 | { | ||
873 | .prepare = prepare_capture_urb, | ||
874 | .retire = retire_capture_urb, | ||
875 | .prepare_sync = prepare_capture_sync_urb, | ||
876 | .retire_sync = retire_capture_sync_urb, | ||
877 | }, | ||
878 | }; | ||
340 | 879 | ||
341 | snd_printk(KERN_ERR "%d:%u:%d : bogus bTerminalLink %d\n", | 880 | /* |
342 | dev->devnum, iface_no, altno, as->bTerminalLink); | 881 | * initialize the substream instance. |
343 | continue; | 882 | */ |
344 | } | ||
345 | } | ||
346 | 883 | ||
347 | /* get format type */ | 884 | void snd_usb_init_substream(struct snd_usb_stream *as, |
348 | fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE); | 885 | int stream, struct audioformat *fp) |
349 | if (!fmt) { | 886 | { |
350 | snd_printk(KERN_ERR "%d:%u:%d : no UAC_FORMAT_TYPE desc\n", | 887 | struct snd_usb_substream *subs = &as->substream[stream]; |
351 | dev->devnum, iface_no, altno); | 888 | |
352 | continue; | 889 | INIT_LIST_HEAD(&subs->fmt_list); |
353 | } | 890 | spin_lock_init(&subs->lock); |
354 | if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8)) || | 891 | |
355 | ((protocol == UAC_VERSION_2) && (fmt->bLength < 6))) { | 892 | subs->stream = as; |
356 | snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n", | 893 | subs->direction = stream; |
357 | dev->devnum, iface_no, altno); | 894 | subs->dev = as->chip->dev; |
358 | continue; | 895 | subs->txfr_quirk = as->chip->txfr_quirk; |
359 | } | 896 | subs->ops = audio_urb_ops[stream]; |
897 | if (snd_usb_get_speed(subs->dev) >= USB_SPEED_HIGH) | ||
898 | subs->ops.prepare_sync = prepare_capture_sync_urb_hs; | ||
899 | |||
900 | snd_usb_set_pcm_ops(as->pcm, stream); | ||
901 | |||
902 | list_add_tail(&fp->list, &subs->fmt_list); | ||
903 | subs->formats |= fp->formats; | ||
904 | subs->endpoint = fp->endpoint; | ||
905 | subs->num_formats++; | ||
906 | subs->fmt_type = fp->fmt_type; | ||
907 | } | ||
360 | 908 | ||
361 | /* | 909 | int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd) |
362 | * Blue Microphones workaround: The last altsetting is identical | 910 | { |
363 | * with the previous one, except for a larger packet size, but | 911 | struct snd_usb_substream *subs = substream->runtime->private_data; |
364 | * is actually a mislabeled two-channel setting; ignore it. | ||
365 | */ | ||
366 | if (fmt->bNrChannels == 1 && | ||
367 | fmt->bSubframeSize == 2 && | ||
368 | altno == 2 && num == 3 && | ||
369 | fp && fp->altsetting == 1 && fp->channels == 1 && | ||
370 | fp->formats == SNDRV_PCM_FMTBIT_S16_LE && | ||
371 | protocol == UAC_VERSION_1 && | ||
372 | le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == | ||
373 | fp->maxpacksize * 2) | ||
374 | continue; | ||
375 | |||
376 | fp = kzalloc(sizeof(*fp), GFP_KERNEL); | ||
377 | if (! fp) { | ||
378 | snd_printk(KERN_ERR "cannot malloc\n"); | ||
379 | return -ENOMEM; | ||
380 | } | ||
381 | 912 | ||
382 | fp->iface = iface_no; | 913 | switch (cmd) { |
383 | fp->altsetting = altno; | 914 | case SNDRV_PCM_TRIGGER_START: |
384 | fp->altset_idx = i; | 915 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
385 | fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress; | 916 | subs->ops.prepare = prepare_playback_urb; |
386 | fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; | 917 | return 0; |
387 | fp->datainterval = snd_usb_parse_datainterval(chip, alts); | 918 | case SNDRV_PCM_TRIGGER_STOP: |
388 | fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); | 919 | return deactivate_urbs(subs, 0, 0); |
389 | /* num_channels is only set for v2 interfaces */ | 920 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
390 | fp->channels = num_channels; | 921 | subs->ops.prepare = prepare_nodata_playback_urb; |
391 | if (snd_usb_get_speed(dev) == USB_SPEED_HIGH) | 922 | return 0; |
392 | fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1) | 923 | } |
393 | * (fp->maxpacksize & 0x7ff); | ||
394 | fp->attributes = parse_uac_endpoint_attributes(chip, alts, protocol, iface_no); | ||
395 | fp->clock = clock; | ||
396 | |||
397 | /* some quirks for attributes here */ | ||
398 | |||
399 | switch (chip->usb_id) { | ||
400 | case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */ | ||
401 | /* Optoplay sets the sample rate attribute although | ||
402 | * it seems not supporting it in fact. | ||
403 | */ | ||
404 | fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE; | ||
405 | break; | ||
406 | case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */ | ||
407 | case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ | ||
408 | /* doesn't set the sample rate attribute, but supports it */ | ||
409 | fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE; | ||
410 | break; | ||
411 | case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */ | ||
412 | case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */ | ||
413 | case USB_ID(0x047f, 0x0ca1): /* plantronics headset */ | ||
414 | case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is | ||
415 | an older model 77d:223) */ | ||
416 | /* | ||
417 | * plantronics headset and Griffin iMic have set adaptive-in | ||
418 | * although it's really not... | ||
419 | */ | ||
420 | fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE; | ||
421 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
422 | fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE; | ||
423 | else | ||
424 | fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC; | ||
425 | break; | ||
426 | } | ||
427 | 924 | ||
428 | /* ok, let's parse further... */ | 925 | return -EINVAL; |
429 | if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) { | 926 | } |
430 | kfree(fp->rate_table); | ||
431 | kfree(fp); | ||
432 | fp = NULL; | ||
433 | continue; | ||
434 | } | ||
435 | 927 | ||
436 | snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint %#x\n", dev->devnum, iface_no, altno, fp->endpoint); | 928 | int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd) |
437 | err = snd_usb_add_audio_endpoint(chip, stream, fp); | 929 | { |
438 | if (err < 0) { | 930 | struct snd_usb_substream *subs = substream->runtime->private_data; |
439 | kfree(fp->rate_table); | 931 | |
440 | kfree(fp); | 932 | switch (cmd) { |
441 | return err; | 933 | case SNDRV_PCM_TRIGGER_START: |
442 | } | 934 | subs->ops.retire = retire_capture_urb; |
443 | /* try to set the interface... */ | 935 | return start_urbs(subs, substream->runtime); |
444 | usb_set_interface(chip->dev, iface_no, altno); | 936 | case SNDRV_PCM_TRIGGER_STOP: |
445 | snd_usb_init_pitch(chip, iface_no, alts, fp); | 937 | return deactivate_urbs(subs, 0, 0); |
446 | snd_usb_init_sample_rate(chip, iface_no, alts, fp, fp->rate_max); | 938 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
939 | subs->ops.retire = retire_paused_capture_urb; | ||
940 | return 0; | ||
941 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
942 | subs->ops.retire = retire_capture_urb; | ||
943 | return 0; | ||
447 | } | 944 | } |
945 | |||
946 | return -EINVAL; | ||
947 | } | ||
948 | |||
949 | int snd_usb_substream_prepare(struct snd_usb_substream *subs, | ||
950 | struct snd_pcm_runtime *runtime) | ||
951 | { | ||
952 | /* clear urbs (to be sure) */ | ||
953 | deactivate_urbs(subs, 0, 1); | ||
954 | wait_clear_urbs(subs); | ||
955 | |||
956 | /* for playback, submit the URBs now; otherwise, the first hwptr_done | ||
957 | * updates for all URBs would happen at the same time when starting */ | ||
958 | if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) { | ||
959 | subs->ops.prepare = prepare_nodata_playback_urb; | ||
960 | return start_urbs(subs, runtime); | ||
961 | } | ||
962 | |||
448 | return 0; | 963 | return 0; |
449 | } | 964 | } |
450 | 965 | ||
diff --git a/sound/usb/endpoint.h b/sound/usb/endpoint.h index 64dd0db023b2..88eb63a636eb 100644 --- a/sound/usb/endpoint.h +++ b/sound/usb/endpoint.h | |||
@@ -1,11 +1,21 @@ | |||
1 | #ifndef __USBAUDIO_ENDPOINT_H | 1 | #ifndef __USBAUDIO_ENDPOINT_H |
2 | #define __USBAUDIO_ENDPOINT_H | 2 | #define __USBAUDIO_ENDPOINT_H |
3 | 3 | ||
4 | int snd_usb_parse_audio_endpoints(struct snd_usb_audio *chip, | 4 | void snd_usb_init_substream(struct snd_usb_stream *as, |
5 | int iface_no); | 5 | int stream, |
6 | struct audioformat *fp); | ||
6 | 7 | ||
7 | int snd_usb_add_audio_endpoint(struct snd_usb_audio *chip, | 8 | int snd_usb_init_substream_urbs(struct snd_usb_substream *subs, |
8 | int stream, | 9 | unsigned int period_bytes, |
9 | struct audioformat *fp); | 10 | unsigned int rate, |
11 | unsigned int frame_bits); | ||
12 | |||
13 | void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force); | ||
14 | |||
15 | int snd_usb_substream_prepare(struct snd_usb_substream *subs, | ||
16 | struct snd_pcm_runtime *runtime); | ||
17 | |||
18 | int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd); | ||
19 | int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd); | ||
10 | 20 | ||
11 | #endif /* __USBAUDIO_ENDPOINT_H */ | 21 | #endif /* __USBAUDIO_ENDPOINT_H */ |
diff --git a/sound/usb/format.c b/sound/usb/format.c index 8d042dce0d16..89421d176570 100644 --- a/sound/usb/format.c +++ b/sound/usb/format.c | |||
@@ -286,7 +286,7 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip, | |||
286 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, | 286 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, |
287 | UAC2_CS_CONTROL_SAM_FREQ << 8, | 287 | UAC2_CS_CONTROL_SAM_FREQ << 8, |
288 | snd_usb_ctrl_intf(chip) | (clock << 8), | 288 | snd_usb_ctrl_intf(chip) | (clock << 8), |
289 | tmp, sizeof(tmp), 1000); | 289 | tmp, sizeof(tmp)); |
290 | 290 | ||
291 | if (ret < 0) { | 291 | if (ret < 0) { |
292 | snd_printk(KERN_ERR "%s(): unable to retrieve number of sample rates (clock %d)\n", | 292 | snd_printk(KERN_ERR "%s(): unable to retrieve number of sample rates (clock %d)\n", |
@@ -307,7 +307,7 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip, | |||
307 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, | 307 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, |
308 | UAC2_CS_CONTROL_SAM_FREQ << 8, | 308 | UAC2_CS_CONTROL_SAM_FREQ << 8, |
309 | snd_usb_ctrl_intf(chip) | (clock << 8), | 309 | snd_usb_ctrl_intf(chip) | (clock << 8), |
310 | data, data_size, 1000); | 310 | data, data_size); |
311 | 311 | ||
312 | if (ret < 0) { | 312 | if (ret < 0) { |
313 | snd_printk(KERN_ERR "%s(): unable to retrieve sample rate range (clock %d)\n", | 313 | snd_printk(KERN_ERR "%s(): unable to retrieve sample rate range (clock %d)\n", |
diff --git a/sound/usb/helper.c b/sound/usb/helper.c index f280c1903c25..9eed8f40b179 100644 --- a/sound/usb/helper.c +++ b/sound/usb/helper.c | |||
@@ -81,7 +81,7 @@ void *snd_usb_find_csint_desc(void *buffer, int buflen, void *after, u8 dsubtype | |||
81 | */ | 81 | */ |
82 | int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request, | 82 | int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request, |
83 | __u8 requesttype, __u16 value, __u16 index, void *data, | 83 | __u8 requesttype, __u16 value, __u16 index, void *data, |
84 | __u16 size, int timeout) | 84 | __u16 size) |
85 | { | 85 | { |
86 | int err; | 86 | int err; |
87 | void *buf = NULL; | 87 | void *buf = NULL; |
@@ -92,7 +92,7 @@ int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request, | |||
92 | return -ENOMEM; | 92 | return -ENOMEM; |
93 | } | 93 | } |
94 | err = usb_control_msg(dev, pipe, request, requesttype, | 94 | err = usb_control_msg(dev, pipe, request, requesttype, |
95 | value, index, buf, size, timeout); | 95 | value, index, buf, size, 1000); |
96 | if (size > 0) { | 96 | if (size > 0) { |
97 | memcpy(data, buf, size); | 97 | memcpy(data, buf, size); |
98 | kfree(buf); | 98 | kfree(buf); |
diff --git a/sound/usb/helper.h b/sound/usb/helper.h index 09bd943c43bf..805c300dd004 100644 --- a/sound/usb/helper.h +++ b/sound/usb/helper.h | |||
@@ -8,7 +8,7 @@ void *snd_usb_find_csint_desc(void *descstart, int desclen, void *after, u8 dsub | |||
8 | 8 | ||
9 | int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, | 9 | int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, |
10 | __u8 request, __u8 requesttype, __u16 value, __u16 index, | 10 | __u8 request, __u8 requesttype, __u16 value, __u16 index, |
11 | void *data, __u16 size, int timeout); | 11 | void *data, __u16 size); |
12 | 12 | ||
13 | unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip, | 13 | unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip, |
14 | struct usb_host_interface *alts); | 14 | struct usb_host_interface *alts); |
diff --git a/sound/usb/midi.c b/sound/usb/midi.c index f9289102886a..e21f026d9577 100644 --- a/sound/usb/midi.c +++ b/sound/usb/midi.c | |||
@@ -816,6 +816,22 @@ static struct usb_protocol_ops snd_usbmidi_raw_ops = { | |||
816 | .output = snd_usbmidi_raw_output, | 816 | .output = snd_usbmidi_raw_output, |
817 | }; | 817 | }; |
818 | 818 | ||
819 | /* | ||
820 | * FTDI protocol: raw MIDI bytes, but input packets have two modem status bytes. | ||
821 | */ | ||
822 | |||
823 | static void snd_usbmidi_ftdi_input(struct snd_usb_midi_in_endpoint* ep, | ||
824 | uint8_t* buffer, int buffer_length) | ||
825 | { | ||
826 | if (buffer_length > 2) | ||
827 | snd_usbmidi_input_data(ep, 0, buffer + 2, buffer_length - 2); | ||
828 | } | ||
829 | |||
830 | static struct usb_protocol_ops snd_usbmidi_ftdi_ops = { | ||
831 | .input = snd_usbmidi_ftdi_input, | ||
832 | .output = snd_usbmidi_raw_output, | ||
833 | }; | ||
834 | |||
819 | static void snd_usbmidi_us122l_input(struct snd_usb_midi_in_endpoint *ep, | 835 | static void snd_usbmidi_us122l_input(struct snd_usb_midi_in_endpoint *ep, |
820 | uint8_t *buffer, int buffer_length) | 836 | uint8_t *buffer, int buffer_length) |
821 | { | 837 | { |
@@ -2163,6 +2179,17 @@ int snd_usbmidi_create(struct snd_card *card, | |||
2163 | /* endpoint 1 is input-only */ | 2179 | /* endpoint 1 is input-only */ |
2164 | endpoints[1].out_cables = 0; | 2180 | endpoints[1].out_cables = 0; |
2165 | break; | 2181 | break; |
2182 | case QUIRK_MIDI_FTDI: | ||
2183 | umidi->usb_protocol_ops = &snd_usbmidi_ftdi_ops; | ||
2184 | |||
2185 | /* set baud rate to 31250 (48 MHz / 16 / 96) */ | ||
2186 | err = usb_control_msg(umidi->dev, usb_sndctrlpipe(umidi->dev, 0), | ||
2187 | 3, 0x40, 0x60, 0, NULL, 0, 1000); | ||
2188 | if (err < 0) | ||
2189 | break; | ||
2190 | |||
2191 | err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints); | ||
2192 | break; | ||
2166 | default: | 2193 | default: |
2167 | snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type); | 2194 | snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type); |
2168 | err = -ENXIO; | 2195 | err = -ENXIO; |
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index cdd19d7fe500..60f65ace7474 100644 --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c | |||
@@ -296,7 +296,7 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int v | |||
296 | if (snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), request, | 296 | if (snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), request, |
297 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, | 297 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, |
298 | validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), | 298 | validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), |
299 | buf, val_len, 100) >= val_len) { | 299 | buf, val_len) >= val_len) { |
300 | *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len)); | 300 | *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len)); |
301 | snd_usb_autosuspend(cval->mixer->chip); | 301 | snd_usb_autosuspend(cval->mixer->chip); |
302 | return 0; | 302 | return 0; |
@@ -333,7 +333,7 @@ static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int v | |||
333 | ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), bRequest, | 333 | ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), bRequest, |
334 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, | 334 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, |
335 | validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), | 335 | validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), |
336 | buf, size, 1000); | 336 | buf, size); |
337 | snd_usb_autosuspend(chip); | 337 | snd_usb_autosuspend(chip); |
338 | 338 | ||
339 | if (ret < 0) { | 339 | if (ret < 0) { |
@@ -445,7 +445,7 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval, | |||
445 | usb_sndctrlpipe(chip->dev, 0), request, | 445 | usb_sndctrlpipe(chip->dev, 0), request, |
446 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, | 446 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, |
447 | validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), | 447 | validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), |
448 | buf, val_len, 100) >= 0) { | 448 | buf, val_len) >= 0) { |
449 | snd_usb_autosuspend(chip); | 449 | snd_usb_autosuspend(chip); |
450 | return 0; | 450 | return 0; |
451 | } | 451 | } |
@@ -881,8 +881,17 @@ static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol, struct snd_ctl_ | |||
881 | uinfo->value.integer.min = 0; | 881 | uinfo->value.integer.min = 0; |
882 | uinfo->value.integer.max = 1; | 882 | uinfo->value.integer.max = 1; |
883 | } else { | 883 | } else { |
884 | if (! cval->initialized) | 884 | if (!cval->initialized) { |
885 | get_min_max(cval, 0); | 885 | get_min_max(cval, 0); |
886 | if (cval->initialized && cval->dBmin >= cval->dBmax) { | ||
887 | kcontrol->vd[0].access &= | ||
888 | ~(SNDRV_CTL_ELEM_ACCESS_TLV_READ | | ||
889 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK); | ||
890 | snd_ctl_notify(cval->mixer->chip->card, | ||
891 | SNDRV_CTL_EVENT_MASK_INFO, | ||
892 | &kcontrol->id); | ||
893 | } | ||
894 | } | ||
886 | uinfo->value.integer.min = 0; | 895 | uinfo->value.integer.min = 0; |
887 | uinfo->value.integer.max = | 896 | uinfo->value.integer.max = |
888 | (cval->max - cval->min + cval->res - 1) / cval->res; | 897 | (cval->max - cval->min + cval->res - 1) / cval->res; |
@@ -1250,7 +1259,7 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void | |||
1250 | build_feature_ctl(state, _ftr, 0, i, &iterm, unitid, 0); | 1259 | build_feature_ctl(state, _ftr, 0, i, &iterm, unitid, 0); |
1251 | } | 1260 | } |
1252 | } else { /* UAC_VERSION_2 */ | 1261 | } else { /* UAC_VERSION_2 */ |
1253 | for (i = 0; i < 30/2; i++) { | 1262 | for (i = 0; i < ARRAY_SIZE(audio_feature_info); i++) { |
1254 | unsigned int ch_bits = 0; | 1263 | unsigned int ch_bits = 0; |
1255 | unsigned int ch_read_only = 0; | 1264 | unsigned int ch_read_only = 0; |
1256 | 1265 | ||
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c index 3d0f4873112b..ab125ee0b0f0 100644 --- a/sound/usb/mixer_quirks.c +++ b/sound/usb/mixer_quirks.c | |||
@@ -190,18 +190,18 @@ static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e | |||
190 | err = snd_usb_ctl_msg(mixer->chip->dev, | 190 | err = snd_usb_ctl_msg(mixer->chip->dev, |
191 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, | 191 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, |
192 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | 192 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
193 | !value, 0, NULL, 0, 100); | 193 | !value, 0, NULL, 0); |
194 | /* USB X-Fi S51 Pro */ | 194 | /* USB X-Fi S51 Pro */ |
195 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) | 195 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) |
196 | err = snd_usb_ctl_msg(mixer->chip->dev, | 196 | err = snd_usb_ctl_msg(mixer->chip->dev, |
197 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, | 197 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, |
198 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | 198 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
199 | !value, 0, NULL, 0, 100); | 199 | !value, 0, NULL, 0); |
200 | else | 200 | else |
201 | err = snd_usb_ctl_msg(mixer->chip->dev, | 201 | err = snd_usb_ctl_msg(mixer->chip->dev, |
202 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, | 202 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, |
203 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | 203 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
204 | value, index + 2, NULL, 0, 100); | 204 | value, index + 2, NULL, 0); |
205 | if (err < 0) | 205 | if (err < 0) |
206 | return err; | 206 | return err; |
207 | mixer->audigy2nx_leds[index] = value; | 207 | mixer->audigy2nx_leds[index] = value; |
@@ -299,7 +299,7 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, | |||
299 | usb_rcvctrlpipe(mixer->chip->dev, 0), | 299 | usb_rcvctrlpipe(mixer->chip->dev, 0), |
300 | UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS | | 300 | UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS | |
301 | USB_RECIP_INTERFACE, 0, | 301 | USB_RECIP_INTERFACE, 0, |
302 | jacks[i].unitid << 8, buf, 3, 100); | 302 | jacks[i].unitid << 8, buf, 3); |
303 | if (err == 3 && (buf[0] == 3 || buf[0] == 6)) | 303 | if (err == 3 && (buf[0] == 3 || buf[0] == 6)) |
304 | snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]); | 304 | snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]); |
305 | else | 305 | else |
@@ -332,7 +332,7 @@ static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol, | |||
332 | err = snd_usb_ctl_msg(mixer->chip->dev, | 332 | err = snd_usb_ctl_msg(mixer->chip->dev, |
333 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x08, | 333 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x08, |
334 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | 334 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
335 | 50, 0, &new_status, 1, 100); | 335 | 50, 0, &new_status, 1); |
336 | if (err < 0) | 336 | if (err < 0) |
337 | return err; | 337 | return err; |
338 | mixer->xonar_u1_status = new_status; | 338 | mixer->xonar_u1_status = new_status; |
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index b8dcbf407bbb..0220b0f335b9 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c | |||
@@ -28,12 +28,36 @@ | |||
28 | #include "card.h" | 28 | #include "card.h" |
29 | #include "quirks.h" | 29 | #include "quirks.h" |
30 | #include "debug.h" | 30 | #include "debug.h" |
31 | #include "urb.h" | 31 | #include "endpoint.h" |
32 | #include "helper.h" | 32 | #include "helper.h" |
33 | #include "pcm.h" | 33 | #include "pcm.h" |
34 | #include "clock.h" | 34 | #include "clock.h" |
35 | #include "power.h" | 35 | #include "power.h" |
36 | 36 | ||
37 | /* return the estimated delay based on USB frame counters */ | ||
38 | snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs, | ||
39 | unsigned int rate) | ||
40 | { | ||
41 | int current_frame_number; | ||
42 | int frame_diff; | ||
43 | int est_delay; | ||
44 | |||
45 | current_frame_number = usb_get_current_frame_number(subs->dev); | ||
46 | /* | ||
47 | * HCD implementations use different widths, use lower 8 bits. | ||
48 | * The delay will be managed up to 256ms, which is more than | ||
49 | * enough | ||
50 | */ | ||
51 | frame_diff = (current_frame_number - subs->last_frame_number) & 0xff; | ||
52 | |||
53 | /* Approximation based on number of samples per USB frame (ms), | ||
54 | some truncation for 44.1 but the estimate is good enough */ | ||
55 | est_delay = subs->last_delay - (frame_diff * rate / 1000); | ||
56 | if (est_delay < 0) | ||
57 | est_delay = 0; | ||
58 | return est_delay; | ||
59 | } | ||
60 | |||
37 | /* | 61 | /* |
38 | * return the current pcm pointer. just based on the hwptr_done value. | 62 | * return the current pcm pointer. just based on the hwptr_done value. |
39 | */ | 63 | */ |
@@ -45,6 +69,8 @@ static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream | |||
45 | subs = (struct snd_usb_substream *)substream->runtime->private_data; | 69 | subs = (struct snd_usb_substream *)substream->runtime->private_data; |
46 | spin_lock(&subs->lock); | 70 | spin_lock(&subs->lock); |
47 | hwptr_done = subs->hwptr_done; | 71 | hwptr_done = subs->hwptr_done; |
72 | substream->runtime->delay = snd_usb_pcm_delay(subs, | ||
73 | substream->runtime->rate); | ||
48 | spin_unlock(&subs->lock); | 74 | spin_unlock(&subs->lock); |
49 | return hwptr_done / (substream->runtime->frame_bits >> 3); | 75 | return hwptr_done / (substream->runtime->frame_bits >> 3); |
50 | } | 76 | } |
@@ -126,7 +152,7 @@ static int init_pitch_v1(struct snd_usb_audio *chip, int iface, | |||
126 | if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, | 152 | if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, |
127 | USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, | 153 | USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, |
128 | UAC_EP_CS_ATTR_PITCH_CONTROL << 8, ep, | 154 | UAC_EP_CS_ATTR_PITCH_CONTROL << 8, ep, |
129 | data, sizeof(data), 1000)) < 0) { | 155 | data, sizeof(data))) < 0) { |
130 | snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n", | 156 | snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n", |
131 | dev->devnum, iface, ep); | 157 | dev->devnum, iface, ep); |
132 | return err; | 158 | return err; |
@@ -150,7 +176,7 @@ static int init_pitch_v2(struct snd_usb_audio *chip, int iface, | |||
150 | if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR, | 176 | if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR, |
151 | USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT, | 177 | USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
152 | UAC2_EP_CS_PITCH << 8, 0, | 178 | UAC2_EP_CS_PITCH << 8, 0, |
153 | data, sizeof(data), 1000)) < 0) { | 179 | data, sizeof(data))) < 0) { |
154 | snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH (v2)\n", | 180 | snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH (v2)\n", |
155 | dev->devnum, iface, fmt->altsetting); | 181 | dev->devnum, iface, fmt->altsetting); |
156 | return err; | 182 | return err; |
@@ -417,6 +443,8 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream) | |||
417 | subs->hwptr_done = 0; | 443 | subs->hwptr_done = 0; |
418 | subs->transfer_done = 0; | 444 | subs->transfer_done = 0; |
419 | subs->phase = 0; | 445 | subs->phase = 0; |
446 | subs->last_delay = 0; | ||
447 | subs->last_frame_number = 0; | ||
420 | runtime->delay = 0; | 448 | runtime->delay = 0; |
421 | 449 | ||
422 | return snd_usb_substream_prepare(subs, runtime); | 450 | return snd_usb_substream_prepare(subs, runtime); |
diff --git a/sound/usb/pcm.h b/sound/usb/pcm.h index ed3e283f618d..df7a003682ad 100644 --- a/sound/usb/pcm.h +++ b/sound/usb/pcm.h | |||
@@ -1,6 +1,9 @@ | |||
1 | #ifndef __USBAUDIO_PCM_H | 1 | #ifndef __USBAUDIO_PCM_H |
2 | #define __USBAUDIO_PCM_H | 2 | #define __USBAUDIO_PCM_H |
3 | 3 | ||
4 | snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs, | ||
5 | unsigned int rate); | ||
6 | |||
4 | void snd_usb_set_pcm_ops(struct snd_pcm *pcm, int stream); | 7 | void snd_usb_set_pcm_ops(struct snd_pcm *pcm, int stream); |
5 | 8 | ||
6 | int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface, | 9 | int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface, |
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h index a42e3ef3832d..b61945f3af9e 100644 --- a/sound/usb/quirks-table.h +++ b/sound/usb/quirks-table.h | |||
@@ -39,6 +39,17 @@ | |||
39 | .idProduct = prod, \ | 39 | .idProduct = prod, \ |
40 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC | 40 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC |
41 | 41 | ||
42 | /* FTDI devices */ | ||
43 | { | ||
44 | USB_DEVICE(0x0403, 0xb8d8), | ||
45 | .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { | ||
46 | /* .vendor_name = "STARR LABS", */ | ||
47 | /* .product_name = "Starr Labs MIDI USB device", */ | ||
48 | .ifnum = 0, | ||
49 | .type = QUIRK_MIDI_FTDI | ||
50 | } | ||
51 | }, | ||
52 | |||
42 | /* Creative/Toshiba Multimedia Center SB-0500 */ | 53 | /* Creative/Toshiba Multimedia Center SB-0500 */ |
43 | { | 54 | { |
44 | USB_DEVICE(0x041e, 0x3048), | 55 | USB_DEVICE(0x041e, 0x3048), |
@@ -1678,6 +1689,20 @@ YAMAHA_DEVICE(0x7010, "UB99"), | |||
1678 | } | 1689 | } |
1679 | }, | 1690 | }, |
1680 | { | 1691 | { |
1692 | /* Added support for Roland UM-ONE which differs from UM-1 */ | ||
1693 | USB_DEVICE(0x0582, 0x012a), | ||
1694 | .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { | ||
1695 | /* .vendor_name = "ROLAND", */ | ||
1696 | /* .product_name = "UM-ONE", */ | ||
1697 | .ifnum = 0, | ||
1698 | .type = QUIRK_MIDI_FIXED_ENDPOINT, | ||
1699 | .data = & (const struct snd_usb_midi_endpoint_info) { | ||
1700 | .out_cables = 0x0001, | ||
1701 | .in_cables = 0x0003 | ||
1702 | } | ||
1703 | } | ||
1704 | }, | ||
1705 | { | ||
1681 | USB_DEVICE(0x0582, 0x011e), | 1706 | USB_DEVICE(0x0582, 0x011e), |
1682 | .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { | 1707 | .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { |
1683 | /* .vendor_name = "BOSS", */ | 1708 | /* .vendor_name = "BOSS", */ |
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index 81e07d842581..2e5bc7344026 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "endpoint.h" | 34 | #include "endpoint.h" |
35 | #include "pcm.h" | 35 | #include "pcm.h" |
36 | #include "clock.h" | 36 | #include "clock.h" |
37 | #include "stream.h" | ||
37 | 38 | ||
38 | /* | 39 | /* |
39 | * handle the quirks for the contained interfaces | 40 | * handle the quirks for the contained interfaces |
@@ -106,7 +107,7 @@ static int create_standard_audio_quirk(struct snd_usb_audio *chip, | |||
106 | 107 | ||
107 | alts = &iface->altsetting[0]; | 108 | alts = &iface->altsetting[0]; |
108 | altsd = get_iface_desc(alts); | 109 | altsd = get_iface_desc(alts); |
109 | err = snd_usb_parse_audio_endpoints(chip, altsd->bInterfaceNumber); | 110 | err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber); |
110 | if (err < 0) { | 111 | if (err < 0) { |
111 | snd_printk(KERN_ERR "cannot setup if %d: error %d\n", | 112 | snd_printk(KERN_ERR "cannot setup if %d: error %d\n", |
112 | altsd->bInterfaceNumber, err); | 113 | altsd->bInterfaceNumber, err); |
@@ -147,7 +148,7 @@ static int create_fixed_stream_quirk(struct snd_usb_audio *chip, | |||
147 | 148 | ||
148 | stream = (fp->endpoint & USB_DIR_IN) | 149 | stream = (fp->endpoint & USB_DIR_IN) |
149 | ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; | 150 | ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; |
150 | err = snd_usb_add_audio_endpoint(chip, stream, fp); | 151 | err = snd_usb_add_audio_stream(chip, stream, fp); |
151 | if (err < 0) { | 152 | if (err < 0) { |
152 | kfree(fp); | 153 | kfree(fp); |
153 | kfree(rate_table); | 154 | kfree(rate_table); |
@@ -254,7 +255,7 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip, | |||
254 | 255 | ||
255 | stream = (fp->endpoint & USB_DIR_IN) | 256 | stream = (fp->endpoint & USB_DIR_IN) |
256 | ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; | 257 | ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; |
257 | err = snd_usb_add_audio_endpoint(chip, stream, fp); | 258 | err = snd_usb_add_audio_stream(chip, stream, fp); |
258 | if (err < 0) { | 259 | if (err < 0) { |
259 | kfree(fp); | 260 | kfree(fp); |
260 | return err; | 261 | return err; |
@@ -306,6 +307,7 @@ int snd_usb_create_quirk(struct snd_usb_audio *chip, | |||
306 | [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk, | 307 | [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk, |
307 | [QUIRK_MIDI_CME] = create_any_midi_quirk, | 308 | [QUIRK_MIDI_CME] = create_any_midi_quirk, |
308 | [QUIRK_MIDI_AKAI] = create_any_midi_quirk, | 309 | [QUIRK_MIDI_AKAI] = create_any_midi_quirk, |
310 | [QUIRK_MIDI_FTDI] = create_any_midi_quirk, | ||
309 | [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, | 311 | [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, |
310 | [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, | 312 | [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, |
311 | [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk, | 313 | [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk, |
@@ -338,7 +340,7 @@ static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interfac | |||
338 | snd_printdd("sending Extigy boot sequence...\n"); | 340 | snd_printdd("sending Extigy boot sequence...\n"); |
339 | /* Send message to force it to reconnect with full interface. */ | 341 | /* Send message to force it to reconnect with full interface. */ |
340 | err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0), | 342 | err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0), |
341 | 0x10, 0x43, 0x0001, 0x000a, NULL, 0, 1000); | 343 | 0x10, 0x43, 0x0001, 0x000a, NULL, 0); |
342 | if (err < 0) snd_printdd("error sending boot message: %d\n", err); | 344 | if (err < 0) snd_printdd("error sending boot message: %d\n", err); |
343 | err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, | 345 | err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, |
344 | &dev->descriptor, sizeof(dev->descriptor)); | 346 | &dev->descriptor, sizeof(dev->descriptor)); |
@@ -359,11 +361,11 @@ static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev) | |||
359 | 361 | ||
360 | snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a, | 362 | snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a, |
361 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, | 363 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
362 | 0, 0, &buf, 1, 1000); | 364 | 0, 0, &buf, 1); |
363 | if (buf == 0) { | 365 | if (buf == 0) { |
364 | snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29, | 366 | snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29, |
365 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | 367 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
366 | 1, 2000, NULL, 0, 1000); | 368 | 1, 2000, NULL, 0); |
367 | return -ENODEV; | 369 | return -ENODEV; |
368 | } | 370 | } |
369 | return 0; | 371 | return 0; |
@@ -406,7 +408,7 @@ static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 valu | |||
406 | buf[3] = reg; | 408 | buf[3] = reg; |
407 | return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION, | 409 | return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION, |
408 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT, | 410 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT, |
409 | 0, 0, &buf, 4, 1000); | 411 | 0, 0, &buf, 4); |
410 | } | 412 | } |
411 | 413 | ||
412 | static int snd_usb_cm106_boot_quirk(struct usb_device *dev) | 414 | static int snd_usb_cm106_boot_quirk(struct usb_device *dev) |
diff --git a/sound/usb/stream.c b/sound/usb/stream.c new file mode 100644 index 000000000000..5ff8010b2d6f --- /dev/null +++ b/sound/usb/stream.c | |||
@@ -0,0 +1,452 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify | ||
3 | * it under the terms of the GNU General Public License as published by | ||
4 | * the Free Software Foundation; either version 2 of the License, or | ||
5 | * (at your option) any later version. | ||
6 | * | ||
7 | * This program is distributed in the hope that it will be useful, | ||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | * GNU General Public License for more details. | ||
11 | * | ||
12 | * You should have received a copy of the GNU General Public License | ||
13 | * along with this program; if not, write to the Free Software | ||
14 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
15 | */ | ||
16 | |||
17 | |||
18 | #include <linux/init.h> | ||
19 | #include <linux/slab.h> | ||
20 | #include <linux/usb.h> | ||
21 | #include <linux/usb/audio.h> | ||
22 | #include <linux/usb/audio-v2.h> | ||
23 | |||
24 | #include <sound/core.h> | ||
25 | #include <sound/pcm.h> | ||
26 | |||
27 | #include "usbaudio.h" | ||
28 | #include "card.h" | ||
29 | #include "proc.h" | ||
30 | #include "quirks.h" | ||
31 | #include "endpoint.h" | ||
32 | #include "pcm.h" | ||
33 | #include "helper.h" | ||
34 | #include "format.h" | ||
35 | #include "clock.h" | ||
36 | #include "stream.h" | ||
37 | |||
38 | /* | ||
39 | * free a substream | ||
40 | */ | ||
41 | static void free_substream(struct snd_usb_substream *subs) | ||
42 | { | ||
43 | struct list_head *p, *n; | ||
44 | |||
45 | if (!subs->num_formats) | ||
46 | return; /* not initialized */ | ||
47 | list_for_each_safe(p, n, &subs->fmt_list) { | ||
48 | struct audioformat *fp = list_entry(p, struct audioformat, list); | ||
49 | kfree(fp->rate_table); | ||
50 | kfree(fp); | ||
51 | } | ||
52 | kfree(subs->rate_list.list); | ||
53 | } | ||
54 | |||
55 | |||
56 | /* | ||
57 | * free a usb stream instance | ||
58 | */ | ||
59 | static void snd_usb_audio_stream_free(struct snd_usb_stream *stream) | ||
60 | { | ||
61 | free_substream(&stream->substream[0]); | ||
62 | free_substream(&stream->substream[1]); | ||
63 | list_del(&stream->list); | ||
64 | kfree(stream); | ||
65 | } | ||
66 | |||
67 | static void snd_usb_audio_pcm_free(struct snd_pcm *pcm) | ||
68 | { | ||
69 | struct snd_usb_stream *stream = pcm->private_data; | ||
70 | if (stream) { | ||
71 | stream->pcm = NULL; | ||
72 | snd_usb_audio_stream_free(stream); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | |||
77 | /* | ||
78 | * add this endpoint to the chip instance. | ||
79 | * if a stream with the same endpoint already exists, append to it. | ||
80 | * if not, create a new pcm stream. | ||
81 | */ | ||
82 | int snd_usb_add_audio_stream(struct snd_usb_audio *chip, | ||
83 | int stream, | ||
84 | struct audioformat *fp) | ||
85 | { | ||
86 | struct list_head *p; | ||
87 | struct snd_usb_stream *as; | ||
88 | struct snd_usb_substream *subs; | ||
89 | struct snd_pcm *pcm; | ||
90 | int err; | ||
91 | |||
92 | list_for_each(p, &chip->pcm_list) { | ||
93 | as = list_entry(p, struct snd_usb_stream, list); | ||
94 | if (as->fmt_type != fp->fmt_type) | ||
95 | continue; | ||
96 | subs = &as->substream[stream]; | ||
97 | if (!subs->endpoint) | ||
98 | continue; | ||
99 | if (subs->endpoint == fp->endpoint) { | ||
100 | list_add_tail(&fp->list, &subs->fmt_list); | ||
101 | subs->num_formats++; | ||
102 | subs->formats |= fp->formats; | ||
103 | return 0; | ||
104 | } | ||
105 | } | ||
106 | /* look for an empty stream */ | ||
107 | list_for_each(p, &chip->pcm_list) { | ||
108 | as = list_entry(p, struct snd_usb_stream, list); | ||
109 | if (as->fmt_type != fp->fmt_type) | ||
110 | continue; | ||
111 | subs = &as->substream[stream]; | ||
112 | if (subs->endpoint) | ||
113 | continue; | ||
114 | err = snd_pcm_new_stream(as->pcm, stream, 1); | ||
115 | if (err < 0) | ||
116 | return err; | ||
117 | snd_usb_init_substream(as, stream, fp); | ||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | /* create a new pcm */ | ||
122 | as = kzalloc(sizeof(*as), GFP_KERNEL); | ||
123 | if (!as) | ||
124 | return -ENOMEM; | ||
125 | as->pcm_index = chip->pcm_devs; | ||
126 | as->chip = chip; | ||
127 | as->fmt_type = fp->fmt_type; | ||
128 | err = snd_pcm_new(chip->card, "USB Audio", chip->pcm_devs, | ||
129 | stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : 0, | ||
130 | stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1, | ||
131 | &pcm); | ||
132 | if (err < 0) { | ||
133 | kfree(as); | ||
134 | return err; | ||
135 | } | ||
136 | as->pcm = pcm; | ||
137 | pcm->private_data = as; | ||
138 | pcm->private_free = snd_usb_audio_pcm_free; | ||
139 | pcm->info_flags = 0; | ||
140 | if (chip->pcm_devs > 0) | ||
141 | sprintf(pcm->name, "USB Audio #%d", chip->pcm_devs); | ||
142 | else | ||
143 | strcpy(pcm->name, "USB Audio"); | ||
144 | |||
145 | snd_usb_init_substream(as, stream, fp); | ||
146 | |||
147 | list_add(&as->list, &chip->pcm_list); | ||
148 | chip->pcm_devs++; | ||
149 | |||
150 | snd_usb_proc_pcm_format_add(as); | ||
151 | |||
152 | return 0; | ||
153 | } | ||
154 | |||
155 | static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip, | ||
156 | struct usb_host_interface *alts, | ||
157 | int protocol, int iface_no) | ||
158 | { | ||
159 | /* parsed with a v1 header here. that's ok as we only look at the | ||
160 | * header first which is the same for both versions */ | ||
161 | struct uac_iso_endpoint_descriptor *csep; | ||
162 | struct usb_interface_descriptor *altsd = get_iface_desc(alts); | ||
163 | int attributes = 0; | ||
164 | |||
165 | csep = snd_usb_find_desc(alts->endpoint[0].extra, alts->endpoint[0].extralen, NULL, USB_DT_CS_ENDPOINT); | ||
166 | |||
167 | /* Creamware Noah has this descriptor after the 2nd endpoint */ | ||
168 | if (!csep && altsd->bNumEndpoints >= 2) | ||
169 | csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT); | ||
170 | |||
171 | if (!csep || csep->bLength < 7 || | ||
172 | csep->bDescriptorSubtype != UAC_EP_GENERAL) { | ||
173 | snd_printk(KERN_WARNING "%d:%u:%d : no or invalid" | ||
174 | " class specific endpoint descriptor\n", | ||
175 | chip->dev->devnum, iface_no, | ||
176 | altsd->bAlternateSetting); | ||
177 | return 0; | ||
178 | } | ||
179 | |||
180 | if (protocol == UAC_VERSION_1) { | ||
181 | attributes = csep->bmAttributes; | ||
182 | } else { | ||
183 | struct uac2_iso_endpoint_descriptor *csep2 = | ||
184 | (struct uac2_iso_endpoint_descriptor *) csep; | ||
185 | |||
186 | attributes = csep->bmAttributes & UAC_EP_CS_ATTR_FILL_MAX; | ||
187 | |||
188 | /* emulate the endpoint attributes of a v1 device */ | ||
189 | if (csep2->bmControls & UAC2_CONTROL_PITCH) | ||
190 | attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL; | ||
191 | } | ||
192 | |||
193 | return attributes; | ||
194 | } | ||
195 | |||
196 | static struct uac2_input_terminal_descriptor * | ||
197 | snd_usb_find_input_terminal_descriptor(struct usb_host_interface *ctrl_iface, | ||
198 | int terminal_id) | ||
199 | { | ||
200 | struct uac2_input_terminal_descriptor *term = NULL; | ||
201 | |||
202 | while ((term = snd_usb_find_csint_desc(ctrl_iface->extra, | ||
203 | ctrl_iface->extralen, | ||
204 | term, UAC_INPUT_TERMINAL))) { | ||
205 | if (term->bTerminalID == terminal_id) | ||
206 | return term; | ||
207 | } | ||
208 | |||
209 | return NULL; | ||
210 | } | ||
211 | |||
212 | static struct uac2_output_terminal_descriptor * | ||
213 | snd_usb_find_output_terminal_descriptor(struct usb_host_interface *ctrl_iface, | ||
214 | int terminal_id) | ||
215 | { | ||
216 | struct uac2_output_terminal_descriptor *term = NULL; | ||
217 | |||
218 | while ((term = snd_usb_find_csint_desc(ctrl_iface->extra, | ||
219 | ctrl_iface->extralen, | ||
220 | term, UAC_OUTPUT_TERMINAL))) { | ||
221 | if (term->bTerminalID == terminal_id) | ||
222 | return term; | ||
223 | } | ||
224 | |||
225 | return NULL; | ||
226 | } | ||
227 | |||
228 | int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no) | ||
229 | { | ||
230 | struct usb_device *dev; | ||
231 | struct usb_interface *iface; | ||
232 | struct usb_host_interface *alts; | ||
233 | struct usb_interface_descriptor *altsd; | ||
234 | int i, altno, err, stream; | ||
235 | int format = 0, num_channels = 0; | ||
236 | struct audioformat *fp = NULL; | ||
237 | int num, protocol, clock = 0; | ||
238 | struct uac_format_type_i_continuous_descriptor *fmt; | ||
239 | |||
240 | dev = chip->dev; | ||
241 | |||
242 | /* parse the interface's altsettings */ | ||
243 | iface = usb_ifnum_to_if(dev, iface_no); | ||
244 | |||
245 | num = iface->num_altsetting; | ||
246 | |||
247 | /* | ||
248 | * Dallas DS4201 workaround: It presents 5 altsettings, but the last | ||
249 | * one misses syncpipe, and does not produce any sound. | ||
250 | */ | ||
251 | if (chip->usb_id == USB_ID(0x04fa, 0x4201)) | ||
252 | num = 4; | ||
253 | |||
254 | for (i = 0; i < num; i++) { | ||
255 | alts = &iface->altsetting[i]; | ||
256 | altsd = get_iface_desc(alts); | ||
257 | protocol = altsd->bInterfaceProtocol; | ||
258 | /* skip invalid one */ | ||
259 | if ((altsd->bInterfaceClass != USB_CLASS_AUDIO && | ||
260 | altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) || | ||
261 | (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING && | ||
262 | altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) || | ||
263 | altsd->bNumEndpoints < 1 || | ||
264 | le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0) | ||
265 | continue; | ||
266 | /* must be isochronous */ | ||
267 | if ((get_endpoint(alts, 0)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != | ||
268 | USB_ENDPOINT_XFER_ISOC) | ||
269 | continue; | ||
270 | /* check direction */ | ||
271 | stream = (get_endpoint(alts, 0)->bEndpointAddress & USB_DIR_IN) ? | ||
272 | SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; | ||
273 | altno = altsd->bAlternateSetting; | ||
274 | |||
275 | if (snd_usb_apply_interface_quirk(chip, iface_no, altno)) | ||
276 | continue; | ||
277 | |||
278 | /* get audio formats */ | ||
279 | switch (protocol) { | ||
280 | default: | ||
281 | snd_printdd(KERN_WARNING "%d:%u:%d: unknown interface protocol %#02x, assuming v1\n", | ||
282 | dev->devnum, iface_no, altno, protocol); | ||
283 | protocol = UAC_VERSION_1; | ||
284 | /* fall through */ | ||
285 | |||
286 | case UAC_VERSION_1: { | ||
287 | struct uac1_as_header_descriptor *as = | ||
288 | snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL); | ||
289 | |||
290 | if (!as) { | ||
291 | snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n", | ||
292 | dev->devnum, iface_no, altno); | ||
293 | continue; | ||
294 | } | ||
295 | |||
296 | if (as->bLength < sizeof(*as)) { | ||
297 | snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n", | ||
298 | dev->devnum, iface_no, altno); | ||
299 | continue; | ||
300 | } | ||
301 | |||
302 | format = le16_to_cpu(as->wFormatTag); /* remember the format value */ | ||
303 | break; | ||
304 | } | ||
305 | |||
306 | case UAC_VERSION_2: { | ||
307 | struct uac2_input_terminal_descriptor *input_term; | ||
308 | struct uac2_output_terminal_descriptor *output_term; | ||
309 | struct uac2_as_header_descriptor *as = | ||
310 | snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL); | ||
311 | |||
312 | if (!as) { | ||
313 | snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n", | ||
314 | dev->devnum, iface_no, altno); | ||
315 | continue; | ||
316 | } | ||
317 | |||
318 | if (as->bLength < sizeof(*as)) { | ||
319 | snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n", | ||
320 | dev->devnum, iface_no, altno); | ||
321 | continue; | ||
322 | } | ||
323 | |||
324 | num_channels = as->bNrChannels; | ||
325 | format = le32_to_cpu(as->bmFormats); | ||
326 | |||
327 | /* lookup the terminal associated to this interface | ||
328 | * to extract the clock */ | ||
329 | input_term = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf, | ||
330 | as->bTerminalLink); | ||
331 | if (input_term) { | ||
332 | clock = input_term->bCSourceID; | ||
333 | break; | ||
334 | } | ||
335 | |||
336 | output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf, | ||
337 | as->bTerminalLink); | ||
338 | if (output_term) { | ||
339 | clock = output_term->bCSourceID; | ||
340 | break; | ||
341 | } | ||
342 | |||
343 | snd_printk(KERN_ERR "%d:%u:%d : bogus bTerminalLink %d\n", | ||
344 | dev->devnum, iface_no, altno, as->bTerminalLink); | ||
345 | continue; | ||
346 | } | ||
347 | } | ||
348 | |||
349 | /* get format type */ | ||
350 | fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE); | ||
351 | if (!fmt) { | ||
352 | snd_printk(KERN_ERR "%d:%u:%d : no UAC_FORMAT_TYPE desc\n", | ||
353 | dev->devnum, iface_no, altno); | ||
354 | continue; | ||
355 | } | ||
356 | if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8)) || | ||
357 | ((protocol == UAC_VERSION_2) && (fmt->bLength < 6))) { | ||
358 | snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n", | ||
359 | dev->devnum, iface_no, altno); | ||
360 | continue; | ||
361 | } | ||
362 | |||
363 | /* | ||
364 | * Blue Microphones workaround: The last altsetting is identical | ||
365 | * with the previous one, except for a larger packet size, but | ||
366 | * is actually a mislabeled two-channel setting; ignore it. | ||
367 | */ | ||
368 | if (fmt->bNrChannels == 1 && | ||
369 | fmt->bSubframeSize == 2 && | ||
370 | altno == 2 && num == 3 && | ||
371 | fp && fp->altsetting == 1 && fp->channels == 1 && | ||
372 | fp->formats == SNDRV_PCM_FMTBIT_S16_LE && | ||
373 | protocol == UAC_VERSION_1 && | ||
374 | le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == | ||
375 | fp->maxpacksize * 2) | ||
376 | continue; | ||
377 | |||
378 | fp = kzalloc(sizeof(*fp), GFP_KERNEL); | ||
379 | if (! fp) { | ||
380 | snd_printk(KERN_ERR "cannot malloc\n"); | ||
381 | return -ENOMEM; | ||
382 | } | ||
383 | |||
384 | fp->iface = iface_no; | ||
385 | fp->altsetting = altno; | ||
386 | fp->altset_idx = i; | ||
387 | fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress; | ||
388 | fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; | ||
389 | fp->datainterval = snd_usb_parse_datainterval(chip, alts); | ||
390 | fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); | ||
391 | /* num_channels is only set for v2 interfaces */ | ||
392 | fp->channels = num_channels; | ||
393 | if (snd_usb_get_speed(dev) == USB_SPEED_HIGH) | ||
394 | fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1) | ||
395 | * (fp->maxpacksize & 0x7ff); | ||
396 | fp->attributes = parse_uac_endpoint_attributes(chip, alts, protocol, iface_no); | ||
397 | fp->clock = clock; | ||
398 | |||
399 | /* some quirks for attributes here */ | ||
400 | |||
401 | switch (chip->usb_id) { | ||
402 | case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */ | ||
403 | /* Optoplay sets the sample rate attribute although | ||
404 | * it seems not supporting it in fact. | ||
405 | */ | ||
406 | fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE; | ||
407 | break; | ||
408 | case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */ | ||
409 | case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ | ||
410 | /* doesn't set the sample rate attribute, but supports it */ | ||
411 | fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE; | ||
412 | break; | ||
413 | case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */ | ||
414 | case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */ | ||
415 | case USB_ID(0x047f, 0x0ca1): /* plantronics headset */ | ||
416 | case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is | ||
417 | an older model 77d:223) */ | ||
418 | /* | ||
419 | * plantronics headset and Griffin iMic have set adaptive-in | ||
420 | * although it's really not... | ||
421 | */ | ||
422 | fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE; | ||
423 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
424 | fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE; | ||
425 | else | ||
426 | fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC; | ||
427 | break; | ||
428 | } | ||
429 | |||
430 | /* ok, let's parse further... */ | ||
431 | if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) { | ||
432 | kfree(fp->rate_table); | ||
433 | kfree(fp); | ||
434 | fp = NULL; | ||
435 | continue; | ||
436 | } | ||
437 | |||
438 | snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint %#x\n", dev->devnum, iface_no, altno, fp->endpoint); | ||
439 | err = snd_usb_add_audio_stream(chip, stream, fp); | ||
440 | if (err < 0) { | ||
441 | kfree(fp->rate_table); | ||
442 | kfree(fp); | ||
443 | return err; | ||
444 | } | ||
445 | /* try to set the interface... */ | ||
446 | usb_set_interface(chip->dev, iface_no, altno); | ||
447 | snd_usb_init_pitch(chip, iface_no, alts, fp); | ||
448 | snd_usb_init_sample_rate(chip, iface_no, alts, fp, fp->rate_max); | ||
449 | } | ||
450 | return 0; | ||
451 | } | ||
452 | |||
diff --git a/sound/usb/stream.h b/sound/usb/stream.h new file mode 100644 index 000000000000..c97f679fc84f --- /dev/null +++ b/sound/usb/stream.h | |||
@@ -0,0 +1,12 @@ | |||
1 | #ifndef __USBAUDIO_STREAM_H | ||
2 | #define __USBAUDIO_STREAM_H | ||
3 | |||
4 | int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, | ||
5 | int iface_no); | ||
6 | |||
7 | int snd_usb_add_audio_stream(struct snd_usb_audio *chip, | ||
8 | int stream, | ||
9 | struct audioformat *fp); | ||
10 | |||
11 | #endif /* __USBAUDIO_STREAM_H */ | ||
12 | |||
diff --git a/sound/usb/urb.c b/sound/usb/urb.c deleted file mode 100644 index e184349aee83..000000000000 --- a/sound/usb/urb.c +++ /dev/null | |||
@@ -1,941 +0,0 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify | ||
3 | * it under the terms of the GNU General Public License as published by | ||
4 | * the Free Software Foundation; either version 2 of the License, or | ||
5 | * (at your option) any later version. | ||
6 | * | ||
7 | * This program is distributed in the hope that it will be useful, | ||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | * GNU General Public License for more details. | ||
11 | * | ||
12 | * You should have received a copy of the GNU General Public License | ||
13 | * along with this program; if not, write to the Free Software | ||
14 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
15 | * | ||
16 | */ | ||
17 | |||
18 | #include <linux/gfp.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/usb.h> | ||
21 | #include <linux/usb/audio.h> | ||
22 | |||
23 | #include <sound/core.h> | ||
24 | #include <sound/pcm.h> | ||
25 | |||
26 | #include "usbaudio.h" | ||
27 | #include "helper.h" | ||
28 | #include "card.h" | ||
29 | #include "urb.h" | ||
30 | #include "pcm.h" | ||
31 | |||
32 | /* | ||
33 | * convert a sampling rate into our full speed format (fs/1000 in Q16.16) | ||
34 | * this will overflow at approx 524 kHz | ||
35 | */ | ||
36 | static inline unsigned get_usb_full_speed_rate(unsigned int rate) | ||
37 | { | ||
38 | return ((rate << 13) + 62) / 125; | ||
39 | } | ||
40 | |||
41 | /* | ||
42 | * convert a sampling rate into USB high speed format (fs/8000 in Q16.16) | ||
43 | * this will overflow at approx 4 MHz | ||
44 | */ | ||
45 | static inline unsigned get_usb_high_speed_rate(unsigned int rate) | ||
46 | { | ||
47 | return ((rate << 10) + 62) / 125; | ||
48 | } | ||
49 | |||
50 | /* | ||
51 | * unlink active urbs. | ||
52 | */ | ||
53 | static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sleep) | ||
54 | { | ||
55 | struct snd_usb_audio *chip = subs->stream->chip; | ||
56 | unsigned int i; | ||
57 | int async; | ||
58 | |||
59 | subs->running = 0; | ||
60 | |||
61 | if (!force && subs->stream->chip->shutdown) /* to be sure... */ | ||
62 | return -EBADFD; | ||
63 | |||
64 | async = !can_sleep && chip->async_unlink; | ||
65 | |||
66 | if (!async && in_interrupt()) | ||
67 | return 0; | ||
68 | |||
69 | for (i = 0; i < subs->nurbs; i++) { | ||
70 | if (test_bit(i, &subs->active_mask)) { | ||
71 | if (!test_and_set_bit(i, &subs->unlink_mask)) { | ||
72 | struct urb *u = subs->dataurb[i].urb; | ||
73 | if (async) | ||
74 | usb_unlink_urb(u); | ||
75 | else | ||
76 | usb_kill_urb(u); | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | if (subs->syncpipe) { | ||
81 | for (i = 0; i < SYNC_URBS; i++) { | ||
82 | if (test_bit(i+16, &subs->active_mask)) { | ||
83 | if (!test_and_set_bit(i+16, &subs->unlink_mask)) { | ||
84 | struct urb *u = subs->syncurb[i].urb; | ||
85 | if (async) | ||
86 | usb_unlink_urb(u); | ||
87 | else | ||
88 | usb_kill_urb(u); | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | |||
97 | /* | ||
98 | * release a urb data | ||
99 | */ | ||
100 | static void release_urb_ctx(struct snd_urb_ctx *u) | ||
101 | { | ||
102 | if (u->urb) { | ||
103 | if (u->buffer_size) | ||
104 | usb_free_coherent(u->subs->dev, u->buffer_size, | ||
105 | u->urb->transfer_buffer, | ||
106 | u->urb->transfer_dma); | ||
107 | usb_free_urb(u->urb); | ||
108 | u->urb = NULL; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | /* | ||
113 | * wait until all urbs are processed. | ||
114 | */ | ||
115 | static int wait_clear_urbs(struct snd_usb_substream *subs) | ||
116 | { | ||
117 | unsigned long end_time = jiffies + msecs_to_jiffies(1000); | ||
118 | unsigned int i; | ||
119 | int alive; | ||
120 | |||
121 | do { | ||
122 | alive = 0; | ||
123 | for (i = 0; i < subs->nurbs; i++) { | ||
124 | if (test_bit(i, &subs->active_mask)) | ||
125 | alive++; | ||
126 | } | ||
127 | if (subs->syncpipe) { | ||
128 | for (i = 0; i < SYNC_URBS; i++) { | ||
129 | if (test_bit(i + 16, &subs->active_mask)) | ||
130 | alive++; | ||
131 | } | ||
132 | } | ||
133 | if (! alive) | ||
134 | break; | ||
135 | schedule_timeout_uninterruptible(1); | ||
136 | } while (time_before(jiffies, end_time)); | ||
137 | if (alive) | ||
138 | snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive); | ||
139 | return 0; | ||
140 | } | ||
141 | |||
142 | /* | ||
143 | * release a substream | ||
144 | */ | ||
145 | void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force) | ||
146 | { | ||
147 | int i; | ||
148 | |||
149 | /* stop urbs (to be sure) */ | ||
150 | deactivate_urbs(subs, force, 1); | ||
151 | wait_clear_urbs(subs); | ||
152 | |||
153 | for (i = 0; i < MAX_URBS; i++) | ||
154 | release_urb_ctx(&subs->dataurb[i]); | ||
155 | for (i = 0; i < SYNC_URBS; i++) | ||
156 | release_urb_ctx(&subs->syncurb[i]); | ||
157 | usb_free_coherent(subs->dev, SYNC_URBS * 4, | ||
158 | subs->syncbuf, subs->sync_dma); | ||
159 | subs->syncbuf = NULL; | ||
160 | subs->nurbs = 0; | ||
161 | } | ||
162 | |||
163 | /* | ||
164 | * complete callback from data urb | ||
165 | */ | ||
166 | static void snd_complete_urb(struct urb *urb) | ||
167 | { | ||
168 | struct snd_urb_ctx *ctx = urb->context; | ||
169 | struct snd_usb_substream *subs = ctx->subs; | ||
170 | struct snd_pcm_substream *substream = ctx->subs->pcm_substream; | ||
171 | int err = 0; | ||
172 | |||
173 | if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) || | ||
174 | !subs->running || /* can be stopped during retire callback */ | ||
175 | (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 || | ||
176 | (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | ||
177 | clear_bit(ctx->index, &subs->active_mask); | ||
178 | if (err < 0) { | ||
179 | snd_printd(KERN_ERR "cannot submit urb (err = %d)\n", err); | ||
180 | snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | |||
185 | |||
186 | /* | ||
187 | * complete callback from sync urb | ||
188 | */ | ||
189 | static void snd_complete_sync_urb(struct urb *urb) | ||
190 | { | ||
191 | struct snd_urb_ctx *ctx = urb->context; | ||
192 | struct snd_usb_substream *subs = ctx->subs; | ||
193 | struct snd_pcm_substream *substream = ctx->subs->pcm_substream; | ||
194 | int err = 0; | ||
195 | |||
196 | if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) || | ||
197 | !subs->running || /* can be stopped during retire callback */ | ||
198 | (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 || | ||
199 | (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | ||
200 | clear_bit(ctx->index + 16, &subs->active_mask); | ||
201 | if (err < 0) { | ||
202 | snd_printd(KERN_ERR "cannot submit sync urb (err = %d)\n", err); | ||
203 | snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | |||
208 | |||
209 | /* | ||
210 | * initialize a substream for plaback/capture | ||
211 | */ | ||
212 | int snd_usb_init_substream_urbs(struct snd_usb_substream *subs, | ||
213 | unsigned int period_bytes, | ||
214 | unsigned int rate, | ||
215 | unsigned int frame_bits) | ||
216 | { | ||
217 | unsigned int maxsize, i; | ||
218 | int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK; | ||
219 | unsigned int urb_packs, total_packs, packs_per_ms; | ||
220 | struct snd_usb_audio *chip = subs->stream->chip; | ||
221 | |||
222 | /* calculate the frequency in 16.16 format */ | ||
223 | if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) | ||
224 | subs->freqn = get_usb_full_speed_rate(rate); | ||
225 | else | ||
226 | subs->freqn = get_usb_high_speed_rate(rate); | ||
227 | subs->freqm = subs->freqn; | ||
228 | subs->freqshift = INT_MIN; | ||
229 | /* calculate max. frequency */ | ||
230 | if (subs->maxpacksize) { | ||
231 | /* whatever fits into a max. size packet */ | ||
232 | maxsize = subs->maxpacksize; | ||
233 | subs->freqmax = (maxsize / (frame_bits >> 3)) | ||
234 | << (16 - subs->datainterval); | ||
235 | } else { | ||
236 | /* no max. packet size: just take 25% higher than nominal */ | ||
237 | subs->freqmax = subs->freqn + (subs->freqn >> 2); | ||
238 | maxsize = ((subs->freqmax + 0xffff) * (frame_bits >> 3)) | ||
239 | >> (16 - subs->datainterval); | ||
240 | } | ||
241 | subs->phase = 0; | ||
242 | |||
243 | if (subs->fill_max) | ||
244 | subs->curpacksize = subs->maxpacksize; | ||
245 | else | ||
246 | subs->curpacksize = maxsize; | ||
247 | |||
248 | if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL) | ||
249 | packs_per_ms = 8 >> subs->datainterval; | ||
250 | else | ||
251 | packs_per_ms = 1; | ||
252 | |||
253 | if (is_playback) { | ||
254 | urb_packs = max(chip->nrpacks, 1); | ||
255 | urb_packs = min(urb_packs, (unsigned int)MAX_PACKS); | ||
256 | } else | ||
257 | urb_packs = 1; | ||
258 | urb_packs *= packs_per_ms; | ||
259 | if (subs->syncpipe) | ||
260 | urb_packs = min(urb_packs, 1U << subs->syncinterval); | ||
261 | |||
262 | /* decide how many packets to be used */ | ||
263 | if (is_playback) { | ||
264 | unsigned int minsize, maxpacks; | ||
265 | /* determine how small a packet can be */ | ||
266 | minsize = (subs->freqn >> (16 - subs->datainterval)) | ||
267 | * (frame_bits >> 3); | ||
268 | /* with sync from device, assume it can be 12% lower */ | ||
269 | if (subs->syncpipe) | ||
270 | minsize -= minsize >> 3; | ||
271 | minsize = max(minsize, 1u); | ||
272 | total_packs = (period_bytes + minsize - 1) / minsize; | ||
273 | /* we need at least two URBs for queueing */ | ||
274 | if (total_packs < 2) { | ||
275 | total_packs = 2; | ||
276 | } else { | ||
277 | /* and we don't want too long a queue either */ | ||
278 | maxpacks = max(MAX_QUEUE * packs_per_ms, urb_packs * 2); | ||
279 | total_packs = min(total_packs, maxpacks); | ||
280 | } | ||
281 | } else { | ||
282 | while (urb_packs > 1 && urb_packs * maxsize >= period_bytes) | ||
283 | urb_packs >>= 1; | ||
284 | total_packs = MAX_URBS * urb_packs; | ||
285 | } | ||
286 | subs->nurbs = (total_packs + urb_packs - 1) / urb_packs; | ||
287 | if (subs->nurbs > MAX_URBS) { | ||
288 | /* too much... */ | ||
289 | subs->nurbs = MAX_URBS; | ||
290 | total_packs = MAX_URBS * urb_packs; | ||
291 | } else if (subs->nurbs < 2) { | ||
292 | /* too little - we need at least two packets | ||
293 | * to ensure contiguous playback/capture | ||
294 | */ | ||
295 | subs->nurbs = 2; | ||
296 | } | ||
297 | |||
298 | /* allocate and initialize data urbs */ | ||
299 | for (i = 0; i < subs->nurbs; i++) { | ||
300 | struct snd_urb_ctx *u = &subs->dataurb[i]; | ||
301 | u->index = i; | ||
302 | u->subs = subs; | ||
303 | u->packets = (i + 1) * total_packs / subs->nurbs | ||
304 | - i * total_packs / subs->nurbs; | ||
305 | u->buffer_size = maxsize * u->packets; | ||
306 | if (subs->fmt_type == UAC_FORMAT_TYPE_II) | ||
307 | u->packets++; /* for transfer delimiter */ | ||
308 | u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); | ||
309 | if (!u->urb) | ||
310 | goto out_of_memory; | ||
311 | u->urb->transfer_buffer = | ||
312 | usb_alloc_coherent(subs->dev, u->buffer_size, | ||
313 | GFP_KERNEL, &u->urb->transfer_dma); | ||
314 | if (!u->urb->transfer_buffer) | ||
315 | goto out_of_memory; | ||
316 | u->urb->pipe = subs->datapipe; | ||
317 | u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; | ||
318 | u->urb->interval = 1 << subs->datainterval; | ||
319 | u->urb->context = u; | ||
320 | u->urb->complete = snd_complete_urb; | ||
321 | } | ||
322 | |||
323 | if (subs->syncpipe) { | ||
324 | /* allocate and initialize sync urbs */ | ||
325 | subs->syncbuf = usb_alloc_coherent(subs->dev, SYNC_URBS * 4, | ||
326 | GFP_KERNEL, &subs->sync_dma); | ||
327 | if (!subs->syncbuf) | ||
328 | goto out_of_memory; | ||
329 | for (i = 0; i < SYNC_URBS; i++) { | ||
330 | struct snd_urb_ctx *u = &subs->syncurb[i]; | ||
331 | u->index = i; | ||
332 | u->subs = subs; | ||
333 | u->packets = 1; | ||
334 | u->urb = usb_alloc_urb(1, GFP_KERNEL); | ||
335 | if (!u->urb) | ||
336 | goto out_of_memory; | ||
337 | u->urb->transfer_buffer = subs->syncbuf + i * 4; | ||
338 | u->urb->transfer_dma = subs->sync_dma + i * 4; | ||
339 | u->urb->transfer_buffer_length = 4; | ||
340 | u->urb->pipe = subs->syncpipe; | ||
341 | u->urb->transfer_flags = URB_ISO_ASAP | | ||
342 | URB_NO_TRANSFER_DMA_MAP; | ||
343 | u->urb->number_of_packets = 1; | ||
344 | u->urb->interval = 1 << subs->syncinterval; | ||
345 | u->urb->context = u; | ||
346 | u->urb->complete = snd_complete_sync_urb; | ||
347 | } | ||
348 | } | ||
349 | return 0; | ||
350 | |||
351 | out_of_memory: | ||
352 | snd_usb_release_substream_urbs(subs, 0); | ||
353 | return -ENOMEM; | ||
354 | } | ||
355 | |||
356 | /* | ||
357 | * prepare urb for full speed capture sync pipe | ||
358 | * | ||
359 | * fill the length and offset of each urb descriptor. | ||
360 | * the fixed 10.14 frequency is passed through the pipe. | ||
361 | */ | ||
362 | static int prepare_capture_sync_urb(struct snd_usb_substream *subs, | ||
363 | struct snd_pcm_runtime *runtime, | ||
364 | struct urb *urb) | ||
365 | { | ||
366 | unsigned char *cp = urb->transfer_buffer; | ||
367 | struct snd_urb_ctx *ctx = urb->context; | ||
368 | |||
369 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | ||
370 | urb->iso_frame_desc[0].length = 3; | ||
371 | urb->iso_frame_desc[0].offset = 0; | ||
372 | cp[0] = subs->freqn >> 2; | ||
373 | cp[1] = subs->freqn >> 10; | ||
374 | cp[2] = subs->freqn >> 18; | ||
375 | return 0; | ||
376 | } | ||
377 | |||
378 | /* | ||
379 | * prepare urb for high speed capture sync pipe | ||
380 | * | ||
381 | * fill the length and offset of each urb descriptor. | ||
382 | * the fixed 12.13 frequency is passed as 16.16 through the pipe. | ||
383 | */ | ||
384 | static int prepare_capture_sync_urb_hs(struct snd_usb_substream *subs, | ||
385 | struct snd_pcm_runtime *runtime, | ||
386 | struct urb *urb) | ||
387 | { | ||
388 | unsigned char *cp = urb->transfer_buffer; | ||
389 | struct snd_urb_ctx *ctx = urb->context; | ||
390 | |||
391 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | ||
392 | urb->iso_frame_desc[0].length = 4; | ||
393 | urb->iso_frame_desc[0].offset = 0; | ||
394 | cp[0] = subs->freqn; | ||
395 | cp[1] = subs->freqn >> 8; | ||
396 | cp[2] = subs->freqn >> 16; | ||
397 | cp[3] = subs->freqn >> 24; | ||
398 | return 0; | ||
399 | } | ||
400 | |||
401 | /* | ||
402 | * process after capture sync complete | ||
403 | * - nothing to do | ||
404 | */ | ||
405 | static int retire_capture_sync_urb(struct snd_usb_substream *subs, | ||
406 | struct snd_pcm_runtime *runtime, | ||
407 | struct urb *urb) | ||
408 | { | ||
409 | return 0; | ||
410 | } | ||
411 | |||
412 | /* | ||
413 | * prepare urb for capture data pipe | ||
414 | * | ||
415 | * fill the offset and length of each descriptor. | ||
416 | * | ||
417 | * we use a temporary buffer to write the captured data. | ||
418 | * since the length of written data is determined by host, we cannot | ||
419 | * write onto the pcm buffer directly... the data is thus copied | ||
420 | * later at complete callback to the global buffer. | ||
421 | */ | ||
422 | static int prepare_capture_urb(struct snd_usb_substream *subs, | ||
423 | struct snd_pcm_runtime *runtime, | ||
424 | struct urb *urb) | ||
425 | { | ||
426 | int i, offs; | ||
427 | struct snd_urb_ctx *ctx = urb->context; | ||
428 | |||
429 | offs = 0; | ||
430 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | ||
431 | for (i = 0; i < ctx->packets; i++) { | ||
432 | urb->iso_frame_desc[i].offset = offs; | ||
433 | urb->iso_frame_desc[i].length = subs->curpacksize; | ||
434 | offs += subs->curpacksize; | ||
435 | } | ||
436 | urb->transfer_buffer_length = offs; | ||
437 | urb->number_of_packets = ctx->packets; | ||
438 | return 0; | ||
439 | } | ||
440 | |||
441 | /* | ||
442 | * process after capture complete | ||
443 | * | ||
444 | * copy the data from each desctiptor to the pcm buffer, and | ||
445 | * update the current position. | ||
446 | */ | ||
447 | static int retire_capture_urb(struct snd_usb_substream *subs, | ||
448 | struct snd_pcm_runtime *runtime, | ||
449 | struct urb *urb) | ||
450 | { | ||
451 | unsigned long flags; | ||
452 | unsigned char *cp; | ||
453 | int i; | ||
454 | unsigned int stride, frames, bytes, oldptr; | ||
455 | int period_elapsed = 0; | ||
456 | |||
457 | stride = runtime->frame_bits >> 3; | ||
458 | |||
459 | for (i = 0; i < urb->number_of_packets; i++) { | ||
460 | cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset; | ||
461 | if (urb->iso_frame_desc[i].status) { | ||
462 | snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status); | ||
463 | // continue; | ||
464 | } | ||
465 | bytes = urb->iso_frame_desc[i].actual_length; | ||
466 | frames = bytes / stride; | ||
467 | if (!subs->txfr_quirk) | ||
468 | bytes = frames * stride; | ||
469 | if (bytes % (runtime->sample_bits >> 3) != 0) { | ||
470 | #ifdef CONFIG_SND_DEBUG_VERBOSE | ||
471 | int oldbytes = bytes; | ||
472 | #endif | ||
473 | bytes = frames * stride; | ||
474 | snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n", | ||
475 | oldbytes, bytes); | ||
476 | } | ||
477 | /* update the current pointer */ | ||
478 | spin_lock_irqsave(&subs->lock, flags); | ||
479 | oldptr = subs->hwptr_done; | ||
480 | subs->hwptr_done += bytes; | ||
481 | if (subs->hwptr_done >= runtime->buffer_size * stride) | ||
482 | subs->hwptr_done -= runtime->buffer_size * stride; | ||
483 | frames = (bytes + (oldptr % stride)) / stride; | ||
484 | subs->transfer_done += frames; | ||
485 | if (subs->transfer_done >= runtime->period_size) { | ||
486 | subs->transfer_done -= runtime->period_size; | ||
487 | period_elapsed = 1; | ||
488 | } | ||
489 | spin_unlock_irqrestore(&subs->lock, flags); | ||
490 | /* copy a data chunk */ | ||
491 | if (oldptr + bytes > runtime->buffer_size * stride) { | ||
492 | unsigned int bytes1 = | ||
493 | runtime->buffer_size * stride - oldptr; | ||
494 | memcpy(runtime->dma_area + oldptr, cp, bytes1); | ||
495 | memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1); | ||
496 | } else { | ||
497 | memcpy(runtime->dma_area + oldptr, cp, bytes); | ||
498 | } | ||
499 | } | ||
500 | if (period_elapsed) | ||
501 | snd_pcm_period_elapsed(subs->pcm_substream); | ||
502 | return 0; | ||
503 | } | ||
504 | |||
505 | /* | ||
506 | * Process after capture complete when paused. Nothing to do. | ||
507 | */ | ||
508 | static int retire_paused_capture_urb(struct snd_usb_substream *subs, | ||
509 | struct snd_pcm_runtime *runtime, | ||
510 | struct urb *urb) | ||
511 | { | ||
512 | return 0; | ||
513 | } | ||
514 | |||
515 | |||
516 | /* | ||
517 | * prepare urb for playback sync pipe | ||
518 | * | ||
519 | * set up the offset and length to receive the current frequency. | ||
520 | */ | ||
521 | static int prepare_playback_sync_urb(struct snd_usb_substream *subs, | ||
522 | struct snd_pcm_runtime *runtime, | ||
523 | struct urb *urb) | ||
524 | { | ||
525 | struct snd_urb_ctx *ctx = urb->context; | ||
526 | |||
527 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | ||
528 | urb->iso_frame_desc[0].length = min(4u, ctx->subs->syncmaxsize); | ||
529 | urb->iso_frame_desc[0].offset = 0; | ||
530 | return 0; | ||
531 | } | ||
532 | |||
533 | /* | ||
534 | * process after playback sync complete | ||
535 | * | ||
536 | * Full speed devices report feedback values in 10.14 format as samples per | ||
537 | * frame, high speed devices in 16.16 format as samples per microframe. | ||
538 | * Because the Audio Class 1 spec was written before USB 2.0, many high speed | ||
539 | * devices use a wrong interpretation, some others use an entirely different | ||
540 | * format. Therefore, we cannot predict what format any particular device uses | ||
541 | * and must detect it automatically. | ||
542 | */ | ||
543 | static int retire_playback_sync_urb(struct snd_usb_substream *subs, | ||
544 | struct snd_pcm_runtime *runtime, | ||
545 | struct urb *urb) | ||
546 | { | ||
547 | unsigned int f; | ||
548 | int shift; | ||
549 | unsigned long flags; | ||
550 | |||
551 | if (urb->iso_frame_desc[0].status != 0 || | ||
552 | urb->iso_frame_desc[0].actual_length < 3) | ||
553 | return 0; | ||
554 | |||
555 | f = le32_to_cpup(urb->transfer_buffer); | ||
556 | if (urb->iso_frame_desc[0].actual_length == 3) | ||
557 | f &= 0x00ffffff; | ||
558 | else | ||
559 | f &= 0x0fffffff; | ||
560 | if (f == 0) | ||
561 | return 0; | ||
562 | |||
563 | if (unlikely(subs->freqshift == INT_MIN)) { | ||
564 | /* | ||
565 | * The first time we see a feedback value, determine its format | ||
566 | * by shifting it left or right until it matches the nominal | ||
567 | * frequency value. This assumes that the feedback does not | ||
568 | * differ from the nominal value more than +50% or -25%. | ||
569 | */ | ||
570 | shift = 0; | ||
571 | while (f < subs->freqn - subs->freqn / 4) { | ||
572 | f <<= 1; | ||
573 | shift++; | ||
574 | } | ||
575 | while (f > subs->freqn + subs->freqn / 2) { | ||
576 | f >>= 1; | ||
577 | shift--; | ||
578 | } | ||
579 | subs->freqshift = shift; | ||
580 | } | ||
581 | else if (subs->freqshift >= 0) | ||
582 | f <<= subs->freqshift; | ||
583 | else | ||
584 | f >>= -subs->freqshift; | ||
585 | |||
586 | if (likely(f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax)) { | ||
587 | /* | ||
588 | * If the frequency looks valid, set it. | ||
589 | * This value is referred to in prepare_playback_urb(). | ||
590 | */ | ||
591 | spin_lock_irqsave(&subs->lock, flags); | ||
592 | subs->freqm = f; | ||
593 | spin_unlock_irqrestore(&subs->lock, flags); | ||
594 | } else { | ||
595 | /* | ||
596 | * Out of range; maybe the shift value is wrong. | ||
597 | * Reset it so that we autodetect again the next time. | ||
598 | */ | ||
599 | subs->freqshift = INT_MIN; | ||
600 | } | ||
601 | |||
602 | return 0; | ||
603 | } | ||
604 | |||
605 | /* determine the number of frames in the next packet */ | ||
606 | static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs) | ||
607 | { | ||
608 | if (subs->fill_max) | ||
609 | return subs->maxframesize; | ||
610 | else { | ||
611 | subs->phase = (subs->phase & 0xffff) | ||
612 | + (subs->freqm << subs->datainterval); | ||
613 | return min(subs->phase >> 16, subs->maxframesize); | ||
614 | } | ||
615 | } | ||
616 | |||
617 | /* | ||
618 | * Prepare urb for streaming before playback starts or when paused. | ||
619 | * | ||
620 | * We don't have any data, so we send silence. | ||
621 | */ | ||
622 | static int prepare_nodata_playback_urb(struct snd_usb_substream *subs, | ||
623 | struct snd_pcm_runtime *runtime, | ||
624 | struct urb *urb) | ||
625 | { | ||
626 | unsigned int i, offs, counts; | ||
627 | struct snd_urb_ctx *ctx = urb->context; | ||
628 | int stride = runtime->frame_bits >> 3; | ||
629 | |||
630 | offs = 0; | ||
631 | urb->dev = ctx->subs->dev; | ||
632 | for (i = 0; i < ctx->packets; ++i) { | ||
633 | counts = snd_usb_audio_next_packet_size(subs); | ||
634 | urb->iso_frame_desc[i].offset = offs * stride; | ||
635 | urb->iso_frame_desc[i].length = counts * stride; | ||
636 | offs += counts; | ||
637 | } | ||
638 | urb->number_of_packets = ctx->packets; | ||
639 | urb->transfer_buffer_length = offs * stride; | ||
640 | memset(urb->transfer_buffer, | ||
641 | runtime->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0, | ||
642 | offs * stride); | ||
643 | return 0; | ||
644 | } | ||
645 | |||
646 | /* | ||
647 | * prepare urb for playback data pipe | ||
648 | * | ||
649 | * Since a URB can handle only a single linear buffer, we must use double | ||
650 | * buffering when the data to be transferred overflows the buffer boundary. | ||
651 | * To avoid inconsistencies when updating hwptr_done, we use double buffering | ||
652 | * for all URBs. | ||
653 | */ | ||
654 | static int prepare_playback_urb(struct snd_usb_substream *subs, | ||
655 | struct snd_pcm_runtime *runtime, | ||
656 | struct urb *urb) | ||
657 | { | ||
658 | int i, stride; | ||
659 | unsigned int counts, frames, bytes; | ||
660 | unsigned long flags; | ||
661 | int period_elapsed = 0; | ||
662 | struct snd_urb_ctx *ctx = urb->context; | ||
663 | |||
664 | stride = runtime->frame_bits >> 3; | ||
665 | |||
666 | frames = 0; | ||
667 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | ||
668 | urb->number_of_packets = 0; | ||
669 | spin_lock_irqsave(&subs->lock, flags); | ||
670 | for (i = 0; i < ctx->packets; i++) { | ||
671 | counts = snd_usb_audio_next_packet_size(subs); | ||
672 | /* set up descriptor */ | ||
673 | urb->iso_frame_desc[i].offset = frames * stride; | ||
674 | urb->iso_frame_desc[i].length = counts * stride; | ||
675 | frames += counts; | ||
676 | urb->number_of_packets++; | ||
677 | subs->transfer_done += counts; | ||
678 | if (subs->transfer_done >= runtime->period_size) { | ||
679 | subs->transfer_done -= runtime->period_size; | ||
680 | period_elapsed = 1; | ||
681 | if (subs->fmt_type == UAC_FORMAT_TYPE_II) { | ||
682 | if (subs->transfer_done > 0) { | ||
683 | /* FIXME: fill-max mode is not | ||
684 | * supported yet */ | ||
685 | frames -= subs->transfer_done; | ||
686 | counts -= subs->transfer_done; | ||
687 | urb->iso_frame_desc[i].length = | ||
688 | counts * stride; | ||
689 | subs->transfer_done = 0; | ||
690 | } | ||
691 | i++; | ||
692 | if (i < ctx->packets) { | ||
693 | /* add a transfer delimiter */ | ||
694 | urb->iso_frame_desc[i].offset = | ||
695 | frames * stride; | ||
696 | urb->iso_frame_desc[i].length = 0; | ||
697 | urb->number_of_packets++; | ||
698 | } | ||
699 | break; | ||
700 | } | ||
701 | } | ||
702 | if (period_elapsed) /* finish at the period boundary */ | ||
703 | break; | ||
704 | } | ||
705 | bytes = frames * stride; | ||
706 | if (subs->hwptr_done + bytes > runtime->buffer_size * stride) { | ||
707 | /* err, the transferred area goes over buffer boundary. */ | ||
708 | unsigned int bytes1 = | ||
709 | runtime->buffer_size * stride - subs->hwptr_done; | ||
710 | memcpy(urb->transfer_buffer, | ||
711 | runtime->dma_area + subs->hwptr_done, bytes1); | ||
712 | memcpy(urb->transfer_buffer + bytes1, | ||
713 | runtime->dma_area, bytes - bytes1); | ||
714 | } else { | ||
715 | memcpy(urb->transfer_buffer, | ||
716 | runtime->dma_area + subs->hwptr_done, bytes); | ||
717 | } | ||
718 | subs->hwptr_done += bytes; | ||
719 | if (subs->hwptr_done >= runtime->buffer_size * stride) | ||
720 | subs->hwptr_done -= runtime->buffer_size * stride; | ||
721 | runtime->delay += frames; | ||
722 | spin_unlock_irqrestore(&subs->lock, flags); | ||
723 | urb->transfer_buffer_length = bytes; | ||
724 | if (period_elapsed) | ||
725 | snd_pcm_period_elapsed(subs->pcm_substream); | ||
726 | return 0; | ||
727 | } | ||
728 | |||
729 | /* | ||
730 | * process after playback data complete | ||
731 | * - decrease the delay count again | ||
732 | */ | ||
733 | static int retire_playback_urb(struct snd_usb_substream *subs, | ||
734 | struct snd_pcm_runtime *runtime, | ||
735 | struct urb *urb) | ||
736 | { | ||
737 | unsigned long flags; | ||
738 | int stride = runtime->frame_bits >> 3; | ||
739 | int processed = urb->transfer_buffer_length / stride; | ||
740 | |||
741 | spin_lock_irqsave(&subs->lock, flags); | ||
742 | if (processed > runtime->delay) | ||
743 | runtime->delay = 0; | ||
744 | else | ||
745 | runtime->delay -= processed; | ||
746 | spin_unlock_irqrestore(&subs->lock, flags); | ||
747 | return 0; | ||
748 | } | ||
749 | |||
750 | static const char *usb_error_string(int err) | ||
751 | { | ||
752 | switch (err) { | ||
753 | case -ENODEV: | ||
754 | return "no device"; | ||
755 | case -ENOENT: | ||
756 | return "endpoint not enabled"; | ||
757 | case -EPIPE: | ||
758 | return "endpoint stalled"; | ||
759 | case -ENOSPC: | ||
760 | return "not enough bandwidth"; | ||
761 | case -ESHUTDOWN: | ||
762 | return "device disabled"; | ||
763 | case -EHOSTUNREACH: | ||
764 | return "device suspended"; | ||
765 | case -EINVAL: | ||
766 | case -EAGAIN: | ||
767 | case -EFBIG: | ||
768 | case -EMSGSIZE: | ||
769 | return "internal error"; | ||
770 | default: | ||
771 | return "unknown error"; | ||
772 | } | ||
773 | } | ||
774 | |||
775 | /* | ||
776 | * set up and start data/sync urbs | ||
777 | */ | ||
778 | static int start_urbs(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime) | ||
779 | { | ||
780 | unsigned int i; | ||
781 | int err; | ||
782 | |||
783 | if (subs->stream->chip->shutdown) | ||
784 | return -EBADFD; | ||
785 | |||
786 | for (i = 0; i < subs->nurbs; i++) { | ||
787 | if (snd_BUG_ON(!subs->dataurb[i].urb)) | ||
788 | return -EINVAL; | ||
789 | if (subs->ops.prepare(subs, runtime, subs->dataurb[i].urb) < 0) { | ||
790 | snd_printk(KERN_ERR "cannot prepare datapipe for urb %d\n", i); | ||
791 | goto __error; | ||
792 | } | ||
793 | } | ||
794 | if (subs->syncpipe) { | ||
795 | for (i = 0; i < SYNC_URBS; i++) { | ||
796 | if (snd_BUG_ON(!subs->syncurb[i].urb)) | ||
797 | return -EINVAL; | ||
798 | if (subs->ops.prepare_sync(subs, runtime, subs->syncurb[i].urb) < 0) { | ||
799 | snd_printk(KERN_ERR "cannot prepare syncpipe for urb %d\n", i); | ||
800 | goto __error; | ||
801 | } | ||
802 | } | ||
803 | } | ||
804 | |||
805 | subs->active_mask = 0; | ||
806 | subs->unlink_mask = 0; | ||
807 | subs->running = 1; | ||
808 | for (i = 0; i < subs->nurbs; i++) { | ||
809 | err = usb_submit_urb(subs->dataurb[i].urb, GFP_ATOMIC); | ||
810 | if (err < 0) { | ||
811 | snd_printk(KERN_ERR "cannot submit datapipe " | ||
812 | "for urb %d, error %d: %s\n", | ||
813 | i, err, usb_error_string(err)); | ||
814 | goto __error; | ||
815 | } | ||
816 | set_bit(i, &subs->active_mask); | ||
817 | } | ||
818 | if (subs->syncpipe) { | ||
819 | for (i = 0; i < SYNC_URBS; i++) { | ||
820 | err = usb_submit_urb(subs->syncurb[i].urb, GFP_ATOMIC); | ||
821 | if (err < 0) { | ||
822 | snd_printk(KERN_ERR "cannot submit syncpipe " | ||
823 | "for urb %d, error %d: %s\n", | ||
824 | i, err, usb_error_string(err)); | ||
825 | goto __error; | ||
826 | } | ||
827 | set_bit(i + 16, &subs->active_mask); | ||
828 | } | ||
829 | } | ||
830 | return 0; | ||
831 | |||
832 | __error: | ||
833 | // snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN); | ||
834 | deactivate_urbs(subs, 0, 0); | ||
835 | return -EPIPE; | ||
836 | } | ||
837 | |||
838 | |||
839 | /* | ||
840 | */ | ||
841 | static struct snd_urb_ops audio_urb_ops[2] = { | ||
842 | { | ||
843 | .prepare = prepare_nodata_playback_urb, | ||
844 | .retire = retire_playback_urb, | ||
845 | .prepare_sync = prepare_playback_sync_urb, | ||
846 | .retire_sync = retire_playback_sync_urb, | ||
847 | }, | ||
848 | { | ||
849 | .prepare = prepare_capture_urb, | ||
850 | .retire = retire_capture_urb, | ||
851 | .prepare_sync = prepare_capture_sync_urb, | ||
852 | .retire_sync = retire_capture_sync_urb, | ||
853 | }, | ||
854 | }; | ||
855 | |||
856 | /* | ||
857 | * initialize the substream instance. | ||
858 | */ | ||
859 | |||
860 | void snd_usb_init_substream(struct snd_usb_stream *as, | ||
861 | int stream, struct audioformat *fp) | ||
862 | { | ||
863 | struct snd_usb_substream *subs = &as->substream[stream]; | ||
864 | |||
865 | INIT_LIST_HEAD(&subs->fmt_list); | ||
866 | spin_lock_init(&subs->lock); | ||
867 | |||
868 | subs->stream = as; | ||
869 | subs->direction = stream; | ||
870 | subs->dev = as->chip->dev; | ||
871 | subs->txfr_quirk = as->chip->txfr_quirk; | ||
872 | subs->ops = audio_urb_ops[stream]; | ||
873 | if (snd_usb_get_speed(subs->dev) >= USB_SPEED_HIGH) | ||
874 | subs->ops.prepare_sync = prepare_capture_sync_urb_hs; | ||
875 | |||
876 | snd_usb_set_pcm_ops(as->pcm, stream); | ||
877 | |||
878 | list_add_tail(&fp->list, &subs->fmt_list); | ||
879 | subs->formats |= fp->formats; | ||
880 | subs->endpoint = fp->endpoint; | ||
881 | subs->num_formats++; | ||
882 | subs->fmt_type = fp->fmt_type; | ||
883 | } | ||
884 | |||
885 | int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd) | ||
886 | { | ||
887 | struct snd_usb_substream *subs = substream->runtime->private_data; | ||
888 | |||
889 | switch (cmd) { | ||
890 | case SNDRV_PCM_TRIGGER_START: | ||
891 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
892 | subs->ops.prepare = prepare_playback_urb; | ||
893 | return 0; | ||
894 | case SNDRV_PCM_TRIGGER_STOP: | ||
895 | return deactivate_urbs(subs, 0, 0); | ||
896 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
897 | subs->ops.prepare = prepare_nodata_playback_urb; | ||
898 | return 0; | ||
899 | } | ||
900 | |||
901 | return -EINVAL; | ||
902 | } | ||
903 | |||
904 | int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd) | ||
905 | { | ||
906 | struct snd_usb_substream *subs = substream->runtime->private_data; | ||
907 | |||
908 | switch (cmd) { | ||
909 | case SNDRV_PCM_TRIGGER_START: | ||
910 | subs->ops.retire = retire_capture_urb; | ||
911 | return start_urbs(subs, substream->runtime); | ||
912 | case SNDRV_PCM_TRIGGER_STOP: | ||
913 | return deactivate_urbs(subs, 0, 0); | ||
914 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
915 | subs->ops.retire = retire_paused_capture_urb; | ||
916 | return 0; | ||
917 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
918 | subs->ops.retire = retire_capture_urb; | ||
919 | return 0; | ||
920 | } | ||
921 | |||
922 | return -EINVAL; | ||
923 | } | ||
924 | |||
925 | int snd_usb_substream_prepare(struct snd_usb_substream *subs, | ||
926 | struct snd_pcm_runtime *runtime) | ||
927 | { | ||
928 | /* clear urbs (to be sure) */ | ||
929 | deactivate_urbs(subs, 0, 1); | ||
930 | wait_clear_urbs(subs); | ||
931 | |||
932 | /* for playback, submit the URBs now; otherwise, the first hwptr_done | ||
933 | * updates for all URBs would happen at the same time when starting */ | ||
934 | if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) { | ||
935 | subs->ops.prepare = prepare_nodata_playback_urb; | ||
936 | return start_urbs(subs, runtime); | ||
937 | } | ||
938 | |||
939 | return 0; | ||
940 | } | ||
941 | |||
diff --git a/sound/usb/urb.h b/sound/usb/urb.h deleted file mode 100644 index 888da38079cf..000000000000 --- a/sound/usb/urb.h +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | #ifndef __USBAUDIO_URB_H | ||
2 | #define __USBAUDIO_URB_H | ||
3 | |||
4 | void snd_usb_init_substream(struct snd_usb_stream *as, | ||
5 | int stream, | ||
6 | struct audioformat *fp); | ||
7 | |||
8 | int snd_usb_init_substream_urbs(struct snd_usb_substream *subs, | ||
9 | unsigned int period_bytes, | ||
10 | unsigned int rate, | ||
11 | unsigned int frame_bits); | ||
12 | |||
13 | void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force); | ||
14 | |||
15 | int snd_usb_substream_prepare(struct snd_usb_substream *subs, | ||
16 | struct snd_pcm_runtime *runtime); | ||
17 | |||
18 | int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd); | ||
19 | int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd); | ||
20 | |||
21 | #endif /* __USBAUDIO_URB_H */ | ||
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h index 1e79986b5777..3e2b03577936 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h | |||
@@ -80,6 +80,7 @@ enum quirk_type { | |||
80 | QUIRK_MIDI_CME, | 80 | QUIRK_MIDI_CME, |
81 | QUIRK_MIDI_AKAI, | 81 | QUIRK_MIDI_AKAI, |
82 | QUIRK_MIDI_US122L, | 82 | QUIRK_MIDI_US122L, |
83 | QUIRK_MIDI_FTDI, | ||
83 | QUIRK_AUDIO_STANDARD_INTERFACE, | 84 | QUIRK_AUDIO_STANDARD_INTERFACE, |
84 | QUIRK_AUDIO_FIXED_ENDPOINT, | 85 | QUIRK_AUDIO_FIXED_ENDPOINT, |
85 | QUIRK_AUDIO_EDIROL_UAXX, | 86 | QUIRK_AUDIO_EDIROL_UAXX, |