aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2016-05-09 08:12:44 -0400
committerTakashi Iwai <tiwai@suse.de>2016-05-09 09:18:24 -0400
commit73fc7f080105b16d9f189c82d0092f22107cc67b (patch)
tree051f5fefd0cb13486f64962cab6d018e5c04a764
parent38b19ed7f81ec930f3ad2066ae088f574970c814 (diff)
ALSA: firewire-lib: compute the value of second field in cycle count for IT context
In callback function of isochronous context, u32 variable is passed for cycle count. The value of this variable comes from DMA descriptors of 1394 Open Host Controller Interface (1394 OHCI). In the specification, DMA descriptors transport lower 3 bits for second field and full cycle field in 16 bits field, therefore 16 bits of the u32 variable are available. The value for second is modulo 8, and the value for cycle is modulo 8,000. Currently, ALSA firewire-lib module don't use the value of the second field, because the value is useless to calculate presentation timestamp in IEC 61883-6. However, the value may be useful for debugging. In later commit, it will be printed with the other parameters for debugging. This commit makes this module to handle the whole cycle count including second. The value is calculated by cycle unit. The existed code is already written with ignoring the value of second, thus this commit causes no issues. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/firewire/amdtp-stream.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c
index 4484242da0e6..46f1167bf69f 100644
--- a/sound/firewire/amdtp-stream.c
+++ b/sound/firewire/amdtp-stream.c
@@ -548,26 +548,44 @@ end:
548 return 0; 548 return 0;
549} 549}
550 550
551static void out_stream_callback(struct fw_iso_context *context, u32 cycle, 551/*
552 * In CYCLE_TIMER register of IEEE 1394, 7 bits are used to represent second. On
553 * the other hand, in DMA descriptors of 1394 OHCI, 3 bits are used to represent
554 * it. Thus, via Linux firewire subsystem, we can get the 3 bits for second.
555 */
556static inline u32 compute_cycle_count(u32 tstamp)
557{
558 return (((tstamp >> 13) & 0x07) * 8000) + (tstamp & 0x1fff);
559}
560
561static inline u32 increment_cycle_count(u32 cycle, unsigned int addend)
562{
563 cycle += addend;
564 if (cycle >= 8 * CYCLES_PER_SECOND)
565 cycle -= 8 * CYCLES_PER_SECOND;
566 return cycle;
567}
568
569static void out_stream_callback(struct fw_iso_context *context, u32 tstamp,
552 size_t header_length, void *header, 570 size_t header_length, void *header,
553 void *private_data) 571 void *private_data)
554{ 572{
555 struct amdtp_stream *s = private_data; 573 struct amdtp_stream *s = private_data;
556 unsigned int i, syt, packets = header_length / 4; 574 unsigned int i, syt, packets = header_length / 4;
557 unsigned int data_blocks; 575 unsigned int data_blocks;
576 u32 cycle;
558 577
559 if (s->packet_index < 0) 578 if (s->packet_index < 0)
560 return; 579 return;
561 580
562 /* 581 cycle = compute_cycle_count(tstamp);
563 * Compute the cycle of the last queued packet. 582
564 * (We need only the four lowest bits for the SYT, so we can ignore 583 /* Align to actual cycle count for the last packet. */
565 * that bits 0-11 must wrap around at 3072.) 584 cycle = increment_cycle_count(cycle, QUEUE_LENGTH - packets);
566 */
567 cycle += QUEUE_LENGTH - packets;
568 585
569 for (i = 0; i < packets; ++i) { 586 for (i = 0; i < packets; ++i) {
570 syt = calculate_syt(s, ++cycle); 587 cycle = increment_cycle_count(cycle, 1);
588 syt = calculate_syt(s, cycle);
571 data_blocks = calculate_data_blocks(s, syt); 589 data_blocks = calculate_data_blocks(s, syt);
572 590
573 if (handle_out_packet(s, data_blocks, syt) < 0) { 591 if (handle_out_packet(s, data_blocks, syt) < 0) {
@@ -580,7 +598,7 @@ static void out_stream_callback(struct fw_iso_context *context, u32 cycle,
580 fw_iso_context_queue_flush(s->context); 598 fw_iso_context_queue_flush(s->context);
581} 599}
582 600
583static void in_stream_callback(struct fw_iso_context *context, u32 cycle, 601static void in_stream_callback(struct fw_iso_context *context, u32 tstamp,
584 size_t header_length, void *header, 602 size_t header_length, void *header,
585 void *private_data) 603 void *private_data)
586{ 604{
@@ -650,7 +668,7 @@ static void in_stream_callback(struct fw_iso_context *context, u32 cycle,
650} 668}
651 669
652/* processing is done by master callback */ 670/* processing is done by master callback */
653static void slave_stream_callback(struct fw_iso_context *context, u32 cycle, 671static void slave_stream_callback(struct fw_iso_context *context, u32 tstamp,
654 size_t header_length, void *header, 672 size_t header_length, void *header,
655 void *private_data) 673 void *private_data)
656{ 674{
@@ -659,7 +677,7 @@ static void slave_stream_callback(struct fw_iso_context *context, u32 cycle,
659 677
660/* this is executed one time */ 678/* this is executed one time */
661static void amdtp_stream_first_callback(struct fw_iso_context *context, 679static void amdtp_stream_first_callback(struct fw_iso_context *context,
662 u32 cycle, size_t header_length, 680 u32 tstamp, size_t header_length,
663 void *header, void *private_data) 681 void *header, void *private_data)
664{ 682{
665 struct amdtp_stream *s = private_data; 683 struct amdtp_stream *s = private_data;
@@ -678,7 +696,7 @@ static void amdtp_stream_first_callback(struct fw_iso_context *context,
678 else 696 else
679 context->callback.sc = out_stream_callback; 697 context->callback.sc = out_stream_callback;
680 698
681 context->callback.sc(context, cycle, header_length, header, s); 699 context->callback.sc(context, tstamp, header_length, header, s);
682} 700}
683 701
684/** 702/**