aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sound/firewire/amdtp.c154
-rw-r--r--sound/firewire/amdtp.h64
-rw-r--r--sound/firewire/dice.c46
-rw-r--r--sound/firewire/speakers.c46
4 files changed, 158 insertions, 152 deletions
diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
index 9048777228e2..16fe858925bd 100644
--- a/sound/firewire/amdtp.c
+++ b/sound/firewire/amdtp.c
@@ -34,13 +34,13 @@
34static void pcm_period_tasklet(unsigned long data); 34static void pcm_period_tasklet(unsigned long data);
35 35
36/** 36/**
37 * amdtp_out_stream_init - initialize an AMDTP output stream structure 37 * amdtp_stream_init - initialize an AMDTP stream structure
38 * @s: the AMDTP output stream to initialize 38 * @s: the AMDTP stream to initialize
39 * @unit: the target of the stream 39 * @unit: the target of the stream
40 * @flags: the packet transmission method to use 40 * @flags: the packet transmission method to use
41 */ 41 */
42int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit, 42int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
43 enum cip_out_flags flags) 43 enum cip_flags flags)
44{ 44{
45 s->unit = fw_unit_get(unit); 45 s->unit = fw_unit_get(unit);
46 s->flags = flags; 46 s->flags = flags;
@@ -51,19 +51,19 @@ int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
51 51
52 return 0; 52 return 0;
53} 53}
54EXPORT_SYMBOL(amdtp_out_stream_init); 54EXPORT_SYMBOL(amdtp_stream_init);
55 55
56/** 56/**
57 * amdtp_out_stream_destroy - free stream resources 57 * amdtp_stream_destroy - free stream resources
58 * @s: the AMDTP output stream to destroy 58 * @s: the AMDTP stream to destroy
59 */ 59 */
60void amdtp_out_stream_destroy(struct amdtp_out_stream *s) 60void amdtp_stream_destroy(struct amdtp_stream *s)
61{ 61{
62 WARN_ON(amdtp_out_stream_running(s)); 62 WARN_ON(amdtp_stream_running(s));
63 mutex_destroy(&s->mutex); 63 mutex_destroy(&s->mutex);
64 fw_unit_put(s->unit); 64 fw_unit_put(s->unit);
65} 65}
66EXPORT_SYMBOL(amdtp_out_stream_destroy); 66EXPORT_SYMBOL(amdtp_stream_destroy);
67 67
68const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT] = { 68const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT] = {
69 [CIP_SFC_32000] = 8, 69 [CIP_SFC_32000] = 8,
@@ -77,8 +77,8 @@ const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT] = {
77EXPORT_SYMBOL(amdtp_syt_intervals); 77EXPORT_SYMBOL(amdtp_syt_intervals);
78 78
79/** 79/**
80 * amdtp_out_stream_set_parameters - set stream parameters 80 * amdtp_stream_set_parameters - set stream parameters
81 * @s: the AMDTP output stream to configure 81 * @s: the AMDTP stream to configure
82 * @rate: the sample rate 82 * @rate: the sample rate
83 * @pcm_channels: the number of PCM samples in each data block, to be encoded 83 * @pcm_channels: the number of PCM samples in each data block, to be encoded
84 * as AM824 multi-bit linear audio 84 * as AM824 multi-bit linear audio
@@ -87,10 +87,10 @@ EXPORT_SYMBOL(amdtp_syt_intervals);
87 * The parameters must be set before the stream is started, and must not be 87 * The parameters must be set before the stream is started, and must not be
88 * changed while the stream is running. 88 * changed while the stream is running.
89 */ 89 */
90void amdtp_out_stream_set_parameters(struct amdtp_out_stream *s, 90void amdtp_stream_set_parameters(struct amdtp_stream *s,
91 unsigned int rate, 91 unsigned int rate,
92 unsigned int pcm_channels, 92 unsigned int pcm_channels,
93 unsigned int midi_ports) 93 unsigned int midi_ports)
94{ 94{
95 static const unsigned int rates[] = { 95 static const unsigned int rates[] = {
96 [CIP_SFC_32000] = 32000, 96 [CIP_SFC_32000] = 32000,
@@ -103,7 +103,7 @@ void amdtp_out_stream_set_parameters(struct amdtp_out_stream *s,
103 }; 103 };
104 unsigned int sfc; 104 unsigned int sfc;
105 105
106 if (WARN_ON(amdtp_out_stream_running(s))) 106 if (WARN_ON(amdtp_stream_running(s)))
107 return; 107 return;
108 108
109 for (sfc = 0; sfc < CIP_SFC_COUNT; ++sfc) 109 for (sfc = 0; sfc < CIP_SFC_COUNT; ++sfc)
@@ -132,47 +132,47 @@ sfc_found:
132 /* additional buffering needed to adjust for no-data packets */ 132 /* additional buffering needed to adjust for no-data packets */
133 s->transfer_delay += TICKS_PER_SECOND * s->syt_interval / rate; 133 s->transfer_delay += TICKS_PER_SECOND * s->syt_interval / rate;
134} 134}
135EXPORT_SYMBOL(amdtp_out_stream_set_parameters); 135EXPORT_SYMBOL(amdtp_stream_set_parameters);
136 136
137/** 137/**
138 * amdtp_out_stream_get_max_payload - get the stream's packet size 138 * amdtp_stream_get_max_payload - get the stream's packet size
139 * @s: the AMDTP output stream 139 * @s: the AMDTP stream
140 * 140 *
141 * This function must not be called before the stream has been configured 141 * This function must not be called before the stream has been configured
142 * with amdtp_out_stream_set_parameters(). 142 * with amdtp_stream_set_parameters().
143 */ 143 */
144unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s) 144unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s)
145{ 145{
146 return 8 + s->syt_interval * s->data_block_quadlets * 4; 146 return 8 + s->syt_interval * s->data_block_quadlets * 4;
147} 147}
148EXPORT_SYMBOL(amdtp_out_stream_get_max_payload); 148EXPORT_SYMBOL(amdtp_stream_get_max_payload);
149 149
150static void amdtp_write_s16(struct amdtp_out_stream *s, 150static void amdtp_write_s16(struct amdtp_stream *s,
151 struct snd_pcm_substream *pcm, 151 struct snd_pcm_substream *pcm,
152 __be32 *buffer, unsigned int frames); 152 __be32 *buffer, unsigned int frames);
153static void amdtp_write_s32(struct amdtp_out_stream *s, 153static void amdtp_write_s32(struct amdtp_stream *s,
154 struct snd_pcm_substream *pcm, 154 struct snd_pcm_substream *pcm,
155 __be32 *buffer, unsigned int frames); 155 __be32 *buffer, unsigned int frames);
156static void amdtp_write_s16_dualwire(struct amdtp_out_stream *s, 156static void amdtp_write_s16_dualwire(struct amdtp_stream *s,
157 struct snd_pcm_substream *pcm, 157 struct snd_pcm_substream *pcm,
158 __be32 *buffer, unsigned int frames); 158 __be32 *buffer, unsigned int frames);
159static void amdtp_write_s32_dualwire(struct amdtp_out_stream *s, 159static void amdtp_write_s32_dualwire(struct amdtp_stream *s,
160 struct snd_pcm_substream *pcm, 160 struct snd_pcm_substream *pcm,
161 __be32 *buffer, unsigned int frames); 161 __be32 *buffer, unsigned int frames);
162 162
163/** 163/**
164 * amdtp_out_stream_set_pcm_format - set the PCM format 164 * amdtp_stream_set_pcm_format - set the PCM format
165 * @s: the AMDTP output stream to configure 165 * @s: the AMDTP stream to configure
166 * @format: the format of the ALSA PCM device 166 * @format: the format of the ALSA PCM device
167 * 167 *
168 * The sample format must be set after the other paramters (rate/PCM channels/ 168 * The sample format must be set after the other paramters (rate/PCM channels/
169 * MIDI) and before the stream is started, and must not be changed while the 169 * MIDI) and before the stream is started, and must not be changed while the
170 * stream is running. 170 * stream is running.
171 */ 171 */
172void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s, 172void amdtp_stream_set_pcm_format(struct amdtp_stream *s,
173 snd_pcm_format_t format) 173 snd_pcm_format_t format)
174{ 174{
175 if (WARN_ON(amdtp_out_stream_running(s))) 175 if (WARN_ON(amdtp_stream_running(s)))
176 return; 176 return;
177 177
178 switch (format) { 178 switch (format) {
@@ -193,24 +193,24 @@ void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
193 break; 193 break;
194 } 194 }
195} 195}
196EXPORT_SYMBOL(amdtp_out_stream_set_pcm_format); 196EXPORT_SYMBOL(amdtp_stream_set_pcm_format);
197 197
198/** 198/**
199 * amdtp_out_stream_pcm_prepare - prepare PCM device for running 199 * amdtp_stream_pcm_prepare - prepare PCM device for running
200 * @s: the AMDTP output stream 200 * @s: the AMDTP stream
201 * 201 *
202 * This function should be called from the PCM device's .prepare callback. 202 * This function should be called from the PCM device's .prepare callback.
203 */ 203 */
204void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s) 204void amdtp_stream_pcm_prepare(struct amdtp_stream *s)
205{ 205{
206 tasklet_kill(&s->period_tasklet); 206 tasklet_kill(&s->period_tasklet);
207 s->pcm_buffer_pointer = 0; 207 s->pcm_buffer_pointer = 0;
208 s->pcm_period_pointer = 0; 208 s->pcm_period_pointer = 0;
209 s->pointer_flush = true; 209 s->pointer_flush = true;
210} 210}
211EXPORT_SYMBOL(amdtp_out_stream_pcm_prepare); 211EXPORT_SYMBOL(amdtp_stream_pcm_prepare);
212 212
213static unsigned int calculate_data_blocks(struct amdtp_out_stream *s) 213static unsigned int calculate_data_blocks(struct amdtp_stream *s)
214{ 214{
215 unsigned int phase, data_blocks; 215 unsigned int phase, data_blocks;
216 216
@@ -243,7 +243,7 @@ static unsigned int calculate_data_blocks(struct amdtp_out_stream *s)
243 return data_blocks; 243 return data_blocks;
244} 244}
245 245
246static unsigned int calculate_syt(struct amdtp_out_stream *s, 246static unsigned int calculate_syt(struct amdtp_stream *s,
247 unsigned int cycle) 247 unsigned int cycle)
248{ 248{
249 unsigned int syt_offset, phase, index, syt; 249 unsigned int syt_offset, phase, index, syt;
@@ -286,7 +286,7 @@ static unsigned int calculate_syt(struct amdtp_out_stream *s,
286 } 286 }
287} 287}
288 288
289static void amdtp_write_s32(struct amdtp_out_stream *s, 289static void amdtp_write_s32(struct amdtp_stream *s,
290 struct snd_pcm_substream *pcm, 290 struct snd_pcm_substream *pcm,
291 __be32 *buffer, unsigned int frames) 291 __be32 *buffer, unsigned int frames)
292{ 292{
@@ -312,7 +312,7 @@ static void amdtp_write_s32(struct amdtp_out_stream *s,
312 } 312 }
313} 313}
314 314
315static void amdtp_write_s16(struct amdtp_out_stream *s, 315static void amdtp_write_s16(struct amdtp_stream *s,
316 struct snd_pcm_substream *pcm, 316 struct snd_pcm_substream *pcm,
317 __be32 *buffer, unsigned int frames) 317 __be32 *buffer, unsigned int frames)
318{ 318{
@@ -338,7 +338,7 @@ static void amdtp_write_s16(struct amdtp_out_stream *s,
338 } 338 }
339} 339}
340 340
341static void amdtp_write_s32_dualwire(struct amdtp_out_stream *s, 341static void amdtp_write_s32_dualwire(struct amdtp_stream *s,
342 struct snd_pcm_substream *pcm, 342 struct snd_pcm_substream *pcm,
343 __be32 *buffer, unsigned int frames) 343 __be32 *buffer, unsigned int frames)
344{ 344{
@@ -369,7 +369,7 @@ static void amdtp_write_s32_dualwire(struct amdtp_out_stream *s,
369 } 369 }
370} 370}
371 371
372static void amdtp_write_s16_dualwire(struct amdtp_out_stream *s, 372static void amdtp_write_s16_dualwire(struct amdtp_stream *s,
373 struct snd_pcm_substream *pcm, 373 struct snd_pcm_substream *pcm,
374 __be32 *buffer, unsigned int frames) 374 __be32 *buffer, unsigned int frames)
375{ 375{
@@ -400,7 +400,7 @@ static void amdtp_write_s16_dualwire(struct amdtp_out_stream *s,
400 } 400 }
401} 401}
402 402
403static void amdtp_fill_pcm_silence(struct amdtp_out_stream *s, 403static void amdtp_fill_pcm_silence(struct amdtp_stream *s,
404 __be32 *buffer, unsigned int frames) 404 __be32 *buffer, unsigned int frames)
405{ 405{
406 unsigned int i, c; 406 unsigned int i, c;
@@ -412,7 +412,7 @@ static void amdtp_fill_pcm_silence(struct amdtp_out_stream *s,
412 } 412 }
413} 413}
414 414
415static void amdtp_fill_midi(struct amdtp_out_stream *s, 415static void amdtp_fill_midi(struct amdtp_stream *s,
416 __be32 *buffer, unsigned int frames) 416 __be32 *buffer, unsigned int frames)
417{ 417{
418 unsigned int i; 418 unsigned int i;
@@ -422,7 +422,7 @@ static void amdtp_fill_midi(struct amdtp_out_stream *s,
422 cpu_to_be32(0x80000000); 422 cpu_to_be32(0x80000000);
423} 423}
424 424
425static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle) 425static void queue_out_packet(struct amdtp_stream *s, unsigned int cycle)
426{ 426{
427 __be32 *buffer; 427 __be32 *buffer;
428 unsigned int index, data_blocks, syt, ptr; 428 unsigned int index, data_blocks, syt, ptr;
@@ -473,7 +473,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
473 if (err < 0) { 473 if (err < 0) {
474 dev_err(&s->unit->device, "queueing error: %d\n", err); 474 dev_err(&s->unit->device, "queueing error: %d\n", err);
475 s->packet_index = -1; 475 s->packet_index = -1;
476 amdtp_out_stream_pcm_abort(s); 476 amdtp_stream_pcm_abort(s);
477 return; 477 return;
478 } 478 }
479 479
@@ -501,7 +501,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
501 501
502static void pcm_period_tasklet(unsigned long data) 502static void pcm_period_tasklet(unsigned long data)
503{ 503{
504 struct amdtp_out_stream *s = (void *)data; 504 struct amdtp_stream *s = (void *)data;
505 struct snd_pcm_substream *pcm = ACCESS_ONCE(s->pcm); 505 struct snd_pcm_substream *pcm = ACCESS_ONCE(s->pcm);
506 506
507 if (pcm) 507 if (pcm)
@@ -509,9 +509,9 @@ static void pcm_period_tasklet(unsigned long data)
509} 509}
510 510
511static void out_packet_callback(struct fw_iso_context *context, u32 cycle, 511static void out_packet_callback(struct fw_iso_context *context, u32 cycle,
512 size_t header_length, void *header, void *data) 512 size_t header_length, void *header, void *private_data)
513{ 513{
514 struct amdtp_out_stream *s = data; 514 struct amdtp_stream *s = private_data;
515 unsigned int i, packets = header_length / 4; 515 unsigned int i, packets = header_length / 4;
516 516
517 /* 517 /*
@@ -526,7 +526,7 @@ static void out_packet_callback(struct fw_iso_context *context, u32 cycle,
526 fw_iso_context_queue_flush(s->context); 526 fw_iso_context_queue_flush(s->context);
527} 527}
528 528
529static int queue_initial_skip_packets(struct amdtp_out_stream *s) 529static int queue_initial_skip_packets(struct amdtp_stream *s)
530{ 530{
531 struct fw_iso_packet skip_packet = { 531 struct fw_iso_packet skip_packet = {
532 .skip = 1, 532 .skip = 1,
@@ -548,16 +548,16 @@ static int queue_initial_skip_packets(struct amdtp_out_stream *s)
548} 548}
549 549
550/** 550/**
551 * amdtp_out_stream_start - start sending packets 551 * amdtp_stream_start - start transferring packets
552 * @s: the AMDTP output stream to start 552 * @s: the AMDTP stream to start
553 * @channel: the isochronous channel on the bus 553 * @channel: the isochronous channel on the bus
554 * @speed: firewire speed code 554 * @speed: firewire speed code
555 * 555 *
556 * The stream cannot be started until it has been configured with 556 * The stream cannot be started until it has been configured with
557 * amdtp_out_stream_set_parameters() and amdtp_out_stream_set_pcm_format(), 557 * amdtp_stream_set_parameters() and it must be started before any PCM or MIDI
558 * and it must be started before any PCM or MIDI device can be started. 558 * device can be started.
559 */ 559 */
560int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed) 560int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
561{ 561{
562 static const struct { 562 static const struct {
563 unsigned int data_block; 563 unsigned int data_block;
@@ -575,7 +575,7 @@ int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
575 575
576 mutex_lock(&s->mutex); 576 mutex_lock(&s->mutex);
577 577
578 if (WARN_ON(amdtp_out_stream_running(s) || 578 if (WARN_ON(amdtp_stream_running(s) ||
579 (!s->pcm_channels && !s->midi_ports))) { 579 (!s->pcm_channels && !s->midi_ports))) {
580 err = -EBADFD; 580 err = -EBADFD;
581 goto err_unlock; 581 goto err_unlock;
@@ -586,7 +586,7 @@ int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
586 s->last_syt_offset = TICKS_PER_CYCLE; 586 s->last_syt_offset = TICKS_PER_CYCLE;
587 587
588 err = iso_packets_buffer_init(&s->buffer, s->unit, QUEUE_LENGTH, 588 err = iso_packets_buffer_init(&s->buffer, s->unit, QUEUE_LENGTH,
589 amdtp_out_stream_get_max_payload(s), 589 amdtp_stream_get_max_payload(s),
590 DMA_TO_DEVICE); 590 DMA_TO_DEVICE);
591 if (err < 0) 591 if (err < 0)
592 goto err_unlock; 592 goto err_unlock;
@@ -599,11 +599,11 @@ int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
599 err = PTR_ERR(s->context); 599 err = PTR_ERR(s->context);
600 if (err == -EBUSY) 600 if (err == -EBUSY)
601 dev_err(&s->unit->device, 601 dev_err(&s->unit->device,
602 "no free output stream on this controller\n"); 602 "no free stream on this controller\n");
603 goto err_buffer; 603 goto err_buffer;
604 } 604 }
605 605
606 amdtp_out_stream_update(s); 606 amdtp_stream_update(s);
607 607
608 s->packet_index = 0; 608 s->packet_index = 0;
609 s->data_block_counter = 0; 609 s->data_block_counter = 0;
@@ -629,15 +629,15 @@ err_unlock:
629 629
630 return err; 630 return err;
631} 631}
632EXPORT_SYMBOL(amdtp_out_stream_start); 632EXPORT_SYMBOL(amdtp_stream_start);
633 633
634/** 634/**
635 * amdtp_out_stream_pcm_pointer - get the PCM buffer position 635 * amdtp_stream_pcm_pointer - get the PCM buffer position
636 * @s: the AMDTP output stream that transports the PCM data 636 * @s: the AMDTP stream that transports the PCM data
637 * 637 *
638 * Returns the current buffer position, in frames. 638 * Returns the current buffer position, in frames.
639 */ 639 */
640unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s) 640unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s)
641{ 641{
642 /* this optimization is allowed to be racy */ 642 /* this optimization is allowed to be racy */
643 if (s->pointer_flush) 643 if (s->pointer_flush)
@@ -647,31 +647,31 @@ unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s)
647 647
648 return ACCESS_ONCE(s->pcm_buffer_pointer); 648 return ACCESS_ONCE(s->pcm_buffer_pointer);
649} 649}
650EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer); 650EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
651 651
652/** 652/**
653 * amdtp_out_stream_update - update the stream after a bus reset 653 * amdtp_stream_update - update the stream after a bus reset
654 * @s: the AMDTP output stream 654 * @s: the AMDTP stream
655 */ 655 */
656void amdtp_out_stream_update(struct amdtp_out_stream *s) 656void amdtp_stream_update(struct amdtp_stream *s)
657{ 657{
658 ACCESS_ONCE(s->source_node_id_field) = 658 ACCESS_ONCE(s->source_node_id_field) =
659 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24; 659 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
660} 660}
661EXPORT_SYMBOL(amdtp_out_stream_update); 661EXPORT_SYMBOL(amdtp_stream_update);
662 662
663/** 663/**
664 * amdtp_out_stream_stop - stop sending packets 664 * amdtp_stream_stop - stop sending packets
665 * @s: the AMDTP output stream to stop 665 * @s: the AMDTP stream to stop
666 * 666 *
667 * All PCM and MIDI devices of the stream must be stopped before the stream 667 * All PCM and MIDI devices of the stream must be stopped before the stream
668 * itself can be stopped. 668 * itself can be stopped.
669 */ 669 */
670void amdtp_out_stream_stop(struct amdtp_out_stream *s) 670void amdtp_stream_stop(struct amdtp_stream *s)
671{ 671{
672 mutex_lock(&s->mutex); 672 mutex_lock(&s->mutex);
673 673
674 if (!amdtp_out_stream_running(s)) { 674 if (!amdtp_stream_running(s)) {
675 mutex_unlock(&s->mutex); 675 mutex_unlock(&s->mutex);
676 return; 676 return;
677 } 677 }
@@ -684,16 +684,16 @@ void amdtp_out_stream_stop(struct amdtp_out_stream *s)
684 684
685 mutex_unlock(&s->mutex); 685 mutex_unlock(&s->mutex);
686} 686}
687EXPORT_SYMBOL(amdtp_out_stream_stop); 687EXPORT_SYMBOL(amdtp_stream_stop);
688 688
689/** 689/**
690 * amdtp_out_stream_pcm_abort - abort the running PCM device 690 * amdtp_stream_pcm_abort - abort the running PCM device
691 * @s: the AMDTP stream about to be stopped 691 * @s: the AMDTP stream about to be stopped
692 * 692 *
693 * If the isochronous stream needs to be stopped asynchronously, call this 693 * If the isochronous stream needs to be stopped asynchronously, call this
694 * function first to stop the PCM device. 694 * function first to stop the PCM device.
695 */ 695 */
696void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s) 696void amdtp_stream_pcm_abort(struct amdtp_stream *s)
697{ 697{
698 struct snd_pcm_substream *pcm; 698 struct snd_pcm_substream *pcm;
699 699
@@ -705,4 +705,4 @@ void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s)
705 snd_pcm_stream_unlock_irq(pcm); 705 snd_pcm_stream_unlock_irq(pcm);
706 } 706 }
707} 707}
708EXPORT_SYMBOL(amdtp_out_stream_pcm_abort); 708EXPORT_SYMBOL(amdtp_stream_pcm_abort);
diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
index 2746ecd291af..60028c7fc144 100644
--- a/sound/firewire/amdtp.h
+++ b/sound/firewire/amdtp.h
@@ -8,7 +8,7 @@
8#include "packets-buffer.h" 8#include "packets-buffer.h"
9 9
10/** 10/**
11 * enum cip_out_flags - describes details of the streaming protocol 11 * enum cip_flags - describes details of the streaming protocol
12 * @CIP_NONBLOCKING: In non-blocking mode, each packet contains 12 * @CIP_NONBLOCKING: In non-blocking mode, each packet contains
13 * sample_rate/8000 samples, with rounding up or down to adjust 13 * sample_rate/8000 samples, with rounding up or down to adjust
14 * for clock skew and left-over fractional samples. This should 14 * for clock skew and left-over fractional samples. This should
@@ -21,7 +21,7 @@
21 * two samples of a channel are stored consecutively in the packet. 21 * two samples of a channel are stored consecutively in the packet.
22 * Requires blocking mode and SYT_INTERVAL-aligned PCM buffer size. 22 * Requires blocking mode and SYT_INTERVAL-aligned PCM buffer size.
23 */ 23 */
24enum cip_out_flags { 24enum cip_flags {
25 CIP_NONBLOCKING = 0x00, 25 CIP_NONBLOCKING = 0x00,
26 CIP_BLOCKING = 0x01, 26 CIP_BLOCKING = 0x01,
27 CIP_HI_DUALWIRE = 0x02, 27 CIP_HI_DUALWIRE = 0x02,
@@ -48,9 +48,9 @@ struct fw_unit;
48struct fw_iso_context; 48struct fw_iso_context;
49struct snd_pcm_substream; 49struct snd_pcm_substream;
50 50
51struct amdtp_out_stream { 51struct amdtp_stream {
52 struct fw_unit *unit; 52 struct fw_unit *unit;
53 enum cip_out_flags flags; 53 enum cip_flags flags;
54 struct fw_iso_context *context; 54 struct fw_iso_context *context;
55 struct mutex mutex; 55 struct mutex mutex;
56 56
@@ -59,7 +59,7 @@ struct amdtp_out_stream {
59 unsigned int data_block_quadlets; 59 unsigned int data_block_quadlets;
60 unsigned int pcm_channels; 60 unsigned int pcm_channels;
61 unsigned int midi_ports; 61 unsigned int midi_ports;
62 void (*transfer_samples)(struct amdtp_out_stream *s, 62 void (*transfer_samples)(struct amdtp_stream *s,
63 struct snd_pcm_substream *pcm, 63 struct snd_pcm_substream *pcm,
64 __be32 *buffer, unsigned int frames); 64 __be32 *buffer, unsigned int frames);
65 65
@@ -84,56 +84,62 @@ struct amdtp_out_stream {
84 bool pointer_flush; 84 bool pointer_flush;
85}; 85};
86 86
87int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit, 87int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
88 enum cip_out_flags flags); 88 enum cip_flags flags);
89void amdtp_out_stream_destroy(struct amdtp_out_stream *s); 89void amdtp_stream_destroy(struct amdtp_stream *s);
90 90
91void amdtp_out_stream_set_parameters(struct amdtp_out_stream *s, 91void amdtp_stream_set_parameters(struct amdtp_stream *s,
92 unsigned int rate, 92 unsigned int rate,
93 unsigned int pcm_channels, 93 unsigned int pcm_channels,
94 unsigned int midi_ports); 94 unsigned int midi_ports);
95unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s); 95unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s);
96 96
97int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed); 97int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed);
98void amdtp_out_stream_update(struct amdtp_out_stream *s); 98void amdtp_stream_update(struct amdtp_stream *s);
99void amdtp_out_stream_stop(struct amdtp_out_stream *s); 99void amdtp_stream_stop(struct amdtp_stream *s);
100 100
101void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s, 101void amdtp_stream_set_pcm_format(struct amdtp_stream *s,
102 snd_pcm_format_t format); 102 snd_pcm_format_t format);
103void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s); 103void amdtp_stream_pcm_prepare(struct amdtp_stream *s);
104unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s); 104unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s);
105void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s); 105void amdtp_stream_pcm_abort(struct amdtp_stream *s);
106 106
107extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT]; 107extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
108 108
109static inline bool amdtp_out_stream_running(struct amdtp_out_stream *s) 109/**
110 * amdtp_stream_running - check stream is running or not
111 * @s: the AMDTP stream
112 *
113 * If this function returns true, the stream is running.
114 */
115static inline bool amdtp_stream_running(struct amdtp_stream *s)
110{ 116{
111 return !IS_ERR(s->context); 117 return !IS_ERR(s->context);
112} 118}
113 119
114/** 120/**
115 * amdtp_out_streaming_error - check for streaming error 121 * amdtp_streaming_error - check for streaming error
116 * @s: the AMDTP output stream 122 * @s: the AMDTP stream
117 * 123 *
118 * If this function returns true, the stream's packet queue has stopped due to 124 * If this function returns true, the stream's packet queue has stopped due to
119 * an asynchronous error. 125 * an asynchronous error.
120 */ 126 */
121static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s) 127static inline bool amdtp_streaming_error(struct amdtp_stream *s)
122{ 128{
123 return s->packet_index < 0; 129 return s->packet_index < 0;
124} 130}
125 131
126/** 132/**
127 * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device 133 * amdtp_stream_pcm_trigger - start/stop playback from a PCM device
128 * @s: the AMDTP output stream 134 * @s: the AMDTP stream
129 * @pcm: the PCM device to be started, or %NULL to stop the current device 135 * @pcm: the PCM device to be started, or %NULL to stop the current device
130 * 136 *
131 * Call this function on a running isochronous stream to enable the actual 137 * Call this function on a running isochronous stream to enable the actual
132 * transmission of PCM data. This function should be called from the PCM 138 * transmission of PCM data. This function should be called from the PCM
133 * device's .trigger callback. 139 * device's .trigger callback.
134 */ 140 */
135static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s, 141static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
136 struct snd_pcm_substream *pcm) 142 struct snd_pcm_substream *pcm)
137{ 143{
138 ACCESS_ONCE(s->pcm) = pcm; 144 ACCESS_ONCE(s->pcm) = pcm;
139} 145}
diff --git a/sound/firewire/dice.c b/sound/firewire/dice.c
index 0c3948630cf7..ca12fcbc65ec 100644
--- a/sound/firewire/dice.c
+++ b/sound/firewire/dice.c
@@ -51,7 +51,7 @@ struct dice {
51 wait_queue_head_t hwdep_wait; 51 wait_queue_head_t hwdep_wait;
52 u32 notification_bits; 52 u32 notification_bits;
53 struct fw_iso_resources resources; 53 struct fw_iso_resources resources;
54 struct amdtp_out_stream stream; 54 struct amdtp_stream stream;
55}; 55};
56 56
57MODULE_DESCRIPTION("DICE driver"); 57MODULE_DESCRIPTION("DICE driver");
@@ -460,17 +460,17 @@ static int dice_stream_start_packets(struct dice *dice)
460{ 460{
461 int err; 461 int err;
462 462
463 if (amdtp_out_stream_running(&dice->stream)) 463 if (amdtp_stream_running(&dice->stream))
464 return 0; 464 return 0;
465 465
466 err = amdtp_out_stream_start(&dice->stream, dice->resources.channel, 466 err = amdtp_stream_start(&dice->stream, dice->resources.channel,
467 fw_parent_device(dice->unit)->max_speed); 467 fw_parent_device(dice->unit)->max_speed);
468 if (err < 0) 468 if (err < 0)
469 return err; 469 return err;
470 470
471 err = dice_enable_set(dice); 471 err = dice_enable_set(dice);
472 if (err < 0) { 472 if (err < 0) {
473 amdtp_out_stream_stop(&dice->stream); 473 amdtp_stream_stop(&dice->stream);
474 return err; 474 return err;
475 } 475 }
476 476
@@ -484,7 +484,7 @@ static int dice_stream_start(struct dice *dice)
484 484
485 if (!dice->resources.allocated) { 485 if (!dice->resources.allocated) {
486 err = fw_iso_resources_allocate(&dice->resources, 486 err = fw_iso_resources_allocate(&dice->resources,
487 amdtp_out_stream_get_max_payload(&dice->stream), 487 amdtp_stream_get_max_payload(&dice->stream),
488 fw_parent_device(dice->unit)->max_speed); 488 fw_parent_device(dice->unit)->max_speed);
489 if (err < 0) 489 if (err < 0)
490 goto error; 490 goto error;
@@ -516,9 +516,9 @@ error:
516 516
517static void dice_stream_stop_packets(struct dice *dice) 517static void dice_stream_stop_packets(struct dice *dice)
518{ 518{
519 if (amdtp_out_stream_running(&dice->stream)) { 519 if (amdtp_stream_running(&dice->stream)) {
520 dice_enable_clear(dice); 520 dice_enable_clear(dice);
521 amdtp_out_stream_stop(&dice->stream); 521 amdtp_stream_stop(&dice->stream);
522 } 522 }
523} 523}
524 524
@@ -581,12 +581,12 @@ static int dice_hw_params(struct snd_pcm_substream *substream,
581 return err; 581 return err;
582 582
583 mode = rate_index_to_mode(rate_index); 583 mode = rate_index_to_mode(rate_index);
584 amdtp_out_stream_set_parameters(&dice->stream, 584 amdtp_stream_set_parameters(&dice->stream,
585 params_rate(hw_params), 585 params_rate(hw_params),
586 params_channels(hw_params), 586 params_channels(hw_params),
587 dice->rx_midi_ports[mode]); 587 dice->rx_midi_ports[mode]);
588 amdtp_out_stream_set_pcm_format(&dice->stream, 588 amdtp_stream_set_pcm_format(&dice->stream,
589 params_format(hw_params)); 589 params_format(hw_params));
590 590
591 return 0; 591 return 0;
592} 592}
@@ -609,7 +609,7 @@ static int dice_prepare(struct snd_pcm_substream *substream)
609 609
610 mutex_lock(&dice->mutex); 610 mutex_lock(&dice->mutex);
611 611
612 if (amdtp_out_streaming_error(&dice->stream)) 612 if (amdtp_streaming_error(&dice->stream))
613 dice_stream_stop_packets(dice); 613 dice_stream_stop_packets(dice);
614 614
615 err = dice_stream_start(dice); 615 err = dice_stream_start(dice);
@@ -620,7 +620,7 @@ static int dice_prepare(struct snd_pcm_substream *substream)
620 620
621 mutex_unlock(&dice->mutex); 621 mutex_unlock(&dice->mutex);
622 622
623 amdtp_out_stream_pcm_prepare(&dice->stream); 623 amdtp_stream_pcm_prepare(&dice->stream);
624 624
625 return 0; 625 return 0;
626} 626}
@@ -640,7 +640,7 @@ static int dice_trigger(struct snd_pcm_substream *substream, int cmd)
640 default: 640 default:
641 return -EINVAL; 641 return -EINVAL;
642 } 642 }
643 amdtp_out_stream_pcm_trigger(&dice->stream, pcm); 643 amdtp_stream_pcm_trigger(&dice->stream, pcm);
644 644
645 return 0; 645 return 0;
646} 646}
@@ -649,7 +649,7 @@ static snd_pcm_uframes_t dice_pointer(struct snd_pcm_substream *substream)
649{ 649{
650 struct dice *dice = substream->private_data; 650 struct dice *dice = substream->private_data;
651 651
652 return amdtp_out_stream_pcm_pointer(&dice->stream); 652 return amdtp_stream_pcm_pointer(&dice->stream);
653} 653}
654 654
655static int dice_create_pcm(struct dice *dice) 655static int dice_create_pcm(struct dice *dice)
@@ -1104,7 +1104,7 @@ static void dice_card_free(struct snd_card *card)
1104{ 1104{
1105 struct dice *dice = card->private_data; 1105 struct dice *dice = card->private_data;
1106 1106
1107 amdtp_out_stream_destroy(&dice->stream); 1107 amdtp_stream_destroy(&dice->stream);
1108 fw_core_remove_address_handler(&dice->notification_handler); 1108 fw_core_remove_address_handler(&dice->notification_handler);
1109 mutex_destroy(&dice->mutex); 1109 mutex_destroy(&dice->mutex);
1110} 1110}
@@ -1360,8 +1360,8 @@ static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
1360 goto err_owner; 1360 goto err_owner;
1361 dice->resources.channels_mask = 0x00000000ffffffffuLL; 1361 dice->resources.channels_mask = 0x00000000ffffffffuLL;
1362 1362
1363 err = amdtp_out_stream_init(&dice->stream, unit, 1363 err = amdtp_stream_init(&dice->stream, unit,
1364 CIP_BLOCKING | CIP_HI_DUALWIRE); 1364 CIP_BLOCKING | CIP_HI_DUALWIRE);
1365 if (err < 0) 1365 if (err < 0)
1366 goto err_resources; 1366 goto err_resources;
1367 1367
@@ -1417,7 +1417,7 @@ static void dice_remove(struct fw_unit *unit)
1417{ 1417{
1418 struct dice *dice = dev_get_drvdata(&unit->device); 1418 struct dice *dice = dev_get_drvdata(&unit->device);
1419 1419
1420 amdtp_out_stream_pcm_abort(&dice->stream); 1420 amdtp_stream_pcm_abort(&dice->stream);
1421 1421
1422 snd_card_disconnect(dice->card); 1422 snd_card_disconnect(dice->card);
1423 1423
@@ -1443,7 +1443,7 @@ static void dice_bus_reset(struct fw_unit *unit)
1443 * to stop so that the application can restart them in an orderly 1443 * to stop so that the application can restart them in an orderly
1444 * manner. 1444 * manner.
1445 */ 1445 */
1446 amdtp_out_stream_pcm_abort(&dice->stream); 1446 amdtp_stream_pcm_abort(&dice->stream);
1447 1447
1448 mutex_lock(&dice->mutex); 1448 mutex_lock(&dice->mutex);
1449 1449
diff --git a/sound/firewire/speakers.c b/sound/firewire/speakers.c
index 9f7ef219b109..2096ad7fd469 100644
--- a/sound/firewire/speakers.c
+++ b/sound/firewire/speakers.c
@@ -51,7 +51,7 @@ struct fwspk {
51 const struct device_info *device_info; 51 const struct device_info *device_info;
52 struct mutex mutex; 52 struct mutex mutex;
53 struct cmp_connection connection; 53 struct cmp_connection connection;
54 struct amdtp_out_stream stream; 54 struct amdtp_stream stream;
55 bool mute; 55 bool mute;
56 s16 volume[6]; 56 s16 volume[6];
57 s16 volume_min; 57 s16 volume_min;
@@ -187,8 +187,8 @@ static int fwspk_close(struct snd_pcm_substream *substream)
187 187
188static void fwspk_stop_stream(struct fwspk *fwspk) 188static void fwspk_stop_stream(struct fwspk *fwspk)
189{ 189{
190 if (amdtp_out_stream_running(&fwspk->stream)) { 190 if (amdtp_stream_running(&fwspk->stream)) {
191 amdtp_out_stream_stop(&fwspk->stream); 191 amdtp_stream_stop(&fwspk->stream);
192 cmp_connection_break(&fwspk->connection); 192 cmp_connection_break(&fwspk->connection);
193 } 193 }
194} 194}
@@ -244,13 +244,13 @@ static int fwspk_hw_params(struct snd_pcm_substream *substream,
244 if (err < 0) 244 if (err < 0)
245 goto error; 245 goto error;
246 246
247 amdtp_out_stream_set_parameters(&fwspk->stream, 247 amdtp_stream_set_parameters(&fwspk->stream,
248 params_rate(hw_params), 248 params_rate(hw_params),
249 params_channels(hw_params), 249 params_channels(hw_params),
250 0); 250 0);
251 251
252 amdtp_out_stream_set_pcm_format(&fwspk->stream, 252 amdtp_stream_set_pcm_format(&fwspk->stream,
253 params_format(hw_params)); 253 params_format(hw_params));
254 254
255 err = fwspk_set_rate(fwspk, fwspk->stream.sfc); 255 err = fwspk_set_rate(fwspk, fwspk->stream.sfc);
256 if (err < 0) 256 if (err < 0)
@@ -282,25 +282,25 @@ static int fwspk_prepare(struct snd_pcm_substream *substream)
282 282
283 mutex_lock(&fwspk->mutex); 283 mutex_lock(&fwspk->mutex);
284 284
285 if (amdtp_out_streaming_error(&fwspk->stream)) 285 if (amdtp_streaming_error(&fwspk->stream))
286 fwspk_stop_stream(fwspk); 286 fwspk_stop_stream(fwspk);
287 287
288 if (!amdtp_out_stream_running(&fwspk->stream)) { 288 if (!amdtp_stream_running(&fwspk->stream)) {
289 err = cmp_connection_establish(&fwspk->connection, 289 err = cmp_connection_establish(&fwspk->connection,
290 amdtp_out_stream_get_max_payload(&fwspk->stream)); 290 amdtp_stream_get_max_payload(&fwspk->stream));
291 if (err < 0) 291 if (err < 0)
292 goto err_mutex; 292 goto err_mutex;
293 293
294 err = amdtp_out_stream_start(&fwspk->stream, 294 err = amdtp_stream_start(&fwspk->stream,
295 fwspk->connection.resources.channel, 295 fwspk->connection.resources.channel,
296 fwspk->connection.speed); 296 fwspk->connection.speed);
297 if (err < 0) 297 if (err < 0)
298 goto err_connection; 298 goto err_connection;
299 } 299 }
300 300
301 mutex_unlock(&fwspk->mutex); 301 mutex_unlock(&fwspk->mutex);
302 302
303 amdtp_out_stream_pcm_prepare(&fwspk->stream); 303 amdtp_stream_pcm_prepare(&fwspk->stream);
304 304
305 return 0; 305 return 0;
306 306
@@ -327,7 +327,7 @@ static int fwspk_trigger(struct snd_pcm_substream *substream, int cmd)
327 default: 327 default:
328 return -EINVAL; 328 return -EINVAL;
329 } 329 }
330 amdtp_out_stream_pcm_trigger(&fwspk->stream, pcm); 330 amdtp_stream_pcm_trigger(&fwspk->stream, pcm);
331 return 0; 331 return 0;
332} 332}
333 333
@@ -335,7 +335,7 @@ static snd_pcm_uframes_t fwspk_pointer(struct snd_pcm_substream *substream)
335{ 335{
336 struct fwspk *fwspk = substream->private_data; 336 struct fwspk *fwspk = substream->private_data;
337 337
338 return amdtp_out_stream_pcm_pointer(&fwspk->stream); 338 return amdtp_stream_pcm_pointer(&fwspk->stream);
339} 339}
340 340
341static int fwspk_create_pcm(struct fwspk *fwspk) 341static int fwspk_create_pcm(struct fwspk *fwspk)
@@ -653,7 +653,7 @@ static void fwspk_card_free(struct snd_card *card)
653{ 653{
654 struct fwspk *fwspk = card->private_data; 654 struct fwspk *fwspk = card->private_data;
655 655
656 amdtp_out_stream_destroy(&fwspk->stream); 656 amdtp_stream_destroy(&fwspk->stream);
657 cmp_connection_destroy(&fwspk->connection); 657 cmp_connection_destroy(&fwspk->connection);
658 fw_unit_put(fwspk->unit); 658 fw_unit_put(fwspk->unit);
659 mutex_destroy(&fwspk->mutex); 659 mutex_destroy(&fwspk->mutex);
@@ -683,7 +683,7 @@ static int fwspk_probe(struct fw_unit *unit,
683 if (err < 0) 683 if (err < 0)
684 goto err_unit; 684 goto err_unit;
685 685
686 err = amdtp_out_stream_init(&fwspk->stream, unit, CIP_NONBLOCKING); 686 err = amdtp_stream_init(&fwspk->stream, unit, CIP_NONBLOCKING);
687 if (err < 0) 687 if (err < 0)
688 goto err_connection; 688 goto err_connection;
689 689
@@ -733,21 +733,21 @@ static void fwspk_bus_reset(struct fw_unit *unit)
733 fcp_bus_reset(fwspk->unit); 733 fcp_bus_reset(fwspk->unit);
734 734
735 if (cmp_connection_update(&fwspk->connection) < 0) { 735 if (cmp_connection_update(&fwspk->connection) < 0) {
736 amdtp_out_stream_pcm_abort(&fwspk->stream); 736 amdtp_stream_pcm_abort(&fwspk->stream);
737 mutex_lock(&fwspk->mutex); 737 mutex_lock(&fwspk->mutex);
738 fwspk_stop_stream(fwspk); 738 fwspk_stop_stream(fwspk);
739 mutex_unlock(&fwspk->mutex); 739 mutex_unlock(&fwspk->mutex);
740 return; 740 return;
741 } 741 }
742 742
743 amdtp_out_stream_update(&fwspk->stream); 743 amdtp_stream_update(&fwspk->stream);
744} 744}
745 745
746static void fwspk_remove(struct fw_unit *unit) 746static void fwspk_remove(struct fw_unit *unit)
747{ 747{
748 struct fwspk *fwspk = dev_get_drvdata(&unit->device); 748 struct fwspk *fwspk = dev_get_drvdata(&unit->device);
749 749
750 amdtp_out_stream_pcm_abort(&fwspk->stream); 750 amdtp_stream_pcm_abort(&fwspk->stream);
751 snd_card_disconnect(fwspk->card); 751 snd_card_disconnect(fwspk->card);
752 752
753 mutex_lock(&fwspk->mutex); 753 mutex_lock(&fwspk->mutex);