firewire-lib: Add macros instead of fixed value for AMDTP

This patch adds some macros instead of fixed value for AMDTP in IEC 61883-6.
These macros will also be used by followed patches.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
firewire-lib: Add 'direction' member to 'amdtp_stream' structure

This patch adds 'direction' member to amdtp_stream structure to indicate its
direction. This patch also adds 'direction' argument to amdtp_stream_init()
function to determine its direction.

The amdtp_stream_init() function is exported and used by firewire-speakers and
dice so this patch also affects them.

This patch just add them. Actual implementation will be done by followed
patches.
firewire-lib: Split some codes into functions to reuse in future

Some codes can be reused in handling transmitted stream. This commit adds new
functions. This commit also renames some functions to keep naming consistency.
firewire-lib: Add support for AMDTP transmit stream and PCM capture

For capturing PCM, this commit adds the functionality to handle transmitted
stream. This is also applied for dual-wire mode.
firewire-lib: Add support for MIDI capture/playback

For capturing/playbacking MIDI message, this commit adds the functionality to
multiplex/demultiplex MIDI messages into AMDTP sream in IEC 61883-6. As a
result, the number of MIDI ports is limited by 16 ports, for my convinience.

And this commit allows to set PCM format even if AMDTP stream already starts.
I suppose the case that PCM data starts to be multiplexed/demultiplexed after
AMDTP stream is already started for MIDI. To distinguish whether PCM or MIDI
functionality starts AMDTP stream, this commit adds amdtp_stream_pcm_running()
and amdtp_stream_midi_running(). I think this is better than reference-counter.

IEC 61883-6 refers to AMEI/MMA RP-027 for implementation of MIDI conformant
data. This module implement 'MIDI1.0-1x-SPEED' mode. In the specification,
'MIDI1.0-2x/3x-SPEED' mode is defined with 'negotiation procedure' and
'encapsulation details'. But I cannot find specifications about them.
firewire-lib: give syt value to handle_out_packet()

For duplex streams with synchronization, this driver should pass 'presentation
timestamp' from transmit packets to out packets. This commit is preparation for
this.
firewire-lib: Add support for duplex streams with synchronization

Generally, the devices can synchronize to handle 'presentation timestamp'
in CIP packets. This commit adds the functionality to pick up this timestamp
in packets transmitted by the device, then use it for out packets.

In previous implementation, this module generated the timestamp by itself. Then
it acts as synchronization master. This commit allows this module to act as
synchronization slave.
firewire-lib: Add sort function for transmitted packet

The aim of this commit is to assure the continuity of timestamp in received
packets. Fireworks with firmware version 5.5 or former is a type of device
which transmits packets with a bit disorder. For example,

Index  Payload	CIP header 1  CIP header 2
023    210      3F1100F8      900478E9
024    002      3F1100F8      90FFFFFF
025    210      3F110000      900490E9
026    210      3F110008      9004A4E9
027    210      3F110010      9004B8E9
028    002      3F110010      90FFFFFF
029    210      3F110020      9004E4E8 <-
030    210      3F110018      9004D0E8 <-
031    210      3F110028      9004F8E8
032    002      3F110028      90FFFFFF
033    210      3F110030      900410E8
034    210      3F110038      900424E8
035    210      3F110040      900438E8
036    002      3F110040      90FFFFFF
037    210      3F110050      900464E8 <-
038    210      3F110048      900450E8 <-
039    210      3F110058      900478E8
040    002      3F110058      90FFFFFF
041    210      3F110068      9004A4E8 <-
042    210      3F110060      900490E8 <-
043    210      3F110070      9004B8E8
044    002      3F110070      90FFFFFF
045    210      3F110080      9004E4E7 <-
046    210      3F110078      9004D0E8 <-
firewire-lib: Add transfer delay to synchronized duplex streams

Currently, when duplex streams with synchronization mode, this module just pass
'presentation timestamp' from transmitted packets to out packets. This is
enough to handle actual device but logically it should include 'transfer delay'
and 'processing time'. This means the timestamp in out packet should be at
future.

To be simple, this commit add only 'transfer delay'.
firewire-lib: Add support for channel mapping

Some devices arrange the position of PCM/MIDI data. This commit allows drivers
to set channel mapping.

To be simple, the mapping table is an array with fixed length. Then the number
of channels for PCM is restricted by 64 channels.
firewire-lib: Rename macros, variables and functions for CMP

Referring to IEC 61883-1, oMPR and iMPR, oPCR and iPCR have some fields with
the same role in the same position. This patch renames some macros, variables
and function arguments with "i" in its prefix to reuse them between oMPR and
iMPR, oPCR and iPCR.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
firewire-lib: Add 'direction' member to 'cmp_connection' structure

This patch adds 'direction' member to 'cmp_connection' structure to indicate
the direction of connection. This patch also adds 'direction' argument to
cmp_connection_init() function to determine the direction.

The cmp_connection_init() function is exported and used in snd-firewire-speakers
so this patch also affect it.

This patch just add them. Actual implementation will be done by followed
patches.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
firewire-lib: Add handling output connection by CMP

This patch adds some macros, codes with condition of direction and new functions
to handle output connection. Once cmp_connection_init() is executed with its
direction, CMP input and output connection can be handled by the same way.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
firewire-lib: Add a new function to check others' connection

The register for CMP plugs has two fields related to the number of established
connections, one is 'Broadcast connection counter' and another is
'Point-to-point connection counter'. The driver can know there are established
connections or not to check these fields.

This is considering for JACK/FFADO streaming. Currently, when JACK/FFADO starts
its streaming to the device, cmp_connection_establish() is failed. This seems to
be enough but there are some devices which needs to change samplling frequency
before trying to establish connections. For these devices, the functionality to
check connections is needed.
firewire-lib: Add some AV/C general commands

This commit add three commands. I think many devices use these commands.
These commands are defined in 'AV/C Digital Interface Command Set General
Specification Version 4.2 (2004006, 1394TA)'.

1. INPUT PLUG SIGNAL FORMAT command
2. OUTPUT PLUG SIGNAL FORMAT command
3. PLUG INFO command

By the command 1 and 2, the drivers can get/set sampling frequency.
By the command 3, the drivers can get the number of each plugs.
firewire-lib: Add quirks for Fireworks chipset

This commit adds two modifications for Fireworks quirks.

1. The driver can indicate the number of first data blocks in which this module
put MIDI messages for out stream.
This commit add 'blocks_for_midi' member to 'amdtp_stream' structure for this
purpose. Fireworks can pick up MIDI messages in first 8 data blocks and ignore
in other data blocks.

2. This module calculate data block size by itself don't check counter.
One of Fireworks device, AudioFirePre8, always reports 8 data block size in
transmitted packets and the data block counter is incremented by 8. But this is
wrong. This commit force this module to calculate data block size and not to
check counter continuity.

I confirm these quirks in firmware version 4.8 to 5.8. I have no investigation
for the other versions.