aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDylan Reid <dgreid@chromium.org>2012-09-18 12:49:47 -0400
committerTakashi Iwai <tiwai@suse.de>2012-09-19 02:07:52 -0400
commit35ec7aa29833de350f51922736aefe22ebf76c4d (patch)
tree20509b13b846678dbb8c16277bb0c57c936e735b
parent715a170563843a1f55ae4c8484bc4732d69d2288 (diff)
ALSA: usb-audio: Don't require hw_params in endpoint.
Change the interface to configure an endpoint so that it doesn't require a hw_params struct. This will allow it to be called from prepare instead of hw_params, configuring it after system resume. Signed-off-by: Dylan Reid <dgreid@chromium.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/usb/endpoint.c31
-rw-r--r--sound/usb/endpoint.h5
-rw-r--r--sound/usb/pcm.c16
3 files changed, 35 insertions, 17 deletions
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index a83a18dbac25..152bfd48a311 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -567,20 +567,19 @@ static void release_urbs(struct snd_usb_endpoint *ep, int force)
567 * configure a data endpoint 567 * configure a data endpoint
568 */ 568 */
569static int data_ep_set_params(struct snd_usb_endpoint *ep, 569static int data_ep_set_params(struct snd_usb_endpoint *ep,
570 struct snd_pcm_hw_params *hw_params, 570 snd_pcm_format_t pcm_format,
571 unsigned int channels,
572 unsigned int period_bytes,
571 struct audioformat *fmt, 573 struct audioformat *fmt,
572 struct snd_usb_endpoint *sync_ep) 574 struct snd_usb_endpoint *sync_ep)
573{ 575{
574 unsigned int maxsize, i, urb_packs, total_packs, packs_per_ms; 576 unsigned int maxsize, i, urb_packs, total_packs, packs_per_ms;
575 int period_bytes = params_period_bytes(hw_params);
576 int format = params_format(hw_params);
577 int is_playback = usb_pipeout(ep->pipe); 577 int is_playback = usb_pipeout(ep->pipe);
578 int frame_bits = snd_pcm_format_physical_width(params_format(hw_params)) * 578 int frame_bits = snd_pcm_format_physical_width(pcm_format) * channels;
579 params_channels(hw_params);
580 579
581 ep->datainterval = fmt->datainterval; 580 ep->datainterval = fmt->datainterval;
582 ep->stride = frame_bits >> 3; 581 ep->stride = frame_bits >> 3;
583 ep->silence_value = format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0; 582 ep->silence_value = pcm_format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0;
584 583
585 /* calculate max. frequency */ 584 /* calculate max. frequency */
586 if (ep->maxpacksize) { 585 if (ep->maxpacksize) {
@@ -693,7 +692,6 @@ out_of_memory:
693 * configure a sync endpoint 692 * configure a sync endpoint
694 */ 693 */
695static int sync_ep_set_params(struct snd_usb_endpoint *ep, 694static int sync_ep_set_params(struct snd_usb_endpoint *ep,
696 struct snd_pcm_hw_params *hw_params,
697 struct audioformat *fmt) 695 struct audioformat *fmt)
698{ 696{
699 int i; 697 int i;
@@ -736,7 +734,10 @@ out_of_memory:
736 * snd_usb_endpoint_set_params: configure an snd_usb_endpoint 734 * snd_usb_endpoint_set_params: configure an snd_usb_endpoint
737 * 735 *
738 * @ep: the snd_usb_endpoint to configure 736 * @ep: the snd_usb_endpoint to configure
739 * @hw_params: the hardware parameters 737 * @pcm_format: the audio fomat.
738 * @channels: the number of audio channels.
739 * @period_bytes: the number of bytes in one alsa period.
740 * @rate: the frame rate.
740 * @fmt: the USB audio format information 741 * @fmt: the USB audio format information
741 * @sync_ep: the sync endpoint to use, if any 742 * @sync_ep: the sync endpoint to use, if any
742 * 743 *
@@ -745,7 +746,10 @@ out_of_memory:
745 * An endpoint that is already running can not be reconfigured. 746 * An endpoint that is already running can not be reconfigured.
746 */ 747 */
747int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep, 748int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
748 struct snd_pcm_hw_params *hw_params, 749 snd_pcm_format_t pcm_format,
750 unsigned int channels,
751 unsigned int period_bytes,
752 unsigned int rate,
749 struct audioformat *fmt, 753 struct audioformat *fmt,
750 struct snd_usb_endpoint *sync_ep) 754 struct snd_usb_endpoint *sync_ep)
751{ 755{
@@ -765,9 +769,9 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
765 ep->fill_max = !!(fmt->attributes & UAC_EP_CS_ATTR_FILL_MAX); 769 ep->fill_max = !!(fmt->attributes & UAC_EP_CS_ATTR_FILL_MAX);
766 770
767 if (snd_usb_get_speed(ep->chip->dev) == USB_SPEED_FULL) 771 if (snd_usb_get_speed(ep->chip->dev) == USB_SPEED_FULL)
768 ep->freqn = get_usb_full_speed_rate(params_rate(hw_params)); 772 ep->freqn = get_usb_full_speed_rate(rate);
769 else 773 else
770 ep->freqn = get_usb_high_speed_rate(params_rate(hw_params)); 774 ep->freqn = get_usb_high_speed_rate(rate);
771 775
772 /* calculate the frequency in 16.16 format */ 776 /* calculate the frequency in 16.16 format */
773 ep->freqm = ep->freqn; 777 ep->freqm = ep->freqn;
@@ -777,10 +781,11 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
777 781
778 switch (ep->type) { 782 switch (ep->type) {
779 case SND_USB_ENDPOINT_TYPE_DATA: 783 case SND_USB_ENDPOINT_TYPE_DATA:
780 err = data_ep_set_params(ep, hw_params, fmt, sync_ep); 784 err = data_ep_set_params(ep, pcm_format, channels,
785 period_bytes, fmt, sync_ep);
781 break; 786 break;
782 case SND_USB_ENDPOINT_TYPE_SYNC: 787 case SND_USB_ENDPOINT_TYPE_SYNC:
783 err = sync_ep_set_params(ep, hw_params, fmt); 788 err = sync_ep_set_params(ep, fmt);
784 break; 789 break;
785 default: 790 default:
786 err = -EINVAL; 791 err = -EINVAL;
diff --git a/sound/usb/endpoint.h b/sound/usb/endpoint.h
index cbbbdf226d66..6376ccf10fd4 100644
--- a/sound/usb/endpoint.h
+++ b/sound/usb/endpoint.h
@@ -9,7 +9,10 @@ struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
9 int ep_num, int direction, int type); 9 int ep_num, int direction, int type);
10 10
11int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep, 11int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
12 struct snd_pcm_hw_params *hw_params, 12 snd_pcm_format_t pcm_format,
13 unsigned int channels,
14 unsigned int period_bytes,
15 unsigned int rate,
13 struct audioformat *fmt, 16 struct audioformat *fmt,
14 struct snd_usb_endpoint *sync_ep); 17 struct snd_usb_endpoint *sync_ep);
15 18
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 786f7a05e9a6..62ab4fd5880a 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -491,14 +491,24 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
491 mutex_lock(&subs->stream->chip->shutdown_mutex); 491 mutex_lock(&subs->stream->chip->shutdown_mutex);
492 /* format changed */ 492 /* format changed */
493 stop_endpoints(subs, 0, 0, 0); 493 stop_endpoints(subs, 0, 0, 0);
494 ret = snd_usb_endpoint_set_params(subs->data_endpoint, hw_params, fmt, 494 ret = snd_usb_endpoint_set_params(subs->data_endpoint,
495 format,
496 channels,
497 subs->period_bytes,
498 rate,
499 fmt,
495 subs->sync_endpoint); 500 subs->sync_endpoint);
496 if (ret < 0) 501 if (ret < 0)
497 goto unlock; 502 goto unlock;
498 503
499 if (subs->sync_endpoint) 504 if (subs->sync_endpoint)
500 ret = snd_usb_endpoint_set_params(subs->sync_endpoint, 505 ret = snd_usb_endpoint_set_params(subs->data_endpoint,
501 hw_params, fmt, NULL); 506 format,
507 channels,
508 subs->period_bytes,
509 rate,
510 fmt,
511 NULL);
502unlock: 512unlock:
503 mutex_unlock(&subs->stream->chip->shutdown_mutex); 513 mutex_unlock(&subs->stream->chip->shutdown_mutex);
504 } 514 }