Commit 5e682c0e543a90f7548fecede64f13c4ed378181
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
Merge tag 'sound-3.6' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
Pull sound fixes from Takashi Iwai: "There are nothing scaring, contains only small fixes for HD-audio and USB-audio: - EPSS regression fix and GPIO fix for HD-audio IDT codecs - A series of USB-audio regression fixes that are found since 3.5 kernel" * tag 'sound-3.6' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: ALSA: snd-usb: fix cross-interface streaming devices ALSA: snd-usb: fix calls to next_packet_size ALSA: snd-usb: restore delay information ALSA: snd-usb: use list_for_each_safe for endpoint resources ALSA: snd-usb: Fix URB cancellation at stream start ALSA: hda - Don't trust codec EPSS bit for IDT 92HD83xx & co ALSA: hda - Avoid unnecessary parameter read for EPSS ALSA: hda - Do not set GPIOs for speakers on IDT if there are no speakers
Showing 7 changed files Side-by-side Diff
sound/pci/hda/hda_codec.c
... | ... | @@ -1209,6 +1209,9 @@ |
1209 | 1209 | kfree(codec); |
1210 | 1210 | } |
1211 | 1211 | |
1212 | +static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, | |
1213 | + hda_nid_t fg, unsigned int power_state); | |
1214 | + | |
1212 | 1215 | static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg, |
1213 | 1216 | unsigned int power_state); |
1214 | 1217 | |
... | ... | @@ -1317,6 +1320,10 @@ |
1317 | 1320 | AC_VERB_GET_SUBSYSTEM_ID, 0); |
1318 | 1321 | } |
1319 | 1322 | |
1323 | + codec->epss = snd_hda_codec_get_supported_ps(codec, | |
1324 | + codec->afg ? codec->afg : codec->mfg, | |
1325 | + AC_PWRST_EPSS); | |
1326 | + | |
1320 | 1327 | /* power-up all before initialization */ |
1321 | 1328 | hda_set_power_state(codec, |
1322 | 1329 | codec->afg ? codec->afg : codec->mfg, |
... | ... | @@ -3543,8 +3550,7 @@ |
3543 | 3550 | /* this delay seems necessary to avoid click noise at power-down */ |
3544 | 3551 | if (power_state == AC_PWRST_D3) { |
3545 | 3552 | /* transition time less than 10ms for power down */ |
3546 | - bool epss = snd_hda_codec_get_supported_ps(codec, fg, AC_PWRST_EPSS); | |
3547 | - msleep(epss ? 10 : 100); | |
3553 | + msleep(codec->epss ? 10 : 100); | |
3548 | 3554 | } |
3549 | 3555 | |
3550 | 3556 | /* repeat power states setting at most 10 times*/ |
sound/pci/hda/hda_codec.h
... | ... | @@ -862,6 +862,7 @@ |
862 | 862 | unsigned int ignore_misc_bit:1; /* ignore MISC_NO_PRESENCE bit */ |
863 | 863 | unsigned int no_jack_detect:1; /* Machine has no jack-detection */ |
864 | 864 | unsigned int pcm_format_first:1; /* PCM format must be set first */ |
865 | + unsigned int epss:1; /* supporting EPSS? */ | |
865 | 866 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
866 | 867 | unsigned int power_on :1; /* current (global) power-state */ |
867 | 868 | int power_transition; /* power-state in transition */ |
sound/pci/hda/patch_sigmatel.c
... | ... | @@ -4543,6 +4543,9 @@ |
4543 | 4543 | struct auto_pin_cfg *cfg = &spec->autocfg; |
4544 | 4544 | int i; |
4545 | 4545 | |
4546 | + if (cfg->speaker_outs == 0) | |
4547 | + return; | |
4548 | + | |
4546 | 4549 | for (i = 0; i < cfg->line_outs; i++) { |
4547 | 4550 | if (presence) |
4548 | 4551 | break; |
... | ... | @@ -5531,6 +5534,7 @@ |
5531 | 5534 | snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e); |
5532 | 5535 | } |
5533 | 5536 | |
5537 | + codec->epss = 0; /* longer delay needed for D3 */ | |
5534 | 5538 | codec->no_trigger_sense = 1; |
5535 | 5539 | codec->spec = spec; |
5536 | 5540 |
sound/usb/card.c
... | ... | @@ -553,7 +553,7 @@ |
553 | 553 | struct snd_usb_audio *chip) |
554 | 554 | { |
555 | 555 | struct snd_card *card; |
556 | - struct list_head *p; | |
556 | + struct list_head *p, *n; | |
557 | 557 | |
558 | 558 | if (chip == (void *)-1L) |
559 | 559 | return; |
... | ... | @@ -570,7 +570,7 @@ |
570 | 570 | snd_usb_stream_disconnect(p); |
571 | 571 | } |
572 | 572 | /* release the endpoint resources */ |
573 | - list_for_each(p, &chip->ep_list) { | |
573 | + list_for_each_safe(p, n, &chip->ep_list) { | |
574 | 574 | snd_usb_endpoint_free(p); |
575 | 575 | } |
576 | 576 | /* release the midi resources */ |
sound/usb/endpoint.c
... | ... | @@ -141,7 +141,7 @@ |
141 | 141 | * |
142 | 142 | * For implicit feedback, next_packet_size() is unused. |
143 | 143 | */ |
144 | -static int next_packet_size(struct snd_usb_endpoint *ep) | |
144 | +int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep) | |
145 | 145 | { |
146 | 146 | unsigned long flags; |
147 | 147 | int ret; |
... | ... | @@ -177,15 +177,6 @@ |
177 | 177 | ep->retire_data_urb(ep->data_subs, urb); |
178 | 178 | } |
179 | 179 | |
180 | -static void prepare_outbound_urb_sizes(struct snd_usb_endpoint *ep, | |
181 | - struct snd_urb_ctx *ctx) | |
182 | -{ | |
183 | - int i; | |
184 | - | |
185 | - for (i = 0; i < ctx->packets; ++i) | |
186 | - ctx->packet_size[i] = next_packet_size(ep); | |
187 | -} | |
188 | - | |
189 | 180 | /* |
190 | 181 | * Prepare a PLAYBACK urb for submission to the bus. |
191 | 182 | */ |
... | ... | @@ -370,7 +361,6 @@ |
370 | 361 | goto exit_clear; |
371 | 362 | } |
372 | 363 | |
373 | - prepare_outbound_urb_sizes(ep, ctx); | |
374 | 364 | prepare_outbound_urb(ep, ctx); |
375 | 365 | } else { |
376 | 366 | retire_inbound_urb(ep, ctx); |
... | ... | @@ -799,7 +789,9 @@ |
799 | 789 | /** |
800 | 790 | * snd_usb_endpoint_start: start an snd_usb_endpoint |
801 | 791 | * |
802 | - * @ep: the endpoint to start | |
792 | + * @ep: the endpoint to start | |
793 | + * @can_sleep: flag indicating whether the operation is executed in | |
794 | + * non-atomic context | |
803 | 795 | * |
804 | 796 | * A call to this function will increment the use count of the endpoint. |
805 | 797 | * In case it is not already running, the URBs for this endpoint will be |
... | ... | @@ -809,7 +801,7 @@ |
809 | 801 | * |
810 | 802 | * Returns an error if the URB submission failed, 0 in all other cases. |
811 | 803 | */ |
812 | -int snd_usb_endpoint_start(struct snd_usb_endpoint *ep) | |
804 | +int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, int can_sleep) | |
813 | 805 | { |
814 | 806 | int err; |
815 | 807 | unsigned int i; |
... | ... | @@ -821,6 +813,11 @@ |
821 | 813 | if (++ep->use_count != 1) |
822 | 814 | return 0; |
823 | 815 | |
816 | + /* just to be sure */ | |
817 | + deactivate_urbs(ep, 0, can_sleep); | |
818 | + if (can_sleep) | |
819 | + wait_clear_urbs(ep); | |
820 | + | |
824 | 821 | ep->active_mask = 0; |
825 | 822 | ep->unlink_mask = 0; |
826 | 823 | ep->phase = 0; |
... | ... | @@ -850,7 +847,6 @@ |
850 | 847 | goto __error; |
851 | 848 | |
852 | 849 | if (usb_pipeout(ep->pipe)) { |
853 | - prepare_outbound_urb_sizes(ep, urb->context); | |
854 | 850 | prepare_outbound_urb(ep, urb->context); |
855 | 851 | } else { |
856 | 852 | prepare_inbound_urb(ep, urb->context); |
sound/usb/endpoint.h
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | struct audioformat *fmt, |
14 | 14 | struct snd_usb_endpoint *sync_ep); |
15 | 15 | |
16 | -int snd_usb_endpoint_start(struct snd_usb_endpoint *ep); | |
16 | +int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, int can_sleep); | |
17 | 17 | void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep, |
18 | 18 | int force, int can_sleep, int wait); |
19 | 19 | int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep); |
... | ... | @@ -21,6 +21,7 @@ |
21 | 21 | void snd_usb_endpoint_free(struct list_head *head); |
22 | 22 | |
23 | 23 | int snd_usb_endpoint_implict_feedback_sink(struct snd_usb_endpoint *ep); |
24 | +int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep); | |
24 | 25 | |
25 | 26 | void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep, |
26 | 27 | struct snd_usb_endpoint *sender, |
sound/usb/pcm.c
... | ... | @@ -212,7 +212,7 @@ |
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | -static int start_endpoints(struct snd_usb_substream *subs) | |
215 | +static int start_endpoints(struct snd_usb_substream *subs, int can_sleep) | |
216 | 216 | { |
217 | 217 | int err; |
218 | 218 | |
... | ... | @@ -225,7 +225,7 @@ |
225 | 225 | snd_printdd(KERN_DEBUG "Starting data EP @%p\n", ep); |
226 | 226 | |
227 | 227 | ep->data_subs = subs; |
228 | - err = snd_usb_endpoint_start(ep); | |
228 | + err = snd_usb_endpoint_start(ep, can_sleep); | |
229 | 229 | if (err < 0) { |
230 | 230 | clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags); |
231 | 231 | return err; |
232 | 232 | |
... | ... | @@ -236,10 +236,25 @@ |
236 | 236 | !test_and_set_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags)) { |
237 | 237 | struct snd_usb_endpoint *ep = subs->sync_endpoint; |
238 | 238 | |
239 | + if (subs->data_endpoint->iface != subs->sync_endpoint->iface || | |
240 | + subs->data_endpoint->alt_idx != subs->sync_endpoint->alt_idx) { | |
241 | + err = usb_set_interface(subs->dev, | |
242 | + subs->sync_endpoint->iface, | |
243 | + subs->sync_endpoint->alt_idx); | |
244 | + if (err < 0) { | |
245 | + snd_printk(KERN_ERR | |
246 | + "%d:%d:%d: cannot set interface (%d)\n", | |
247 | + subs->dev->devnum, | |
248 | + subs->sync_endpoint->iface, | |
249 | + subs->sync_endpoint->alt_idx, err); | |
250 | + return -EIO; | |
251 | + } | |
252 | + } | |
253 | + | |
239 | 254 | snd_printdd(KERN_DEBUG "Starting sync EP @%p\n", ep); |
240 | 255 | |
241 | 256 | ep->sync_slave = subs->data_endpoint; |
242 | - err = snd_usb_endpoint_start(ep); | |
257 | + err = snd_usb_endpoint_start(ep, can_sleep); | |
243 | 258 | if (err < 0) { |
244 | 259 | clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags); |
245 | 260 | return err; |
246 | 261 | |
... | ... | @@ -544,13 +559,10 @@ |
544 | 559 | subs->last_frame_number = 0; |
545 | 560 | runtime->delay = 0; |
546 | 561 | |
547 | - /* clear the pending deactivation on the target EPs */ | |
548 | - deactivate_endpoints(subs); | |
549 | - | |
550 | 562 | /* for playback, submit the URBs now; otherwise, the first hwptr_done |
551 | 563 | * updates for all URBs would happen at the same time when starting */ |
552 | 564 | if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) |
553 | - return start_endpoints(subs); | |
565 | + return start_endpoints(subs, 1); | |
554 | 566 | |
555 | 567 | return 0; |
556 | 568 | } |
... | ... | @@ -1032,6 +1044,7 @@ |
1032 | 1044 | struct urb *urb) |
1033 | 1045 | { |
1034 | 1046 | struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; |
1047 | + struct snd_usb_endpoint *ep = subs->data_endpoint; | |
1035 | 1048 | struct snd_urb_ctx *ctx = urb->context; |
1036 | 1049 | unsigned int counts, frames, bytes; |
1037 | 1050 | int i, stride, period_elapsed = 0; |
... | ... | @@ -1043,7 +1056,11 @@ |
1043 | 1056 | urb->number_of_packets = 0; |
1044 | 1057 | spin_lock_irqsave(&subs->lock, flags); |
1045 | 1058 | for (i = 0; i < ctx->packets; i++) { |
1046 | - counts = ctx->packet_size[i]; | |
1059 | + if (ctx->packet_size[i]) | |
1060 | + counts = ctx->packet_size[i]; | |
1061 | + else | |
1062 | + counts = snd_usb_endpoint_next_packet_size(ep); | |
1063 | + | |
1047 | 1064 | /* set up descriptor */ |
1048 | 1065 | urb->iso_frame_desc[i].offset = frames * stride; |
1049 | 1066 | urb->iso_frame_desc[i].length = counts * stride; |
1050 | 1067 | |
... | ... | @@ -1094,7 +1111,16 @@ |
1094 | 1111 | subs->hwptr_done += bytes; |
1095 | 1112 | if (subs->hwptr_done >= runtime->buffer_size * stride) |
1096 | 1113 | subs->hwptr_done -= runtime->buffer_size * stride; |
1114 | + | |
1115 | + /* update delay with exact number of samples queued */ | |
1116 | + runtime->delay = subs->last_delay; | |
1097 | 1117 | runtime->delay += frames; |
1118 | + subs->last_delay = runtime->delay; | |
1119 | + | |
1120 | + /* realign last_frame_number */ | |
1121 | + subs->last_frame_number = usb_get_current_frame_number(subs->dev); | |
1122 | + subs->last_frame_number &= 0xFF; /* keep 8 LSBs */ | |
1123 | + | |
1098 | 1124 | spin_unlock_irqrestore(&subs->lock, flags); |
1099 | 1125 | urb->transfer_buffer_length = bytes; |
1100 | 1126 | if (period_elapsed) |
1101 | 1127 | |
1102 | 1128 | |
... | ... | @@ -1112,12 +1138,26 @@ |
1112 | 1138 | struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; |
1113 | 1139 | int stride = runtime->frame_bits >> 3; |
1114 | 1140 | int processed = urb->transfer_buffer_length / stride; |
1141 | + int est_delay; | |
1115 | 1142 | |
1116 | 1143 | spin_lock_irqsave(&subs->lock, flags); |
1117 | - if (processed > runtime->delay) | |
1118 | - runtime->delay = 0; | |
1144 | + est_delay = snd_usb_pcm_delay(subs, runtime->rate); | |
1145 | + /* update delay with exact number of samples played */ | |
1146 | + if (processed > subs->last_delay) | |
1147 | + subs->last_delay = 0; | |
1119 | 1148 | else |
1120 | - runtime->delay -= processed; | |
1149 | + subs->last_delay -= processed; | |
1150 | + runtime->delay = subs->last_delay; | |
1151 | + | |
1152 | + /* | |
1153 | + * Report when delay estimate is off by more than 2ms. | |
1154 | + * The error should be lower than 2ms since the estimate relies | |
1155 | + * on two reads of a counter updated every ms. | |
1156 | + */ | |
1157 | + if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2) | |
1158 | + snd_printk(KERN_DEBUG "delay: estimated %d, actual %d\n", | |
1159 | + est_delay, subs->last_delay); | |
1160 | + | |
1121 | 1161 | spin_unlock_irqrestore(&subs->lock, flags); |
1122 | 1162 | } |
1123 | 1163 | |
... | ... | @@ -1175,7 +1215,7 @@ |
1175 | 1215 | |
1176 | 1216 | switch (cmd) { |
1177 | 1217 | case SNDRV_PCM_TRIGGER_START: |
1178 | - err = start_endpoints(subs); | |
1218 | + err = start_endpoints(subs, 0); | |
1179 | 1219 | if (err < 0) |
1180 | 1220 | return err; |
1181 | 1221 |