Commit Graph

321 Commits

Author SHA1 Message Date
Takashi Sakamoto 660dd3d52e ALSA: firewire-digi00x: add hwdep interface
This commit adds hwdep interface so as the other sound drivers for units
on IEEE 1394 bus have.

This interface is designed for mixer/control applications. By using this
interface, an application can get information about firewire node, can
lock/unlock kernel streaming and can get notification at starting/stopping
kernel streaming.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-30 15:36:56 +02:00
Takashi Sakamoto 0120d0f1fe ALSA: firewire-digi00x: add PCM functionality
This commit adds PCM functionality to transmit/receive PCM samples.

Any PCM substreams are jointed because incoming/outgoing AMDTP streams
are bound. When one of PCM substream is running or external clock source
is selected, current sampling rate is used. Else, the sampling rate is
changed as an userspace application requests.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-30 15:36:40 +02:00
Takashi Sakamoto 927f17dc3a ALSA: firewire-digi00x: add proc node to show clock status
This commit adds proc node to show current clock status for debugging.

As long as testing Digi 002 rack, registers can show local clock rate,
local clock source. When external clock input such as S/PDIF is
connected, the registers show the detection and external clock rate.

Additionally, the registers show the mode of optical digital input
interface. Although, a tester with Digi 003 rack reports this makes no
sense. Further investigation is required for Digi 003 series.

Besides, in Digi 002 rack, the S/PDIF format must be IEC 60958-4,
so-called professional.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-30 15:35:31 +02:00
Takashi Sakamoto 3a2a17974e ALSA: firewire-digi00x: add stream functionality
This commit adds a functionality to manage streaming.

The streaming is not controlled by CMP in IEC 61883-6. It's controlled by
IEEE 1394 write transaction to certain addresses.

Several clock sources are available, while there're no differences about
packet transmission. The value of SYT field in transmitted packets is
always zero. Thus, streams in both direction don't build synchronization.

And the device always requires received packets to transmit packets. This
driver keeps to transfer outgoing stream even if they're not required.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-30 15:34:55 +02:00
Takashi Sakamoto 163ae6f3f3 ALSA: firewire-digi00x: add data block processing layer
Digi 002/003 family uses its own format for data blocks. The format is
quite similar to AM824 in IEC 61883-6, while there're some differences:

 * The Valid Bit Length (VBL) code is always 0x40 in Multi-bit Linear Audio
   (MBLA) data channel.
 * The first data channel includes MIDI messages, against IEC 61883-6
   recommendation.
 * The Counter field is always zero in MIDI conformant data channel.
 * Sequence multiplexing in IEC 61883-6 is not applied to the MIDI
   conformant data channel.
 * PCM samples are scrambled in received AMDTP packets. We call the way
   as Double-Oh-Three (DOT). The algorithm was discovered by
   Robin Gareus and Damien Zammit in 2012.

This commit adds data processing layer to satisfy these differences.

There's a quirk about transmission mode for received packets. When this
driver applies non-blocking mode to outgoing packets with isochronous
channel 2 or more, after 15 to 20 seconds since playbacking, any PCM
samples causes noisy sound on the device. With isochronous channel 0 or 1,
this doesn't occur. As long as I investigated, this quirk is not observed
when applying blocking mode to the received packets.

This driver applies blocking mode to outgoing packets, while non-blocking
mode to incoming packgets.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-30 15:34:25 +02:00
Takashi Sakamoto 9edf723fd8 ALSA: firewire-digi00x: add skeleton for Digi 002/003 family
This commit adds a new driver for Digidesign 002/003 family. This commit
just creates/removes card instance according to bus event. More functions
will be added in following commits.

Digidesign 002/003 family consists of:
 * Agere FW802B for IEEE 1394 PHY layer
 * PDI 1394L40 for IEEE 1394 LINK layer and IEC 61883 interface
 * ALTERA ACEX EP1K50 for IEC 61883 layer and DSP controller
 * ADSP-21065L for signal processing

[minor cleanup using skip_spaces() by tiwai]

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-30 15:33:50 +02:00
kbuild test robot 02e6ef9fba ALSA: firewire-lib: process_rx_data_blocks() can be static
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 16:52:52 +02:00
Takashi Iwai d8dfacf8b5 Merge branch 'topic/firewire-update' into for-next 2015-09-29 12:52:07 +02:00
Takashi Sakamoto df075feefb ALSA: firewire-lib: complete AM824 data block processing layer
This commit moves the codes related to data block processing from packet
streaming layer to AM824 layer.

Each driver initializes amdtp stream structure for AM824 data block by
calling amdtp_am824_init(). Then, a memory block is allocated for AM824
specific structure. This memory block is released by calling
amdtp_stream_destroy().

When setting streaming parameters, it calls amdtp_am824_set_parameters().
When starting packet streaming, it calls amdtp_stream_start(). When
stopping packet streaming, it calls amdtp_stream_stop().

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:51:20 +02:00
Takashi Sakamoto 49c7b3fcd9 ALSA: firewire-lib: rename macros with AM824 prefix
This commit renames some macros just related to AM824 format. In later
commit, they're moved to AM824 layer.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:50:23 +02:00
Takashi Sakamoto 85130cb43e ALSA: firewire-lib: rename PCM format helper function
Setting the format of PCM substream to AMDTP stream structure is important
to set a handler to copy actual PCM samples between buffers. The
processing should be in data block processing layer because essentially
it has no relationship to packet streaming.

This commit renames PCM format setting function to prepare for integrating
AM824 layer.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:49:04 +02:00
Takashi Sakamoto 03e2a67eed ALSA: firewire-lib: move MIDI trigger helper function to AM824 layer
In IEC 61883-6, MIDI messages are transferred in MIDI conformant data
channel. Essentially, packet streaming layer is not responsible for MIDI
functionality.

This commit moves MIDI trigger helper function from the layer to AM824
layer. The rest of codes related to MIDI functionality will be moved in
later commits.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:48:49 +02:00
Takashi Sakamoto f65be911c0 ALSA: firewire-lib: add helper functions to set positions of data channels
In IEC 61883-6, several types of data are available in AM824 format. The
data is transferred in each data channel. The position of data channel in
data block differs depending on model.

Current implementation has an array to map the index of data channel in an
data block to the position of actual data channel. The implementation
allows each driver to access the mapping directly.

In later commit, the mapping is in specific structure pushed into an
opaque pointer. Helper functions are required.

This commit adds the helper functions for this purpose. In IEC 61883-6,
AM824 format supports many data types, while this specification easily
causes over-engineering. Current AM824 implementation is allowed to handle
two types of data, Multi Bit Linear Audio data (=PCM samples) and MIDI
conformant data (=MIDI messages).

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:48:36 +02:00
Takashi Sakamoto bc8500da3e ALSA: firewire-lib: move PCM substream constraint to AM824 layer
In IEC 61883-6, PCM frames are transferred in Multi Bit Linear Audio data
channel. The data channel transfers 16/20/24 bit PCM samples. Thus, PCM
substream has a constrain about it.

This commit moves codes related to the constraint from packet streaming
layer to AM824 data block processing layer.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:48:19 +02:00
Takashi Sakamoto 51c29fd213 ALSA: firewire-lib: rename parameter setting function for AM824 with FDF field
The value of FDF field in CIP header is protocol-dependent. Thus, it's
better to allow data block processing layer to decide the value in any
timing.

In AM824 data format, the value of FDF field in CIP header indicates
N-flag and Nominal Sampling Frequency Code (sfc). The N-flag is for
switching 'Clock-based rate control mode' and 'Command-based rate control
mode'. In our implementation, 'Clock-based rate control mode' is just
supported. Therefore, When sampling transfer frequency is decided, then
the FDF can be set.

This commit replaces 'amdtp_stream_set_parameters' with
'amdtp_am824_set_parameters' to set the FDF. This is the same timing
to decide the ration between the number of data blocks and the number of
PCM frames.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:48:02 +02:00
Takashi Sakamoto 5955815e71 ALSA: firewire-lib: add data block processing layer for AM824 format
This commit adds data block processing layer for AM824 format. The new
layer initializes streaming layer with its value for fmt field.

Currently, most implementation of data block processing still remains
streaming layer. In later commits, these codes will be moved to the layer.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:47:45 +02:00
Takashi Sakamoto d67c46b953 ALSA: firewire-lib: rename 'amdtp' to 'amdtp-stream' to prepare for functional separation
In later commit, data block processing layer will be newly added. This
layer will be named as 'amdtp-am824'.

This commit renames current amdtp file to amdtp-stream, to distinguish it
from the new layer.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:47:11 +02:00
Takashi Sakamoto 414ba022a5 ALSA: firewire-lib: add support arbitrary value for fmt/fdf fields in CIP header
Some vendor specific protocol uses its own value for fmt/fdf fields in
CIP header.

This commit support to set arbitrary values for the fields.

In IEC 61883-6, NO-DATA code is defined for FDF field. A packet with this
code includes no data even if it includes some data blocks. This commit
still leaves a condition to handle this special packet.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:35:48 +02:00
Takashi Sakamoto 20e445771e ALSA: firewire-lib: add helper functions as interfaces between packet streaming layer and data block processing layer
ALSA PCM framework uses PCM buffer with a concept of 'period' to
synchronize userspace operations to hardware for nearly-realtime
processing. Each driver implements snd_pcm_period_elapsed() to tell across
of the period boundary to ALSA PCM middleware. To call the function, some
drivers utilize hardware interrupt handlers, the others count handled PCM
frames.

Drivers for sound units on IEEE 1394 bus are the latter. They use two
buffers; PCM buffer and DMA buffer for IEEE 1394 isochronous packet. PCM
frames are copied between these two buffers and 'amdtp_stream' structure
counts the handled PCM frames. Then, snd_pcm_period_elapsed() is called if
required.

Essentially, packet streaming layer should not be responsible for PCM
frame processing. The PCM frame processing should be handled in each data
block processing layer as a result of handling data blocks. Although, PCM
frame counting is a common work for all of protocols which ALSA firewire
stack is going to support.

This commit adds two new helper functions as interfaces between packet
streaming layer to data block processing layer. In future, each data block
processing layer implements these functions. The packet streaming layer
calls data block processing layer per packet by calling the functions. The
data block processing layer processes data blocks and PCM frames, and
returns the number of processed PCM frames. Then the packet streaming layer
calculates handled PCM frames and calls snd_pcm_period_elapsed().

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:35:47 +02:00
Takashi Sakamoto 6a4e89ff0f ALSA: firewire-lib: add a member of frame_multiplier instead of double_pcm_frames
In future commit, interface between data block processing layer and packet
stream processing layer is defined. These two layers communicate the
number of data blocks and the number of PCM frames.

The data block processing layer has a responsibility for calculating the
number of PCM frames. Therefore, 'dual wire' of Dice quirk should be
handled in data block processing layer.

This commit adds a member of 'frame_multiplier'. This member represents
the ratio of the number of PCM frames against the number of data blocks.
Usually, the value of this member is 1, while it's 2 in Dice's 'dual wire'.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:35:46 +02:00
Takashi Sakamoto 27ec83b5c6 ALSA: firewire-lib: add an argument for Dice's dual wire mode
In IEC 61883-6, one data block represents one event. In ALSA, the event is
one PCM frame. Therefore, when processing one data block, current
implementation counts one PCM frame.

On the other hand, Dice platform has a quirk called as 'dual wire' at
higher sampling rate. In detail, see comment of commit 6eb6c81eee
("ALSA: dice: Split stream functionality into a file").

Currently, to handle this quirk, AMDTP stream structure has a
'double_pcm_frames' member. When this is enabled, two PCM frames are
counted. Each driver set this flag by accessing the structure member
directly.

In future commit, some members related to AM824 data block will be moved
to specific structure, to separate packet streaming layer and data block
processing layer. The access will be limited by opaque pointer.

For this reason, this commit adds an argument into
amdtp_stream_set_parameter() to set the flag.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:35:46 +02:00
Takashi Sakamoto 547e631ce3 ALSA: firewire-lib: return error code when amdtp_stream_set_parameters() detects error
Currently, amdtp_stream_set_parameters() returns no error even if wrong
arguments are given. This is not good for streaming layer because drivers
can continue processing ignoring capability of streaming layer.

This commit changes this function to return error code.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:35:45 +02:00
Takashi Sakamoto 10b2b6dc1a ALSA: firewire-lib: arrange structure for AMDTP stream
In later commit, some members related to AM824 data format will be moved
from AMDTP stream structure to data block structure. This commit is a
preparation for it. Additionally, current layout of AMDTP stream structure
is a bit mess by several extensions. This commit also arranges the layout.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-29 12:35:44 +02:00
Takashi Sakamoto 13f3a46d2a ALSA: oxfw: add Mackie Onyx Satellite quirk to inform wrong value in 'dbs' field in tx CIP header
Mackie Onyx Satellite has two usage; standalone and with base station.

These two modes has different stream formats. In standalone mode, rx data
block includes 2 Multi Bit Linear Audio (MBLA) data channels and tx data
block includes 2. With base station, they're 6 and 2.

Although, with base station, the actual tx packet include wrong value in
'dbs' field in its CIP header. This quirk causes packet streaming layer to
detect packet discontinuity and to stop PCM substream.

This is a response of 'single' subfunction 'extended stream format
information' command in AV/C Stream Format Information Specification 1.1.
It means that a data block in tx packets includes 2 MBLA data channels.

$ ./firewire-request /dev/fw1 fcp 0x01ffbfc001000000ffffffff
response: 000: 0c ff bf c0 01 00 00 00 ff 00 90 40 03 02 01 02
response: 010: 06

Current OXFW driver parses the response and detects stream formats
correctly.

$ cat /proc/asound/card1/firewire/formation
...
Output Stream from device:
	Rate	PCM	MIDI
* 	48000	2	0
 	44100	2	0
 	88200	2	0
	96000	2	0

On the other hand, in actual tx CIP, the 'dbs' field has 6. But the number
of quadlets in CIP payload is not multiple of 6. Seeing the subtraction of
two successive payload quadlets, it should be multiple of 2.

payload  CIP      CIP
quadlets header0  header1
      24 00060052 9002ffff
      24 0006005e 9002ffff
      26 0006006a 9002ffff
      24 00060077 9002ffff
      24 00060083 9002ffff
      26 0006008f 9002ffff
      24 0006009c 9002ffff
      24 000600a8 9002ffff
      26 000600b4 9002ffff
      24 000600c1 9002ffff

This commit adds support for this quirk to OXFW driver, by using
CIP_WRONG_DBS flag. When this flag is set, packet streaming layer uses
the value of its 'data_block_quadlets' member instead of the value in CIP
header. This value is already set by OXFW driver and no discontinuity is
detected.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-24 11:44:25 +02:00
Takashi Sakamoto 22c103cd3d ALSA: fireworks/bebob/dice/oxfw: fix substreams counting at vmalloc failure
In PCM core, when hw_params() in each driver returns error, the state of
PCM substream is kept as 'open'. In this case, current drivers for sound
units on IEEE 1394 bus doesn't decrement substream counter in hw_free()
correctly. This causes these drivers to keep streams even if not
required.

This commit fixes this bug. When snd_pcm_lib_alloc_vmalloc_buffer()
fails, hw_params function in each driver returns without incrementing the
counter.

Reported-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-08-29 09:14:41 +02:00
Takashi Iwai 41450b1b5b Merge branch 'for-linus' into for-next 2015-08-11 09:40:16 +02:00
Andrzej Hajda 96bab82f6b ALSA: firewire: use kmemdup rather than duplicating its implementation
The patch was generated using fixed coccinelle semantic patch
scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-08-07 14:52:07 +02:00
Takashi Sakamoto 18f5ed365d ALSA: fireworks/firewire-lib: add support for recent firmware quirk
Fireworks uses TSB43CB43(IceLynx-Micro) as its IEC 61883-1/6 interface.
This chip includes ARM7 core, and loads and runs program. The firmware
is stored in on-board memory and loaded every powering-on from it.

Echo Audio ships several versions of firmwares for each model. These
firmwares have each quirk and the quirk changes a sequence of packets.

As long as I investigated, AudioFire2/AudioFire4/AudioFirePre8 have a
quirk to transfer a first packet with 0x02 in its dbc field. This causes
ALSA Fireworks driver to detect discontinuity. In this case, firmware
version 5.7.0, 5.7.3 and 5.8.0 are used.

Payload  CIP      CIP
quadlets header1  header2
02       00050002 90ffffff <-
42       0005000a 90013000
42       00050012 90014400
42       0005001a 90015800
02       0005001a 90ffffff
42       00050022 90019000
42       0005002a 9001a400
42       00050032 9001b800
02       00050032 90ffffff
42       0005003a 9001d000
42       00050042 9001e400
42       0005004a 9001f800
02       0005004a 90ffffff
(AudioFire2 with firmware version 5.7.)

$ dmesg
snd-fireworks fw1.0: Detect discontinuity of CIP: 00 02

These models, AudioFire8 (since Jul 2009 ) and Gibson Robot Interface
Pack series uses the same ARM binary as their firmware. Thus, this
quirk may be observed among them.

This commit adds a new member for AMDTP structure. This member represents
the value of dbc field in a first AMDTP packet. Drivers can set it with
a preferred value according to model's quirk.

Tested-by: Johannes Oertei <johannes.oertel@uni-due.de>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-08-05 07:52:39 +02:00
Takashi Sakamoto c85523d1d9 Revert "ALSA: fireworks: add support for AudioFire2 quirk"
This reverts commit 9c6893e0be.

The fix is superseded by the next commit as a better implementation
for supporting AudioFire2/AudioFire4/AudioFirePre8 quirks.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-08-05 07:51:53 +02:00
Takashi Sakamoto 9c6893e0be ALSA: fireworks: add support for AudioFire2 quirk
Fireworks uses TSB43CB43(IceLynx-Micro) as its IEC 61883-1/6 interface.
This chip includes ARM7 core, and loads and runs program. The firmware
is stored in on-board memory and loaded every powering-on.

Echo Audio ships several versions of firmwares for each model. These
firmwares have each quirk and the quirk changes a sequence of packets.

AudioFire2 has a quirk to transfer a first packet with non-zero in
its dbc field. This causes ALSA Fireworks driver to detect discontinuity.
As long as I investigated, firmware 5.7, 5.7.6 and 5.8 have this quirk.

This commit adds a support for the quirk to handle AudioFire2 packets.
For safe, CIP_SKIP_INIT_DBC_CHECK is applied to all versions of
AudioFire2's firmwares.

02 00050002 90ffffff <-
42 0005000a 90013000
42 00050012 90014400
42 0005001a 90015800
02 0005001a 90ffffff
42 00050022 90019000
42 0005002a 9001a400
42 00050032 9001b800
02 00050032 90ffffff
42 0005003a 9001d000
42 00050042 9001e400
42 0005004a 9001f800
02 0005004a 90ffffff

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-07-27 10:12:25 +02:00
Takashi Sakamoto cf8a471909 ALSA: bebob: add support for Behringer FCA 610/1616
They're based on DM1500 (ArchWave produced), and BeBoB version 3 is
installed.

$ cat /proc/asound/FCA610/firewire/firmware
Manufacturer:	bridgeCo
Protocol Ver:	3
Build Ver:		0
GUID:		0x001564000002AD73
Model ID:		0x03
Model Rev:		0
Firmware Date:	20121102
Firmware Time:	153431
Firmware ID:	0x610
Firmware Ver:	8348
Base Addr:		0x400C0080
Max Size:		1422624
Loader Date:	20121015
Loader Time:	104710

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-15 13:38:47 +02:00
Takashi Sakamoto 8d1c2694e4 ALSA: bebob: keep duplex streams always to keep internal multiplexer properly
Behringer FCA610 transmits packets with periodic noisy PCM samples
when receiving no streams, and generates a bit noisy sound.

ALSA BeBoB driver is programmed to establish both in/out connections
when starting streaming, then transfers packets as userspace applications
requested. This means that there's a case that one of incoming/outgoing
streams is running, to save CPU and bandwidth usage. Although, it's natural
to start transferring packets in both direction.

This commit makes this driver to keeps duplex streams always.

Tested-by: Kim Tore Jensen <kim@incendio.no>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-15 13:38:29 +02:00
Takashi Sakamoto c4d860a0d2 ALSA: bebob: loosen up severity of checking continuity for BeBoB v3 quirk
PrismSound Orpheus, Behringer UFX1604 and FCA610 work with BeBoB v3, and
they're confirmed to transmit discontinuous packets in the beginning of
streaming.

payload    CIP headers
  8        0x00070000 0x9002FFFF
  8        0x00070000 0x9002FFFF
  8        0x00070000 0x9002FFFF
  8        0x00070008 0x9002FFFF <-
  8        0x00070008 0x9002FFFF
  8        0x00070008 0x9002FFFF
  8        0x00070008 0x9002FFFF
  8        0x00070008 0x9002FFFF
  8        0x00070008 0x9002FFFF
232        0x00070000 0x9002E798 <-
232        0x00070008 0x9002FB99
232        0x00070010 0x90021398
  8        0x00070018 0x9002FFFF
(This sample was got with Behringer FCA610 and FFADO library.)

This commit sets CIP_EMPTY_HAS_WRONG_DBC and CIP_SKIP_DBC_ZERO_CHECK to
ignore these discontinuities.

Tested-by: Kim Tore Jensen <kim@incendio.no>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-15 13:38:14 +02:00
Takashi Sakamoto 9a73195e61 ALSA: bebob: expand timeout for DM1500 quirk
Behringer FCA610 and UFX1604 is confirmed to require more time till
transmitting packets after establishing connections. This seems to
be a quirk of DM1500 ASIC which ArchWave produced.

For this quirk, this commit extends the time to wait up to 2 seconds.
As a result, in worst cases, below userspace functions require 2 seconds
to return.
 - snd_pcm_prepare()
 - snd_pcm_hw_params()
 - snd_pcm_recover()

Tested-by: Kim Tore Jensen <kim@incendio.no>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-15 13:38:00 +02:00
Takashi Sakamoto 7b4d7dcfa8 ALSA: bebob: add 'version' member for BeBoB protocol version
BeBoB installed devices have BeBoB register area. This area stores
basic information about its firmware. A register has its protocol
version.

This commit adds 'version' member and store the device's protocol
version to handle v3 quirks in following commits.

Tested-by: Kim Tore Jensen <kim@incendio.no>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-15 13:37:26 +02:00
Takashi Sakamoto 0577379271 ALSA: bebob: add SYT-Match support
In previous commits, this driver can detect the source of clock as mush
as possible. SYT-Match mode is also available.

This commit purge the restriction.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-15 13:37:07 +02:00
Takashi Sakamoto 554d8983a0 ALSA: bebob: obsolete string literal expression for clock source
The old string literals were completely replaced by new normalized
representation.

This commit obsoletes it.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-15 13:36:44 +02:00
Takashi Sakamoto 3e254b16b6 ALSA: bebob: use normalized representation for the type of clock source
This commit changes function prototype and its processing. As a result,
function caller can execute additional processing according to detected
clock source.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-15 13:36:00 +02:00
Takashi Sakamoto ba5177131d ALSA: bebob: preparation for replacing string literals by normalized representation for model-dependent structures
Previous commit adds a enumerator as a normalized representation of
clock source, while model-dependent structures still use string literals
for this purpose.

This commit is a preparation for replacement.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-15 13:34:47 +02:00
Takashi Sakamoto 13a4f42016 ALSA: bebob: apply new enumerator to normalize the type of clock source
Previous commit allows this driver to detect several types of clock
source, while there's no normalized expression for it.

This commit adds a new enumerator for this purpose.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-15 13:34:29 +02:00
Takashi Sakamoto 5a66881270 ALSA: bebob: improve signal mode detection for clock source
With BeBoB version 3, current ALSA BeBoB driver detects the type of
current clock signal source wrongly. This is due to a lack of proper
implementation to parse the information.

This commit renews the parser. As a result, this driver detects
SYT-Match clock signal, thus it can start streams with two modes;
SYT-Match mode and the others. SYT-Match mode will be supported in future
commits.

There's a constrain about detected internal/external clock source.
When detecting external clock source, this driver allows userspace
applications to use current sampling rate only. This is due to consider
abour synchronization to external clock sources such as S/PDIF, ADAT or
word-clock.

According to several information from some devices, I guesss that the
internal clock of most devices synchronize to IEEE 1394 cycle start
packet. In this case, by a usual way, it's detect as 'Sync type
of output Music Sub-Unit' connected to 'Sync type of PCR output Unit
(oPCR)', and this driver judges it as internal clock. Therefore,
userspace applications is allowed to request arbitrary supported sampling
rates.

On the other hand, several devices based on BeBoB version 3 have
additional internal clock. In this case, by a usual way, it's detect as
'Sync/Additional type of External input Unit'. Unfortunately, there's no
way to distinguish this sync type from the other external clock sources
such as word-clock. In this case, this driver handles it as external and
userspace applications is forced to use current sampling rate.

I note that when the source of clock is detected as 'Isochronous stream
type of input PCR[0]', it's under 'SYT-Match' mode. In this mode, the
synchronization clock is generated according to SYT-series in received
packets. In this case, this driver generates the series by myself. I
experienced this mode often make the device silent suddenly during
playbacking. This means that the mode is easy to lost synchronization.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-15 13:34:13 +02:00
Takashi Sakamoto 31ea49baa1 ALSA: firewire-lib: fix buffer-over-run when detecting packet discontinuity
When detecting packet discontinuity, handle_in_packet() returns minus value
and this value is assigned to unsigned int variable, then the variable has
huge value. As a result, the variable causes buffer-over-run in
handle_out_packet(). This brings invalid page request and system hangup.

This commit fixes the bug to add a new argument into handle_in_packet()
and the number of handled data blocks is assignd to it. The function
return value is just used to check error.

I also considered to change the type of local variable to 'int' in
in_stream_callback(). This idea is based on type-conversion in C standard,
while it may cause future problems when adding more works. Thus, I dropped
this idea.

Fixes: 6fc6b9ce41c6('ALSA: firewire-lib: pass the number of data blocks in incoming packets to outgoing packets')
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-05-27 17:44:42 +02:00
Takashi Sakamoto 146a5e3c1e ALSA: bebob: add Digidesign Mbox 2 Pro support
This device is based on DM1000E, and BeBoB version 1 firmware is
installed.

$ cat /proc/asound/cards
 0 [Pro            ]: BeBoB - Mbox 2 Pro
                      DIGIDESIGN Mbox 2 Pro (id:1, rev:1),
		      GUID 00a07e0100a90000 at fw1.0, S400

$ cat /proc/asound/Pro/firewire/firmware
Manufacturer:	bridgeCo
Protocol Ver:	1
Build Ver:		0
GUID:		0x00A07E0100A90000
Model ID:		0x01
Model Rev:		1
Firmware Date:	20071031
Firmware Time:	034402
Firmware ID:	0xA9
Firmware Ver:	16777215
Base Addr:		0x20080000
Max Size:		1572864
Loader Date:	20051207
Loader Time:	205554

With this patch, ALSA BeBoB driver can start packet streaming to/from
this model, while as a default, internal multiplexer of this model is
not initialized and generates no sound even if the driver transfers
any packets with PCM samples. To hear any sounds from this model,
userspace applications should be developed to set parameters to the
internal multiplexer. You can see raw information in FFADO website:
http://subversion.ffado.org/wiki/AvcModels/DigiDesignMboxPro2

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-05-24 17:31:11 +02:00
Takashi Sakamoto a900705491 ALSA: firewire-lib: use protocol error when detecting wrong value in CIP header
When detecting zero in 'dbs' field of CIP header, this packet streaming
should be aborted because of avoiding division-by-zero. This is an error
in an aspect of IEC 61883-1, thus protocol error.

This commit use EPROTO instead of EIO. Actually, the returned value is
not used for userspace and this commit has no effect.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-05-24 08:23:58 +02:00
Takashi Sakamoto 12e0f438d3 ALSA: firewire-lib: use dev_err() when detecting incoming streaming error
When detecting invalid value in 'dbs' field of CIP header or packet
discontinuity, current implementation reports the status by err_info().
In most cases this state is caused by model-specific issue due to
vendor's customization and should be reported to developers.

This commit use dev_err() instead of dev_info() for this purpose.
In the cases, packet streaming is aborted, thus no message floading
occurs.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-05-24 08:23:43 +02:00
Takashi Sakamoto 9a2820c118 ALSA: firewire-lib: macro arrangement for code cleanup
Some macros include my misunderstanding for IEC 61883-1 or -6.
Additionally, some fixed values appear on codes.

This commit replaces these with macros with proper names.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-05-24 08:23:36 +02:00
Takashi Sakamoto 29bcae2081 ALSA: firewire-lib: rename local functions for code cleanup
The naming rule for local functions was inconsistent. This commit
rename them with a consistent manner.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-05-24 08:23:14 +02:00
Takashi Sakamoto 727d3a0b1f ALSA: firewire-lib: remove restriction for non-blocking mode
Former patches allow non-blocking streams to synchronize with timestamp.
This patch removes the restriction.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-05-23 09:13:21 +02:00
Takashi Sakamoto a4103bd7fd ALSA: firewire-lib: set streaming error outside of packetization
In previous commit, error handling for incoming packet processing is
outside of packetization. This is nice for reading the codes.

This commit applies this idea for outgoing packet processing, too.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-05-23 09:13:20 +02:00
Takashi Sakamoto 6fc6b9ce41 ALSA: firewire-lib: pass the number of data blocks in incoming packets to outgoing packets
Current implementation reuses the value of syt field in incoming packet to
outgoing packet for full duplex timestamp synchronization, while the number
of data blocks in outgoing packets refers to hard-coded table and the
synchronization cannot be applied to non-blocking stream.

This commit passes the number of data blocks from incoming packet
processing to outgoing packet processing for the synchronization. For
normal mode, isochronous callback handler is changed to generate the values
of syt and data blocks.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-05-23 09:13:19 +02:00
Takashi Sakamoto 875be09160 ALSA: firewire-lib: simplify function to calculate the number of data blocks
This function is called according to conditions between the value of
syt and streaming mode(blocking or non-blocking).

To simplify caller's work, this commit push these conditions to the
function.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-05-23 09:13:19 +02:00
Takashi Sakamoto a2064710ba ALSA: firewire-lib: add buffer-over-run protection at receiving more data blocks than expected
In IEC 61883-6, the number of data blocks in a packet is limited up to
the value of SYT_INTERVAL. Current implementation is compliant to the
limitation, while it can cause buffer-over-run when the value of dbs
field in received packet is illegally large.

This commit adds a validator to detect such illegal packets to prevent
the buffer-over-run. Actually, the buffer is aligned to the size of memory
 page, thus this issue hardly causes system errors due to the room to page
alignment, as long as a few packets includes such jumbo payload; i.e.
a packet to several received packets.

Here, Behringer F-Control Audio 202 (based on OXFW 960) has a quirk to
postpone transferring isochronous packet till finish handling any
asynchronous packets. In this case, this model is lazy, transfers no
packets according to several cycle-start packets. After finishing, this
model pushes required data in next isochronous packet. As a result, the
packet include more data blocks than IEC 61883-6 defines.

To continue to support this model, this commit adds a new flag to extend
the length of calculated payload. This flag allows the size of payload
5 times as large as IEC 61883-6 defines. As a result, packets from this
model passed the validator successfully.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-05-23 09:13:18 +02:00
Takashi Iwai 9a4f35865f Merge branch 'for-next' into for-linus 2015-04-13 10:23:18 +02:00
Takashi Sakamoto a053fc318b ALSA: bebob: fix to processing in big-endian machine for sending cue
Some M-Audio devices require to receive bootup command just after
powering on, while codes in BeBoB driver doesn't work properly in
big-endian machine because the command should be aligned by
little-endian.

This commit fixes this bug. This fix should go to stable kernel.

Cc: Takayuki Shiroma <t.shiroma.oki@gmail.com>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-04-08 18:23:10 +02:00
Takashi Iwai e6826ef145 Merge branch 'for-linus' into for-next 2015-03-12 07:38:46 +01:00
Takashi Sakamoto 59294a01d7 ALSA: firewire-lib: leave unit reference counting completely
With previous commit, this module managed to leave the counting to each
drivers, but the isochronous resources functionality still increment/decrement
the count.

This commit purge such codes to leave the responsibility to each drivers.

Fix: c6f224dc20 ('ALSA: firewire-lib: remove reference counting')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-03-10 15:27:19 +01:00
Takashi Sakamoto 5b1274efe2 Revert "ALSA: dice: fix wrong offsets for Dice interface"
This reverts commit 8cdebf7109.

The reverted commit breaks out-stream functionality of Dice driver.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-03-10 15:26:25 +01:00
Yannick Guerrini ce99198131 ALSA: firewire: Fix trivial typos in comments
Change 'propper' to 'proper'
Change 'paramters' to 'parameters'
Change 'SYT_INTEVAL' to 'SYT_INTERVAL'
Change 'aligh'/'alighed' to 'align'/'aligned'

Signed-off-by: Yannick Guerrini <yguerrini@tomshardware.fr>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-03-10 12:40:30 +01:00
Takashi Sakamoto 8cdebf7109 ALSA: dice: fix wrong offsets for Dice interface
For received packet stream, the offset of 'RX_SEQ_START' locates after
the offset of 'RX_NUMBER_MIDI', although current macro and proc output
includes wrong offsets.

Fortunately, this bug doesn't affect streaming functionality because
these macro is not used.

This commit fixes these wrong macro and outputs.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-03-01 10:49:06 +01:00
Takashi Sakamoto f2b14c0bc5 ALSA: oxfw: fix a condition and return code in start_stream()
The amdtp_stream_wait_callback() doesn't return minus value and
the return code is not for error code.

This commit fixes with a propper condition and an error code.

Fixes: f3699e2c77 ('ALSA: oxfw: Change the way to start stream')
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: <stable@vger.kernel.org> # 3.19+
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-27 14:42:18 +01:00
Takashi Sakamoto dec84316dd ALSA: fireworks/bebob/dice/oxfw: make it possible to shutdown safely
A part of these drivers, especially BeBoB driver, are programmed to wait
some events. Thus the drivers should not destroy any data in .remove()
context.

This commit moves some destructors from 'struct fw_driver.remove()' to
'struct snd_card.private_free()' to shutdown safely.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: <stable@vger.kernel.org> # 3.19+
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-23 09:11:24 +01:00
Takashi Sakamoto d23c2cc448 ALSA: fireworks/bebob/dice/oxfw: allow stream destructor after releasing runtime
Currently stream destructor in each driver has a problem to be called in
a context in which sound card object is released, because the destructors
call amdtp_stream_pcm_abort() and touch PCM runtime data.

The PCM runtime data is destroyed in application's context with
snd_pcm_close(), on the other hand PCM substream data is destroyed after
sound card object is released, in most case after all of ALSA character
devices are released. When PCM runtime is destroyed and PCM substream is
remained, amdtp_stream_pcm_abort() touches PCM runtime data and causes
Null-pointer-dereference.

This commit changes stream destructors and allows each driver to call
it after releasing runtime.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: <stable@vger.kernel.org> # 3.19+
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-23 09:11:16 +01:00
Takashi Sakamoto c6f224dc20 ALSA: firewire-lib: remove reference counting
AMDTP helper functions increment/decrement reference counter for an
instance of FireWire unit, while it's complicated for each driver to
process error state.

In previous commit, each driver has the role of reference counting. This
commit removes this role from the helper function.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: <stable@vger.kernel.org> # 3.19+
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-23 09:11:08 +01:00
Takashi Sakamoto 12ed719291 ALSA: fireworks/bebob/dice/oxfw: add reference-counting for FireWire unit
Fireworks and Dice drivers try to touch instances of FireWire unit after
sound card object is released, while references to the unit is decremented
in .remove(). When unplugging during streaming, sound card object is
released after .remove(), thus Fireworks and Dice drivers causes GPF or
Null-pointer-dereferencing to application processes because an instance of
FireWire unit was already released.

This commit adds reference-counting for FireWire unit in drivers to allow
them to touch an instance of FireWire unit after .remove(). In most case,
any operations after .remove() may be failed safely.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: <stable@vger.kernel.org> # 3.19+
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-23 09:10:38 +01:00
Takashi Sakamoto ca5b50501d ALSA: firewire-lib: fix an unexpected byte sequence for micro sign
The sign for microsecond (U+0085, MICRO SIGN) was encoded to '0x c2 b5'
by UTF-8 character encoding scheme. But the byte sequence was converted
to '0x c3 82 c2 b5' in a previous commit. As a result, the byte
sequence cannot represent microsecond sign in UTF-8 or ASCII. This
may confuse developers.

This commit replaces the sign to string expression with 'microseconds'
to purge superfluous troubles.

Fixes: 5c697e5b46ef("ALSA: firewire-lib: remove rx_blocks_for_midi quirk")
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-23 08:46:03 +01:00
Clemens Ladisch 25ca917c0f ALSA: firewire-lib: limit the MIDI data rate
Do no send MIDI bytes at the full rate at which FireWire packets happen
to be sent, but restrict them to the actual rate of a real MIDI port.
This is required by the specification, and prevents data loss when the
device's buffer overruns.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Tested-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-01-16 22:51:23 +01:00
Clemens Ladisch 5c697e5b46 ALSA: firewire-lib: remove rx_blocks_for_midi quirk
There are several devices that expect to receive MIDI data only in the
first eight data blocks of a packet.  If the driver restricts the data
rate to the allowed rate (as mandated by the specification, but not yet
implemented by this driver), this happens naturally.  Therefore, there
is no reason to ever try to use more data packets with any device.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Tested-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-01-16 22:50:45 +01:00
Takashi Sakamoto 92cb46584e ALSA: fireworks: fix an endianness bug for transaction length
Although the 't->length' is a big-endian value, it's used without any
conversion. This means that the driver always uses 'length' parameter.

Fixes: 555e8a8f7f14("ALSA: fireworks: Add command/response functionality into hwdep interface")
Reported-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-01-07 16:39:21 +01:00
Dan Carpenter 5580ba7bf6 ALSA: oxfw: some signedness bugs
This code tends to use unsigned variables by default and it causes
signedness bugs when we use negative variables for error handling.
The "i" and "j" variables are used to iterated over small positive
values and so they should be type "int".  The "len" variable doesn't
*need* to be signed but it should be signed to make the code easier to
read and audit.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-15 10:03:21 +01:00
Dan Carpenter 0d3aba30b7 ALSA: oxfw: fix detect_loud_models() return value
This code causes a static checker warning:

	sound/firewire/oxfw/oxfw.c:46 detect_loud_models()
	warn: signedness bug returning '(-2)'

The detect_loud_models() function should return false on falure, so that
we don't try to set up the loud code for hardware that doesn't support
it.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-14 16:04:50 +01:00
Takashi Sakamoto 8985f4ac1c ALSA: oxfw: Add hwdep interface
This interface is designed for mixer/control application. By using this
interface, an application can get information about firewire node, can
lock/unlock kernel streaming and can get notification at starting/stopping
kernel streaming.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:50:00 +01:00
Takashi Sakamoto 05588d340a ALSA: oxfw: Add support for capture/playback MIDI messages
This commit adds MIDI functionality with an assumption of 'if the device
has MIDI comformant data channels in its stream formation, the device has
one MIDI port'.

When no streams have already started, MIDI functionality starts stream
with current sampling rate.

When MIDI functionality has already starts some streams and PCM
functionality is going to start streams at different sampling rate,
this driver stops streams once and changes sampling rate, then restarts
streams for both PCM/MIDI substreams.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:49:33 +01:00
Takashi Sakamoto 216e256f7b ALSA: oxfw: add support for capturing PCM samples
In previous commit, a support for transmitted packets is added. This commit
add a support for capturing PCM samples.

When any streams are already started, this driver should not change sampling
rate of the device, thus this commit also adds a restriction of sampling rate
in this situation.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:49:17 +01:00
Takashi Sakamoto b0ac00095f ALSA: oxfw: Add support AMDTP in-stream
Previous commit adds support for some devices which can capture PCM samples.
These devices transmit AMDTP stream in non-blocking mode. This commit adds
functionality to handle AMDTP incoming stream.

OXFW seems to have two quirks:
 - Transmits packets with non-zero dbc in its beginning
 - Transmits packets with wrong values in syt field

For the first quirk, this commit adds CIP_SKIP_INIT_DBC_CHECK flag for
incoming stream to skip first check of dbc.

For the second quirk, this commit doesn't add duplex stream which
Fireworks/BeBoB drivers use. So OXFW driver generates syt value for outgoing
stream.

Here are examples of a sequence of packets transmitted by Behringer F-Control
Audio 202. There are differences between sequences of syt value when OXFW
driver transfers outgoing stream or not.

When driver gives no outgoing stream:
Index   Payload CIP_Header_0    CIP_Header_1
38      14      00020092        900103D1
39      12      00020098        900102FF
40      12      0002009D        9001027F
41      14      000200A2        90010396
42      14      000200A8        900102E8
43      12      000200AE        90010219
44      14      000200B3        90010331
45      12      000200B9        9001025F
46      14      000200BE        90010376
47      12      000200C4        900102A1
00      12      000200C9        9001023E
01      14      000200CE        90010358
02      12      000200D4        90010289
03      16      000200D9        900103A3
04      12      000200E0        900102DD
05      14      000200E5        900103F1
06      12      000200EB        90010335
07      12      000200F0        90010263
08      14      000200F5        9001037C
09      12      000200FB        900102AE

When driver gives outgoing stream:
Index   Payload CIP_Header_0    CIP_Header_1
38      12      000200BD        900104A8
39      14      000200C2        900104A8
40      12      000200C8        900104AC
41      14      000200CD        900104A9
42      12      000200D3        900104B1
43      14      000200D8        900104A8
44      12      000200DE        900104AA
45      14      000200E3        900104A9
46      14      000200E9        900104AE
47      12      000200EF        900104A8
00      14      000200F4        900104AD
01      12      000200FA        900104A7
02      14      000200FF        900104A9
03      12      00020005        900104A9
04      14      0002000A        900104B1
05      12      00020010        900104AA
06      14      00020015        900104AD
07      12      0002001B        900104A7
08      14      00020020        900104AC
09      12      00020026        900104A7

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:48:59 +01:00
Takashi Sakamoto ec4dba5053 ALSA: oxfw: Add support for Behringer/Mackie devices
Some devices produced by Behringer/Mackie are based on OXFW970/971. This
commit adds support for them. Additionally, this commit changes the way to
name card with some information in config rom.

Ids of some Mackie(Loud) models are not identified, therefore this commit
applies name detection for these models.

The devices support capture/playback of PCM-samples and some of them
supports capture/playback of MIDI messages. These functionalities are
implemented by followed commits.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:48:30 +01:00
Takashi Sakamoto f3699e2c77 ALSA: oxfw: Change the way to start stream
In past commit, this driver can keep stream formations for each sampling
rate. So its stream functionality can decide stream formations with given
some parameters.

This commit moves related codes from PCM functionality to stream
functionality. Furthermore, to set stream format correctly, this commit
uses AV/C Stream Format Information command instead of AV/C Input/Output
Plug Signal Format command.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:48:12 +01:00
Takashi Sakamoto 3c96101f19 ALSA: oxfw: Add proc interface for debugging purpose
This commit adds proc interface to get information about stream
formation. This commit also adds snd_oxfw_stream_get_current_formation()
to get current stream formation.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:47:54 +01:00
Takashi Sakamoto 5cd1d3f47a ALSA: oxfw: Change the way to make PCM rules/constraints
In previous commit, this driver can get to know stream formations at
each supported sampling rates. This commit uses it to make PCM
rules/constraints and obsoletes hard-coded rules/constraints.

For this purpose, this commit adds 'struct snd_oxfw_stream_formation' and
snd_oxfw_stream_parse_format() to parse data channel formation of data
block.

According to datasheet of OXFW970/971, they support 32.0kHz to 196.0kHz.

As long as developers investigate, some devices are confirmed to have
several formats for the same sampling rate.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:47:37 +01:00
Takashi Sakamoto 5b59d8098d ALSA: oxfw: Add support for AV/C stream format command to get/set supported stream formation
OXFW970/971 may supports AV/C Stream Format Information Specification 1.1
Working Draft (Apr 2005, 1394TA). By using this command, drivers can get to know
stream formations which device supports.

This commit adds 'EXTENDED STREAM FORMAT INFORMATION' command. This command
has two subfunctions, 'SINGLE' and 'LIST'. Drivers can use 'SINGLE' subfunction
to know/set current formation of AMDTP stream, Drivers can use 'LIST'
subfunction to know an available formation of AMDTP stream in a certain sampling
rate.

But some devices don't implement the 'LIST' subfunction. So this commit uses
an assumption that 'if they don't implement it, they don't change stream
formation depending on current each sampling rate'. With this assumption, this
driver generates formations for such devices by:
 1.getting current formation by SINGLE subfunction
 2.getting supported sampling rates
 3.applying current formation for all of supported sampling rates

Followed commit implements a parser of this format information.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:47:09 +01:00
Takashi Sakamoto fec7b75362 ALSA: oxfw: Change the way to name card
This is a preparation for more models. In following commit, members
of 'struct snd_card' related to name becomes to consists of vendor and
model strings in device's config-rom.

Current supported devices also has strings in their config rom, but the
strings are too long to name sound card, thus this driver still keep
hard-coded vendor and model names for them.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:46:46 +01:00
Takashi Sakamoto a113ff886b ALSA: dice: Add support for MIDI capture/playback
This commit adds a support for MIDI capture/playback

When MIDI substrams already start streaming and PCM substreams are going to
join at different sampling rate, streams are stopped once. Then sampling rate
is changed and streams are restarted.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:46:14 +01:00
Takashi Sakamoto 69dcf3e47a ALSA: dice: Add support for capturing PCM samples
This commit adds a support for capturing PCM samples.

When opposite PCM substream is already running, available sampling rate is
limited at current one.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:45:53 +01:00
Takashi Sakamoto 8fc01fc067 ALSA: dice: Support for non SYT-Match sampling clock source mode
This commit allows this driver to handle devices with non SYT-Match
sampling clock source.

When sampling clock source is SYT-Match mode, devices handle
'presentation timestamp' in received packets and generates sampling clock
according to the information. In this case, driver is synchronization master
and must transfer correct value in SYT field of each packets in outgoing
stream, then the outgoing stream is a master stream.

On the other hand, non SYT-Match mode, devices do this. So drivers must pick
up the value in SYT field of incoming packets and use the value for outgoing
stream. Currently firewire-lib module achieve this work.

Furthermore, without SYT-Match and internal clock source, the sampling rate
should be fixed for the other devices connected to the handled device. This
commit add a restriction of sampling rate at this situation.

With these implementations, this driver has no need to set clock source.
This commit remove set function.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:45:28 +01:00
Takashi Sakamoto 9a02843cae ALSA: dice: Add support for duplex streams with synchronization
This commit adds support for AMDTP in-stream. As a result, Dice driver
supports full duplex streams with synchronization.

AMDTP can transfer timestamps in its packets. By handling the timestamp,
devices can synchronize to the other devices or drivers on the same bus.

When Dice chipset is 'enabled', it starts streams with correct settings.
This 'enable' register is global, thus, when a stream is started to run,
an opposite stream can't start unless turning off 'enable'. Therefore
a pair of streams must be running. This causes a loss of CPU usage when
single stream is needed for neither playbacking or capturing.

This commit assumes that playback-only models also have a functionality
to transmit stream for delivering timestamps.

Currently, sampling clock source is restricted to SYT-Match mode. This is
improved in followed commit. I note that at SYT-Match mode, Dice can select
from 4 streams for synchronization but this driver uses the 1st stream only
for simplicity.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:44:54 +01:00
Takashi Sakamoto 288a8d0cb0 ALSA: dice: Change the way to start stream
Streaming functionality can start streams when rate is given but currently
some codes are in PCM functionality.

This commit changes the way to start stream and add some arrangement
to make it easy to understand the way.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-10 10:44:37 +01:00
Fengguang Wu ea09dd3b00 ALSA: dice: fix semicolon.cocci warnings
sound/firewire/dice/dice-transaction.c:34:2-3: Unneeded semicolon

 Removes unneeded semicolon.

Generated by: scripts/coccinelle/misc/semicolon.cocci

CC: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-12-01 21:41:07 +01:00
Takashi Sakamoto 31514bfb4a ALSA: oxfw: Split control functionality to a new file
This is a help for works in followed patches.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:22:37 +01:00
Takashi Sakamoto 3713d93a6a ALSA: oxfw: Split PCM functionality to a new file
This is a help for works in followed patches.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:22:22 +01:00
Takashi Sakamoto e2786ca648 ALSA: oxfw: Split stream functionality to a new file and add a header file
This is a help for works in followed patches.

And this commit remove 'fw_unit_get()/fw_unit_put()' because these
are called by helper functions in 'snd-firewire-lib'.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:22:08 +01:00
Takashi Sakamoto 1a4e39c2e5 ALSA: oxfw: Move to its own directory
Followed commits add much codes. To make the work easy, this commit creates
own directory and move current file to it.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:21:43 +01:00
Takashi Sakamoto 8832c5a74b ALSA: speakers: Rename to oxfw and rename some members
This commit renames 'firewire-speakers' to 'oxfw' to enhance support for
devices which based on OXFW970/971. A line for MODULE_ALIAS is added.

Additionally, to help for works in followed paches, some members
in private structure are renamed.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:21:15 +01:00
Takashi Sakamoto 60cea52296 ALSA: dice: remove experimental state
Some developers test this driver, thus it's better to remove its
experimental state.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:20:23 +01:00
Takashi Sakamoto 2c2416c83e ALSA: dice: Add new functions for constraints of PCM parameters
This commit adds a new functions and some arrangement for PCM restriction.
This arrangement is due to the number of channels which each Dice device has.

I note that minimum number for period becomes 2, instead of 1 because its PCM
functionality has SNDRV_PCM_INFO_BATCH, this means that the driver uses double
(or more) buffering so the minimum number for period should be 2.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:17:06 +01:00
Takashi Sakamoto 04d426a039 ALSA: dice: Split proc interface into a file
This commit adds a file and move some codes related to proc output.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:09:47 +01:00
Takashi Sakamoto 19af57b46d ALSA: dice: Split hwdep functionality into a file
This commit adds a file and move some codes related to hwdep functionality.

This interface is designed for mixer/control application. By using hwdep
interface, the application can get information about firewire node, can
lock/unlock kernel streaming and can get notification at starting/stopping
kernel streaming.

Additionally, this interface give a way to read Dice notification.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:08:19 +01:00
Takashi Sakamoto c50fb91f53 ALSA: dice: Split PCM functionality into a file
This commit adds a file and move some codes related to PCM functionality.

Currently PCM playback is supported. PCM capture will be supported in followed
commits.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:07:47 +01:00
Takashi Sakamoto 6eb6c81eee ALSA: dice: Split stream functionality into a file
This commit adds a file with some helper functions for streaming, and move some
codes into the file with some arrangements.

Well-known CMP is not used to start/stop streams for Dice chipset. It's
achieved by writing to specific address. We call this way as 'enable'.
When devices are 'enabled', streaming starts in registered isochronous channel.
Some helper functions are already implemented in previous commit.

Basically, the stream is compliant to IEC 61883-6, so-called as AMDTP. But Dice
has a specific quirk, so called-as 'Dual Wire'. This quirk is applied at
176.4/192.0kHz. In this mode, each packet includes double number of events than
number in the specification, and stream runs at a half of sampling rate.

There is another quirk at bus reset. Dice chipset handles drivers' request but
don't re-enable streaming. So stream should be stopped.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:07:33 +01:00
Takashi Sakamoto 7c2d4c0cf5 ALSA: dice: Split transaction functionality into a file
This commit adds a file with some helper functions for transaction, and move
some codes into the file with some arrangements.

For Dice chipset, well-known FCP or AV/C commands are not used to control
devices. It's achieved by read/write transactions into specific addresses.

Dice's address area is split into 5 areas. Each area has its own role. The
offset for each area can be got by reading head of the address area. By
reading these areas, drivers can get to know device status. By writing these
areas, drivers can change device status.

Dice has a specific mechanism called as 'notification'. When device status is
changed, Dice devices tells the event by sending transaction. This notification
is sent to an address which drivers register in advance. But this causes an
issue to drivers.

To handle the notification, drivers need to allocate its own callback function
to the address region in host controller. This region is exclusive. For the
other applications, drivers must give a mechanism to read the received
notification. For this purpose, Dice driver already implements hwdep interface.

Dice chipset doesn't allow drivers to register several addresses. In this
reason, when this driver is applied to a device, the other drivers should
_not_ try to register its own address to the device.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:04:15 +01:00
Takashi Sakamoto 14ff6a0948 ALSA: dice: Move file to its own directory
In followed commits, dice driver is split into several files. For easily
managing these files, this commit adds subdirectory and move file into
the directory.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:03:45 +01:00
Takashi Sakamoto 732d153fbe ALSA: dice: Rename structure and its members
Currently, dice driver supports AMDTP out-stream. In followed commits, AMDTP
in-stream will be supported but current name of members in dice structure
are not propper. This commit renames these members to proper name.

Additionally, for easily distinguishing local symbols from structure tag,
rename dice tag into snd_dice.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-29 20:03:17 +01:00