Commit Graph

491 Commits

Author SHA1 Message Date
Takashi Sakamoto f90e2dedf7 ALSA: firewire-lib: compute the value of second field in cycle count for IR context
In callback function of isochronous context, modules can queue packets to
indicated isochronous cycles. Although the cycle to queue a packet is
deterministic by calculation, this module doesn't implement the calculation
because it's useless for processing.

In future, the cycle count is going to be printed with the other parameters
for debugging. This commit is the preparation. The cycle count is computed
by cycle unit, and correctly arranged to corresponding packets. The
calculated count is used in later commit.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-05-09 15:18:25 +02:00
Takashi Sakamoto 73fc7f0801 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>
2016-05-09 15:18:24 +02:00
Takashi Sakamoto f8ff65bce4 ALSA: dice: add support for M-Audio Profire 610 and perhaps 2626
M-Audio Profire 610 has an unexpected value in version field of its config
ROM, thus ALSA dice driver is not assigned to the model due to a mismatch
of modalias.

This commit adds an entry to support the model. I expect the entry is
also for Profire 2626.

I note that Profire 610 uses TCD2220 (so-called Dice Jr.), and supports a
part of Extended Application Protocol (EAP).

$ cd linux-firewire-utils/src
$ ./crpp < /sys/bus/firewire/devices/fw1/config_rom
               ROM header and bus information block
               ------------------------------------------------------------
400  04047689  bus_info_length 4, crc_length 4, crc 30345
404  31333934  bus_name "1394"
408  e0ff8112  irmc 1, cmc 1, isc 1, bmc 0, pmc 0, cyc_clk_acc 255,
               max_rec 8 (512), max_rom 1, gen 1, spd 2 (S400)
40c  000d6c04  company_id 000d6c     |
410  04400002  device_id 0404400002  | EUI-64 000d6c0404400002

               root directory
               ------------------------------------------------------------
414  000695fe  directory_length 6, crc 38398
418  03000d6c  vendor
41c  8100000a  --> descriptor leaf at 444
420  17000011  model
424  8100000d  --> descriptor leaf at 458
428  0c0087c0  node capabilities per IEEE 1394
42c  d1000001  --> unit directory at 430

               unit directory at 430
               ------------------------------------------------------------
430  0004fb14  directory_length 4, crc 64276
434  12000d6c  specifier id
438  130100d1  version
43c  17000011  model
440  8100000c  --> descriptor leaf at 470

               descriptor leaf at 444
               ------------------------------------------------------------
444  0004b8e4  leaf_length 4, crc 47332
448  00000000  textual descriptor
44c  00000000  minimal ASCII
450  4d2d4175  "M-Au"
454  64696f00  "dio"

               descriptor leaf at 458
               ------------------------------------------------------------
458  00053128  leaf_length 5, crc 12584
45c  00000000  textual descriptor
460  00000000  minimal ASCII
464  50726f46  "ProF"
468  69726520  "ire "
46c  36313000  "610"

               descriptor leaf at 470
               ------------------------------------------------------------
470  00053128  leaf_length 5, crc 12584
474  00000000  textual descriptor
478  00000000  minimal ASCII
47c  50726f46  "ProF"
480  69726520  "ire "
484  36313000  "610"

$ cat /proc/asound/card1/dice
sections:
  global: offset 10, size 90
  tx: offset 100, size 142
  rx: offset 242, size 282
  ext_sync: offset 524, size 4
  unused2: offset 0, size 0
global:
  owner: ffc0:000100000000
  notification: 00000040
  nick name: FW610
  clock select: internal 48000
  enable: 1
  status: locked 48000
  ext status: 00000040
  sample rate: 48000
  version: 1.0.4.0
  clock caps: 32000 44100 48000 88200 96000 176400 192000 aes1 aes4 aes adat tdif wc arx1 arx2 internal
  clock source names: SPDIF\AES34\AES56\TOS\AES_ANY\ADAT\ADAT_AUX\Word Clock\Unused\Unused\Unused\Unused\Internal\\
  ...

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-05-08 11:17:37 +02:00
Takashi Sakamoto b610386c8a ALSA: firewire-tascam: deleyed registration of sound card
When some tascam units are connected sequentially, userspace
applications are involved at bus-reset state on IEEE 1394 bus. In the
state, any communications can be canceled. Therefore, sound card
registration should be delayed till the bus gets calm.

This commit achieves it.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-04-25 10:40:42 +02:00
Takashi Sakamoto 86c8dd7f4d ALSA: firewire-digi00x: delayed registration of sound card
When some digi00x units are connected sequentially, userspace
applications are involved at bus-reset state on IEEE 1394 bus. In the
state, any communications can be canceled. Therefore, sound card
registration should be delayed till the bus gets calm.

This commit achieves it.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-31 15:36:20 +02:00
Takashi Sakamoto 6c29230e2a ALSA: oxfw: delayed registration of sound card
Some oxfw based units tends to fail asynchronous communication when
IEEE 1394 bus is under bus-reset state. When registering sound card
instance at unit probe callback, userspace applications can be involved
to the state.

This commit postpones the registration till the bus is calm.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-31 15:36:19 +02:00
Takashi Sakamoto 7d3c1d5901 ALSA: fireworks: delayed registration of sound card
When some fireworks units are connected sequentially, userspace
applications are involved at bus-reset state on IEEE 1394 bus. In the
state, any communications can be canceled. Therefore, sound card
registration should be delayed till the bus gets calm.

This commit achieves it.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-31 15:36:19 +02:00
Takashi Sakamoto 04a2c73c97 ALSA: bebob: delayed registration of sound card
Some bebob based units tends to fail asynchronous communication when
IEEE 1394 bus is under bus-reset state. When registering sound card
instance at unit probe callback, userspace applications can be involved
to the state.

This commit postpones the registration till the bus is calm.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-31 15:36:18 +02:00
Takashi Sakamoto 923f92ebb4 ALSA: firewire-lib: add new function to schedule a work for sound card registration
In former commit, ALSA dice driver postpone sound card registration after
IEEE 1394 bus is calm. This idea has advantages for the other drivers.

This commit adds a helper function for it to firewire-lib module. The
function is really for the specific purpose. Callers should initialize
delayed work structure with callback function.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-31 15:36:18 +02:00
Takashi Sakamoto 0eced45ca6 ALSA: dice: simplify unit probe processing
In former commit, ALSA dice driver doesn't generate kernel warnings
when unplugging units before initializing stream data.

This commit moves the initialization to delayed registration of sound
card, to simplify unit probe processing.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-31 15:36:17 +02:00
Takashi Sakamoto 44c376b959 ALSA: firewire-lib: suppress kernel warnings when releasing uninitialized stream data
When any of AMDTP stream data are not initialized and private data is
going to be released, WARN_ON() in amdtp_stream_destroy() is hit and
dump messages. This may take users irritated.

This commit fixes the bug to skip releasing when it's not initialized.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-31 15:36:17 +02:00
Takashi Sakamoto 25c0e953eb ALSA: firewire-tascam: add Kconfig entry for TASCAM FW-1804
I forgot it.

Fixes: 3e78e1518e12('ALSA: firewire-tascam: add support for FW-1804')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-28 09:39:41 +02:00
Takashi Sakamoto 0655ac2f40 ALSA: fireworks: move model quirk detection code to information parser
Currently, model-specific quirks are detected out of information parser,
however it's natural to detect it in the parser.

This commit applies the idea.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-28 09:39:41 +02:00
Takashi Sakamoto 329fec2f7f ALSA: oxfw: remove needless member from private structure
In former commit, 'struct device_info' is obsoleted, whereas private
structure still keeps a pointer to it.

This commit remove the member.

d6ce6bbd7d83('ALSA: oxfw: rename a structure so that it means backward compatibility to old drivers')

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-28 09:39:40 +02:00
Takashi Sakamoto 093dd44978 ALSA: bebob: remove needless argument from local function
The 'vendor_id' argument is not used in the local function. Let's remove
it.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-28 09:39:40 +02:00
Takashi Sakamoto 6b94fb14fc ALSA: dice: fix memory leak when unplugging
When sound card is going to be released, dice private data is
also released. Then all of data should be released. However,
stream data is not released. This causes memory leak when
unplugging dice unit.

This commit fixes the bug.

Fixes: 4bdc495c87b3('ALSA: dice: handle several PCM substreams when any isochronous streams are available')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-28 09:32:57 +02:00
Takashi Sakamoto 8cc1a8ab47 ALSA: dice: use structure to represent register parameters instead of array with basic type element
In dice interface, two blocks of register are accessible via IEEE 1394
asynchronous transaction to represent the number of supported isochronous
streams and the number of quadlets for stream information.

Current ALSA dice driver uses array with 'unsigned int' element for
temporary cache of these information. But using structure is preferable
for begin easily comprehensible.

This commit applies a local structure for this aim.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-10 15:44:39 +01:00
Takashi Sakamoto 7cafc65b3a ALSA: dice: force to add two pcm devices for listed models
Some models reduce the number of available isochronous streams for higher
sampling transfer frequency. Such models bring an issue about how to add
PCM substreams. When at lower sampling transfer frequency, the
models reports whole available streams, thus this driver can add enough
number of PCM substreams at probing time. On the other hand, at higher
sampling transfer frequency, this driver can just add reduced number of
PCM substreams. After probed, even if the sampling transfer frequency is
changed to lower rate, fewer PCM substreams are actually available. This
is inconvenience.

For the reason, this commit adds a list so that this driver assume models
on the list to have two pairs of PCM substreams. This list keeps the name
of model in which the number of available streams differs depending on
sampling transfer frequency.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-09 16:20:58 +01:00
Takashi Sakamoto 4bdc495c87 ALSA: dice: handle several PCM substreams when any isochronous streams are available
In former commits, ALSA dice driver can handle available isochronous
streams. This commit adds support for several PCM substreams on the
streams.

The additional PCM substreams are available via another ALSA PCM character
devices so that one ALSA PCM application can handle them without cumbersome
operations. For example, two PCM substreams are available on each stream,
two ALSA character devices are added for them. In configuration space of
alsa-lib, it's represented with 'hw:0,0' and 'hw:0,1'.

The PCM substreams are constraint to parameters of the corresponding
streams. If the PCM substreams are unavailable for some reasons,
open(2) to ALSA PCM character device returns error and reports ENXIO.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-09 16:20:57 +01:00
Takashi Sakamoto 436b5abe22 ALSA: dice: handle whole available isochronous streams
This commit enables ALSA dice driver to handle whole available streams.

In Dice, certain registers represent the number of available streams at
current sampling transfer frequency for both directions. The parameters
of each stream are represented in a block of register. This block is
aligned sequentially. These streams start simultaneously by writing
enable bit to a register.

This commit operates these registers when starting/stopping streams.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-09 16:20:57 +01:00
Takashi Sakamoto 8ae25b760a ALSA: dice: have two sets of isochronous resources/streams
Currently ALSA dice driver handles a pair of isochronous resources for
IEC 61883-1/6 packet streaming. While, according to some documents about
ASICs named as 'Dice', several isochronous streams are available.

Here, I start to describe ASICs produced under 'Dice' name.
 * Dice II (designed by wavefront semiconductor, including TCAT's IP)
   * STD (with limited functionality of DTCP)
   * CP  (with full functionality of DTCP)
 * TCD2210/2210-E (so-called 'Dice Mini')
 * TCD2220/2220-E (so-called 'Dice Jr.')
 * TCD3070-CH (so-called 'Dice III')

Some documents are public and we can see hardware design of them. We can
find some articles about hardware internal register definitions
(not registers exported to IEEE 1394 bus).

* DICE II User Guide
  * http://www.tctechnologies.tc/archive/downloads/dice_ii_user_guide.pdf
    * 6.1 AVS Audio Receivers
      * Table 6.1: AVS Audio Receiver Memory Map
        * ARX1-ARX4
    * 6.2 AVS Audio Transmitters
      * Table 6.2: AVS Audio Transmitter Memory Map
        * ATX1, ATX2
* TCD22xx User Guide
  * http://www.tctechnologies.tc/downloads/tcd22xx_user_guide.pdf
    * 6.1 AVS Audio Receivers
      * Table 66: AVS Audio Receiver Memory Map
        * ARX1, ARX2
    * 6/2 AVS Audio Transmitters
      * Table 67: AVS Audio Transmitter Memory Map
        * ATX1, ATX2
* DICE III
  * http://www.tctechnologies.tc/downloads/TCD3070-CH.pdf
    * Dual stream 63 channel transmitter/receiver

For Dice II and TCD22xx series, maximum 16 data channels are transferred in
an AMDTP packet, while for Dice III, maximum 32 data channels are
transferred.

According to the design of the series of these ASICs, this commit allows
this driver to handle additional set of isochronous resources. For
practical reason, two pair of isochronous resources are added. As of this
commit, this driver still use a pair of the first isochronous resources.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-09 16:20:56 +01:00
Takashi Sakamoto 1387e3eafa ALSA: dice: drop duplex streams synchronization to transfer own time stamps
This commit drops implementation of duplex streams synchronization
from ALSA dice driver, due to a reason of hardware design. This patch
allows dice-based units to generate sounds correctly when isochronous
packet streaming starts at first time.

In IEC 61883-6:2005, CIP packetization layer for AM824 data format
utilizes the value of SYT field in CIP header of received packet for
a reference to phase lock loop. Figure 3 in clause 4.3 describes it.
The value is an offset from cycle_time field of every cycle start packet
from cycle master on IEEE 1394 bus. The time calculated with these two
fields is called as 'presentation timestamp' which represents the time
to play data included in the packet.

Although, this idea includes some problems due to accuracy of timekeep in
cycle master, accuracy of transmission of cycle start packet on the bus
with the other units, accuracy of sampling clock in data transmitter side
and accuracy of replay in data receiver side. In most case, these
accuracies somewhat worse because there's no such ideal hardwares in this
world.

For the issues, ASICs for Dice include Jitter Elimination Technologies
(JET) PLL. The PLL can handle several sources of clock and compensate it
with high-precision internal clock source. The sequence of value in syt
field of received AMDTP packets is one of the sources, therefore
transmitters on IEEE 1394 bus should transfer it.

On the other hand, current ALSA dice driver is programmed with a mode of
duplex streams with synchronization. In this mode, the driver outputs
packets after some incoming packets are handled, to re-use the value of
SYT field in incoming packets to the value for outgoing packets. This mode
is enabled when source signal of sampling clock is set to internal, and
this is a major use case. Thus, in most cases, the unit receives no packets
during a short time after packet streaming starts.

As long as I experienced, this causes the units to generate no sounds at
first time to receive packets. This issue occurs only with Dice II. I guess
this is due to a quirk of the PLL. In short, the PLL cannot generate firm
signals to ADCs/DACs or the other ICs when no packets are received in the
beginning of packet streaming. While, on second time or later, the unit
generates sound correctly. I guess that starting packet streaming at first
time sets the PLL correctly.

Well, still based on my hypothesis and no way to prove it, this commit
drops duplex streams synchronization from this driver. At least, the PLL
requires the sequence of value in SYT field of received AMDTP packets as
one of source of clock signals with internal clock source.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-28 10:56:24 +01:00
Takashi Sakamoto 956dea9e91 ALSA: oxfw: discontinue MIDI substream for scs1x at transaction failure
With a previous commit, ALSA oxfw driver retries transferring MIDI
messages at transaction failure for scs1x. On the other hand, there're
fatal transaction error. Then, no MIDI messages reach to the unit anymore.
In this case, MIDI substream should be terminated.

This commit stops MIDI transmission after the fatal error occurs.
Unfortunately, unlike ALSA PCM functionality, ALSA rawmidi core has no
feature to discontinue MIDI substream runtime in kernel side, thus this
commit just stops MIDI transmission without notifying it to userspace.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-24 16:32:08 +01:00
Takashi Sakamoto b4c23ab1cb ALSA: oxfw: retry MIDI transferring for scs1x at transaction failure
Currently, ALSA oxfw driver has a TODO to retry MIDI transferring
at transaction failure.

This commit achieves it. Current implementation uses snd_rawmidi_transmit()
to transfer messages, thus the target MIDI messages are not in buffer when
transaction failure is detected. Although we cannot use a pair of
snd_rawmidi_transmit_peek() and snd_ramwidi_transmit_ack(), the
messages are still in scs1x specific structure and the data is available
for retries.

This commit adds a member to the structure for the length of buffered
messages, and uses the value again at retries.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-24 16:31:54 +01:00
Takashi Sakamoto 99d7355914 ALSA: fireworks: serialize transactions to update connections at bus reset
In IEC 61883-1, at bus-reset, applications can continue isochronous
streaming by updating connections. In ALSA fireworks driver, the
operation is executed in 'update' handler for bus driver.

The connection resources are also changed in process contexts of PCM/MIDI
applications. Therefore, bus-reset handling has race condition
against connection. Current ALSA fireworks driver has a bug for the
condition.

This commit fixes the bug, by expand critical section with mutex. As a
result, connection updating operation in bus-reset handler and connection
changing operation in process context are serialized.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-20 15:46:38 +01:00
Takashi Sakamoto 3800e6f944 ALSA: bebob: give up updating streams at bus reset handler
DM1000/DM1100/DM1500 chipsets transfer packets with discontinue value in
'dbc' field of CIP header. For ALSA bebob driver, this makes its bus-reset
handler meaningless, because the discontinuity is detected quite earlier
than executing the handler.

This commit gives up updating streams at the bus reset handler.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-20 15:45:54 +01:00
Takashi Sakamoto 4fd6c6c729 ALSA: bebob: change type of substream counter from atomic_t to unsigned int
The counter is incremented/decremented in critical section protected with
mutex. Therefore, no need to use atomic_t.

This commit changes the type to unsigned int.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-20 15:45:38 +01:00
Takashi Sakamoto 2a71e70166 ALSA: bebob: move mutex from function callee to callers
Currently, critical section is protected by mutex in functions of
fireworks_stream.c. Callers increments/decrements substreams counter
before calling the functions. Moving mutex to the callers code allows
to change type of the substream counter from atomic_t to unsigned int.

This commit is a preparation for obsoleting usage of atomic_t for
substream counter.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-20 15:45:25 +01:00
Takashi Sakamoto 14a37ac1bf ALSA: bebob: simplify bus-reset handling
At bus-reset, DM1000/DM1100/DM1500 chipsets transfer packets with
discontinuous value in 'dbc' field of CIP header. In this case, packet
streaming layer in firewire-lib module stops streaming and set XRUN to PCM
substream.

In ALSA, PCM applications are notified the XRUN status by the return value
of ALSA PCM interface. They can recover this state by executing
snd_pcm_prepare(), then PCM drivers' prepare handler is called, and start
new PCM substream. For ALSA BeBoB driver, the handler establishes new
connections and start new AMDTP streaming.

Unfortunately, neither the PCM applications nor the driver know the reason
of XRUN. The driver gets to know the reason when update handler is called
by IEEE 1394 bus driver. As long as I tested, the order of below events are
not fixed:
 * Detecting packet discontinuity in tasklet context of OHCI 1394 driver
 * Calling prepare handler in process context of ALSA PCM application
 * Calling update handler in kthread context of IEEE 1394 bus driver

The unpredictable order is disadvantage for the driver to be compliant to
CMP. In IEC 61883-1, new CMP establish operations should be done 1 sec
(isoc_resource_delay) after bus-reset. Within 1 sec, CMP restore
operations are allowed. For this reason, in former commit ('b6bc812327aa:
ALSA: bebob/firewire-lib: Add a quirk for discontinuity at bus reset'),
the process context is forced to wait for executing update handler. The
process context wait for bus-reset up to 1 sec. This commit solves the
issue, while causes more disadvantages. For PCM applications, calling
snd_pcm_prepare() for recovering XRUN state takes more time and the driver
got a bit complicated code, while the recovery is not always successful.

As long as I tested, DM1000/DM1100/DM1500 and BeBoB firmware can allow
drivers to establish new connections just after bus reset. Furthermore,
any FCP transactions are handled correctly. Therefore, the driver don't
need to wait for bus reset handler for starting new streaming.

This commit removes the codes to reduce maintenance cost.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-20 15:45:15 +01:00
Takashi Sakamoto ea79005367 ALSA: oxfw: use workqueue instead of tasklet for scs1x
This commit replaces tasklet with workqueue for scs1x functionality of
ALSA oxfw driver.

This driver transfers MIDI message specific for SCS.1m and SCS.1d. This
task is currently done in software IRQ context of tasklet. In a view of
system, this context is limited resources and some important drivers (at
least, more important than ALSA oxfw driver) use the context as its
bottom-harf.

If the work to transfer MIDI messages is done within a time, it's better
to use the other context for the work. Actually, with recent CPUs, the
work will be scheduled within a time. This is a reason of this commit.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-18 15:18:33 +01:00
Takashi Sakamoto fbeac84dbe ALSA: dice: old firmware optimization for Dice notification
As long as I tested, Dice-based models produced by TC Electronic with
factory-configured settings transfer no notification within
ensure_phase_lock(). On the other hand, with upgraded firmwares, it
starts to transfer the notification. This seems to be a quirk of earlier
firmwares.

This commit ensures phase lock by reading a register after waiting for
the notification. Even if it's timed-out, ensure_phase_lock() return
success as long as the register has expected clock status.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-12 09:52:49 +01:00
Takashi Sakamoto aec045b80d ALSA: dice: change notification mask to detect lock status change
With former patchset, ALSA dice driver doesn't change clock parameters
anymore, while the driver still touch clock configuration for phase lock.

Although the locking status is in Dice notification, the driver doesn't
detect it. Usually, this causes no issues because in most case
NOTIFY_LOCK_CHG notification transfers after NOTIFY_CLOCK_ACCEPTED
notification, while it's better to detect locking status.

This commit changes notification mask just to detect lock status change.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-12 09:52:43 +01:00
Takashi Iwai 9b88daa513 Merge branch 'for-linus' into for-next 2016-02-09 23:08:48 +01:00
Takashi Sakamoto dfabc0eee1 ALSA: dice: ensure phase lock before starting streaming
In former commits, probing process has no need to set sampling transfer
frequency. Although it's OK to drop a function to change the frequency
from this module, some models require it before streaming. This seems to
be due to phase lock of clock source.

This commit moves the function from transaction layer to stream layer, and
rename it according to the purpose.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-09 12:22:11 +01:00
Takashi Sakamoto 6f688268b3 ALSA: dice: purge generating channel cache
Dice interface design doesn't allow drivers to read supported combination
between sampling transfer frequencies and the number of Multi bit linear
audio data channels. Due to the design, ALSA dice driver changes current
sampling transfer frequency to generate cache of the combinations at
device probing processing.

Although, this idea is worse because ALSA dice driver changes the state of
clock. This is not what users want when they save favorite configuration
to the device in advance.

Furthermore, there's a possibility that the format of data block is decided
not only according to current sampling transfer frequency, but also the
other factors, i.e. data format for digital interface. It's not good to
generate channel cache according to the sampling transfer frequency only.

This commit purges processing cache data and related structure members. As
a result, users must set preferable sampling transfer frequency before
using ALSA PCM applications, as long as they want to start any PCM
substreams at the rate except for current one.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-09 12:22:10 +01:00
Takashi Sakamoto c30076568d ALSA: dice: get the number of MBLA data channel at opening PCM substream
This commit is a preparation to remove members related to channel cache
for the number of channels for multi bit linear audio data and MIDI
ports. This commit changes the way to get the number of multi bit linear
audio data channel. It's directly retrieved by asynchronous transactions
to some registers.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-09 12:22:10 +01:00
Takashi Sakamoto b9022f4d2c ALSA: dice: add MIDI ports according to current number of MIDI substreams
This commit changes the way to add ALSA MIDI ports. This driver read the
number of multiplexed MIDI substreams from hardware register, then adds the
same number of ALSA MIDI ports. This commit is based on my assumption that
the number is fixed at all of supported sampling transfer frequency.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-09 12:22:09 +01:00
Takashi Sakamoto 1bc8e12d94 ALSA: dice: limit stream to current sampling transfer frequency.
In previous commit, ALSA Dice driver limits PCM substreams at current
sampling transfer frequency and current number of Multi bit linear audio
data channel. Thus, the driver has no need to start AMDTP streams at
the other sampling transfer frequency except for current one. This is due
to Dice interface design.

This commit limits AMDTP stream at current sampling transfer frequency,
according to the design.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-09 12:22:09 +01:00
Takashi Sakamoto 0d5ee195b1 ALSA: dice: limit to current sampling transfer frequency
ALSA PCM core has a functionality for rule of PCM substream parameters.
Typically, when userspace opens PCM character devices, each driver adds
its own rules to PCM substream according to design of hardware. When the
userspace executes hw_params ioctl with favorite parameters, the actual
parameters are calculated according to the rules and the given parameters.
Then, the result is returned to userspace.

Currently, ALSA Dice driver has the rule between channels and rates, while
Dice interface design doesn't allow drivers to retrieve all of the
combinations. Dice drivers are just allowed to get current sampling
transfer frequency and the number of multi bit linear audio data channels
in an data block of an AMDTP packet.

This commit purges the rule, and limit PCM substreams to current sampling
transfer frequency, following to the interface design.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-09 12:22:08 +01:00
Geert Uytterhoeven b8cb3750ce ALSA: firewire-digi00x: Drop bogus const type qualifier on dot_scrt()
sound/firewire/digi00x/amdtp-dot.c:67: warning: type qualifiers ignored on function return type

Drop the bogus "const" type qualifier on the return type of dot_scrt()
to fix this.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-09 12:16:52 +01:00
Takashi Sakamoto 56661a2ed5 ALSA: firewire-tascam: remove needless member for control and status message
Commit 3beab0f844 added a member for control and status message, while
it's planned and not implemented yet.

This commit removes it.

Fixes: 3beab0f844fa('ALSA: firewire-tascam: add support for outgoing MIDI messages by asynchronous transaction')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-05 12:47:14 +01:00
Takashi Sakamoto 61ebe49964 ALSA: firewire-tascam: remove a flag for controller
Currently, 'struct snd_tscm_spec' has a member named as 'is_controller' to
identify MIDI controller. This member was originally added to skip
parse control and status messages in isochronous packets for non-controller
model.

As long as I investigate, FW-1804 (non-controller) also transfers the
control and status message, thus it becomes meaningless.

This commit removes it.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-05 12:46:15 +01:00
Takashi Sakamoto 3e78e1518e ALSA: firewire-tascam: add support for FW-1804
This model supports:
 * maximum 12 PCM channels for PCM playback
 * maximum 18 PCM channels for PCM capture
 * 4 ports for MIDI playback
 * 4 ports for MIDI capture
 * control and status messages in tx isochronous packets
 * up to 96.0 kHz

This commit adds support for the model. As the other supported models,
all of available PCM channels are always enabled.

As I described in commit c0949b2785, Ilya Zimnovich had investigated
TASCAM FireWire series in 2011 with his FW-1804. In his report, this model
has internal multiplexer and any software implementation can control it.
Following to the design of ALSA firewire stack, this commit won't
implement it. It should be in userspace via Linux fw character device.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-05 12:46:07 +01:00
Takashi Sakamoto 5d2560a427 ALSA: firewire-tascam: fix NULL pointer dereference when model identification fails
When unsupported models are connected, snd-firewire-tascam module causes
NULL pointer dereference in fw_core_remove_address_handler() (due to
list_del_rcu()).

This commit prevents this bug.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-02-05 12:45:59 +01:00
Lucas Tanure 07905298e4 ALSA: bebob: Use a signed return type for get_formation_index
The return type "unsigned int" was used by the get_formation_index function
despite of the aspect that it will eventually return a negative	error code.
So, change to signed int and get index by reference in the parameters.

Done with the help of Coccinelle.

[Fix the missing braces suggested by Julia Lawall -- tiwai]

Signed-off-by: Lucas Tanure <tanure@linux.com>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Tested-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-01-26 11:38:53 +01:00
Takashi Sakamoto 2eb65d67af ALSA: dice: expand timeout to wait for Dice notification
Some users have reported that their Dice based models generate ETIMEDOUT
when starting PCM playback. It means that current timeout (=100msec) is
not enough for their models to transfer notifications.

This commit expands the timeout up to 2 sec. As a result, in a worst case,
any operations to start AMDTP streams takes 2 sec or more. Then, in
userspace, snd_pcm_hw_params(), snd_pcm_prepare(), snd_pcm_recover(),
snd_rawmidi_open(), snd_seq_connect_from() and snd_seq_connect_to() may
take the time.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-01-06 10:18:54 +01:00
Takashi Sakamoto a2875a92b8 ALSA: dice: purge transaction initialization at timeout of Dice notification
In previous commit, card registration is processed under situation
with few bus reset. There's no need to add a workaround of transaction
re-initialization at timeout.

This commit purges the re-initialization.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-01-06 10:18:54 +01:00
Takashi Sakamoto b59fb1900b ALSA: dice: postpone card registration
Some models based on ASIC for Dice II series (STD, CP) change their
hardware configurations after appearing on IEEE 1394 bus. This is due to
interactions of boot loader (RedBoot), firmwares (eCos) and vendor's
configurations. This causes current ALSA dice driver to get wrong
information about the hardware's capability because its probe function
runs just after detecting unit of the model.

As long as I investigated, it takes a bit time (less than 1 second) to load
the firmware after bootstrap. Just after loaded, the driver can get
information about the unit. Then the hardware is initialized according to
vendor's configurations. After, the got information becomes wrong.
Between bootstrap, firmware loading and post configuration, some bus resets
are observed.

This commit offloads most processing of probe function into workqueue and
schedules the workqueue after successive bus resets. This has an effect to
get correct hardware information and avoid involvement to bus reset storm.

For code simplicity, this change effects all of Dice-based models, i.e.
Dice II, Dice Jr., Dice Mini and Dice III.

I use a loose strategy to manage a race condition between the work and the
bus reset. This is due to a specification of dice transaction. When bus
reset occurs, registered address for the transaction is cleared. Drivers
must re-register their own address again. While, this operation is required
for the work because the work includes to wait for the transaction. This
commit uses no lock primitives for the race condition. Instead, checking
'registered' member of 'struct snd_dice' avoid executing the work again.
If sound card is not registered, the work can be scheduled again by bus
reset handler.

When .remove callback is executed, the sound card is going to be released.
The work should not be pending or executed in the releasing. This commit
uses cancel_delayed_work_sync() in .remove callback and wait till the
pending work finished. After .remove callback, .update callback is not
executed, therefore no works are scheduled again.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-01-06 10:18:53 +01:00
Takashi Sakamoto 4a47a87def ALSA: dice: split subaddress check from category check
Before allocating an instance of sound card, ALSA dice driver checks
chip_ID_hi in Bus information block of Config ROM, then also checks
subaddresses. The former operation reads cache of Config ROM in Linux
FireWire subsystem, while the latter operation sends read transaction.
The latter can be merged into initialization of transaction system.

This commit splits these two operations to reduce needless transactions
in probe processing.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-01-06 10:18:52 +01:00
Takashi Sakamoto de5126cc3c ALSA: oxfw: add stream format quirk for SCS.1 models
As long as I investigate SCS.1m, this model reports to transfer/receive
PCM data channels/MIDI conformant data channels in tx/rx AMDTP packet.
There's a contradiction that this model actually has no analog/digital
capture port for PCM frames and no physical MIDI ports.

I guess that SCS.1d also has the contradiction. This model has no
analog/digital ports for PCM frames and no physical MIDI ports, thus it
requires no streaming functionality.

This commit adds some modification codes to handle the contradiction,
as much as possible. Unfortunately, this module adds one PCM playback
substream for SCS.1d so as SCS.1m.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-22 11:51:32 +01:00
Takashi Sakamoto 9e2004f9ce ALSA: oxfw: obsolete scs1x module
Now ALSA oxfw driver gains functionalities which scs1x module has.

This commit obsoletes the scs1x module, and adds a line of MODULE_ALIAS
to load oxfw module instead of scs1x module.

In scs1x module, the name of 'shortname' field is fixed as 'SCS1x'. This
field is used to name MIDI ports for both of SCS.1m and SCS.1d. This is
not good because typically some SCS.1m and SCS.1d are used in the same
system. It's better to distinguish them according to name of the ports.
This commit applies model name in config ROM to the 'shortname'.

For the name of 'driver' and 'longname', this commit uses the same way
applied to the other models. This change may not bring disadvantages to
users because userspace applications use ALSA rawmidi or seq interface
and these interfaces are not influenced by them directly.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-22 11:51:31 +01:00
Takashi Sakamoto 6f5dcb28df ALSA: oxfw: add MIDI playback port for SCS.1 models
This commit adds MIDI playback ports so that scs1x driver has.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-22 11:51:31 +01:00
Takashi Sakamoto d7d20e7781 ALSA: oxfw: copy handlers of asynchronous transaction for MIDI playback
This commit copies some functions of asynchronous transactions for MIDI
playback, to merge scs1x module. The features of payload in asynchronous
transaction are the same as captured MIDI messages.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-22 11:51:30 +01:00
Takashi Sakamoto 8250427dc1 ALSA: oxfw: add MIDI capture port for SCS.1 models
This commit adds MIDI capture so that scs1x driver has.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-22 11:51:29 +01:00
Takashi Sakamoto 13b8b78c7f ALSA: oxfw: copy handlers of asynchronous transaction for MIDI capture
This commit copies some functions of asynchronous transactions for MIDI
capture, to merge scs1x module. The features of payload in asynchronous
transaction are:

 * System exclusive messages for SCS.1 are encoded without ID data. In
   this encoding scheme, 4 bits in LSB are available. The bits are squashed
   in payload byte. Thus, one payload byte transfers two MIDI messages.
 * The first byte of payload byte means:
  * 0x00: depending on second payload byte
   * 0xf9: including escaped system exclusive messages for SCS.1, up to
     3 byte (= 6 MIDI messages)
   * the others: including MIDI 1.0 messages
  * the others: including escaped system exclusive messages for SCS.1, up
    to 64 bytes

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-22 11:51:29 +01:00
Takashi Sakamoto e3315b439c ALSA: oxfw: allocate own address region for SCS.1 series
When physical controls on SCS.1 models are operated, the models transfer
MIDI messages in asynchronous transactions on IEEE 1394 bus. The models
have a register to have an address for the transactions, and drivers
can register own address for this purpose.

This commit keeps a region of address, registers it and adds a handler for
the transactions.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-22 11:51:28 +01:00
Takashi Sakamoto 3f47152a1c ALSA: oxfw: add scs1x layer
Stanton Controllers and Systems 1 (SCS.1) series is supported by ALSA
scs1x driver. This driver just supports MIDI functionality. On the other
hand, models in this series are based on OXFW971 and ALSA OXFW driver can
support them.

SCS.1 series has MIDI functionality to control its surface state such as
LED lighting. When operating physical knobs and faders, the models
generate MIDI messages. These MIDI messages are transferred by asynchronous
transactions. These transactions are really model-specific and ALSA OXFW
driver requires the functionality so as scs1x module implements.

This commit adds scs1x layer as a preparation to merge scs1x driver to
oxfw driver.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-22 11:51:27 +01:00
Takashi Sakamoto d6ce6bbd7d ALSA: oxfw: rename a structure so that it means backward compatibility to old drivers
In former commits, some model-specific members are split from the
structure. The structure is just to keep names for compatibility to old
drivers.

This commit arranges name of the structure and localize it.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-22 11:50:31 +01:00
Takashi Sakamoto 3e2f45708e ALSA: oxfw: move model-specific parameters from common structure
In previous commit, some members are moved from 'struct snd_oxfw' because
they're model-specific. There are also the other model-specific parameters
in 'struct device_info'.

This commit moves these members to model-specific structure.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-22 11:50:31 +01:00
Takashi Sakamoto 40540de503 ALSA: oxfw: move model-specific members from common structure
Currently, 'struct snd_oxfw' has some members for models supported by old
firewire-speakers driver, while these members are useless to the other
models.

This commit allocates new memory block and moves these members to
model-specific structure.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-22 11:50:30 +01:00
Takashi Sakamoto c582cc66b9 ALSA: oxfw: enable to keep memory block for model-specific structure
ALSA oxfw driver should have backward compatibility to old
firewire-speakers driver. Additionally, in future commit, scs1x driver
will be merged. It's nice to add a pointer to have a memory block for
model-specific structures.

This commit adds a member to 'struct snd_oxfw' for this aim. Deallocation
is done at freeing ALSA card structure.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-22 11:50:29 +01:00
Takashi Iwai f2777c1344 Merge branch 'topic/firewire-update' into for-next 2015-12-16 12:09:10 +01:00
Takashi Sakamoto 5ce8cc4844 ALSA: oxfw: gather model-dependent conditions to a function
Adding control elements is just for models supported by old
firewire-speakers modules. The processing should be in a function to add
model-dependent quirk.

This commit moves the codes to the function. As a result, the function
should handle error state, thus this commit also changes prototype of
the function.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-15 16:30:05 +01:00
Takashi Sakamoto 27e6663501 ALSA: oxfw: reuse driver entry to detect quirks
Currently, assignment to model-dependent quirk is corresponding to
asynchronous transactions on IEEE 1394 bus. This is also achieved with
device entry.

This commit changes the processing of model-dependent quirk with the
entry. As a result, the transactions are sent only for Loud models.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-15 16:30:04 +01:00
Takashi Sakamoto eab8e4e461 ALSA: oxfw: change function prototype for AV/C Audio Subunit command
ALSA OXFW driver uses AV/C Audio Subunit commands to control some models.
The commands get/set the state of Feature function block of the subunit.
The commands are not specific to OXFW, thus there's a possibility to use
them in the other drivers.

Currently, helper functions for the commands require 'struct snd_oxfw',
although, it's not necessarily required. It's better to change prototype
of the functions without the structure for future use.

This commit changes the prototype.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-15 16:30:04 +01:00
Takashi Sakamoto 29aa09acb2 ALSA: oxfw: rename local functions for control elements so that they represent as local
This commit renames local functions with prefix 'spkr_', so that they're
for firewire-speakers.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-15 16:30:03 +01:00
Takashi Sakamoto f3a0e32a6f ALSA: oxfw: rename a file for control elements so that it's for model-specific
In ALSA firewire stack, drivers basically has no control elements. This
is due to the fact that each model has own functionality even if they use
the same communication chipset. Implementing all of the functionalities in
kernel space unreasonably increases our efforts to maintain the stack. In
most case, these functionalities can be implemented in userspace via Linux
fw character devices.

However, ALSA OXFW driver has control elements comes from old
firewire-speakers driver. Adding the elements is in a file names as
'oxfw-control.c', while the elements are really model-specific. The
name is confusing because it gives an idea to handle control elements
for all of OXFW-based models.

This commit renames the file so that it's just for models supported by
old firewire-speakers driver.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-12-15 16:30:02 +01:00
Takashi Sakamoto 4d2c50a0a9 ALSA: fireworks: change type of substream counter from atomic_t to unsigned int
The counter is incremented/decremented in critical section protected with
mutex. Therefore, no need to use atomic_t.

This commit changes the type to unsigned int.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-11-14 17:53:46 +01:00
Takashi Sakamoto ea54a37442 ALSA: fireworks: move mutex from function callees to callers
Currently, critical section is protected by mutex in functions of
fireworks_stream.c. Callers increments/decrements substreams counter
before calling the functions. Moving mutex to the callers code allows
to change type of the substeram counter from atomic_t to unsigned int.

This commit is a preparation for obsoleting usage of atomic_t for
substream counter.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-11-14 17:53:41 +01:00
Takashi Sakamoto 5d5563b14f ALSA: dice: fix detection of Loud devices
Commit a471fcde8c ("ALSA: dice: fix detection of Weiss devices") adds
a quirk of Weiss models. According to users' reports, Loud models also
have the similar quirk. They have 0x10 in the category field.

This commit adds support for Mackie Onyx Blackbird and Onyx-i series.
As long as I know, Dice-based models produced by
Focusrite/Alesis/PreSonus/M-Audio/TC Electronic have default value (0x04)
in their category field, thus it may be reasonable to add a condition
statement for Loud models, instead of removing the check of category value.

Reported-by: Rouge Etienne <erouge.externe@m6.fr>
Reported-by: Etilem <contact@etilem.net>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-11-14 17:50:57 +01:00
Takashi Sakamoto 94d505e974 ALSA: oxfw: add an comment to Kconfig for TASCAM FireOne
A commit to add support for this model should have added a comment
about this model to Kconfig.

Fixes: 759a2f40c9fa('ALSA: oxfw: add an entry for TASCAM FireOne')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-11-08 09:04:36 +01:00
Takashi Sakamoto d1482fb335 ALSA: firewire-digi00x: add another rawmidi character device for MIDI control ports
Digi 002/003 family uses two ways to transfer MIDI messages. They're
different mechanisms, while it's better to handle the ways in different
ALSA rawmidi character devices because one character device has just a
set of operations.

This commit adds another rawmidi character device for control MIDI port. As
a result, first rawmidi character device is just for MIDI messages
transferred by isochronous packets.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-30 19:34:44 +01:00
Takashi Sakamoto c5fcee0373 ALSA: firewire-digi00x: add MIDI operations for MIDI control port
Digi 002/003 family has two types of MIDI port; one is for physical MIDI
port and another is for MIDI control message. The former is transferred in
isochronous packet, and the latter is transferred by asynchronous
transaction. These transmission mechanisms are completely different, while
current ALSA digi00x driver defines a set of operations for them with
several condition statements. As a result, codes for the operation are
messy.

This commit adds a set of MIDI operation for control MIDI ports. In later
commit, it's applied as an operation for ALSA rawmidi character device.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-30 19:34:32 +01:00
Takashi Sakamoto 5918f96220 ALSA: firewire-digi00x: rename identifiers of MIDI operation for physical ports
In following commit, new functions and variables are added for operations
of MIDI control port.

This commit is a preparation. Current identifiers are renamed so that they
mean physical MIDI ports.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-30 19:34:13 +01:00
Takashi Sakamoto f937b43d48 ALSA: firewire-tascam: clear extra MIDI bytes in an asynchronous transaction
When MIDI buffer stores two or more MIDI messages, TASCAM driver
transfers asynchronous transactions including one MIDI message and
extra bytes from second MIDI message.

This commit fixes this bug by clearing needless bytes in the buffer. The
consumed bytes are already calculated correctly, thus the sequence of
transactions is already correct.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-20 17:49:15 +02:00
Takashi Sakamoto 123990e930 ALSA: firewire-tascam: fix loop condition with some readable variables
In transactions for MIDI messages, the first byte is used for label and
the rest is for MIDI bytes. In current code, these are handled correctly,
while there's a small mistake for loop condition to include meaningless
statement.

This commit adds two local variables for them and improve the loop
condition.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-20 17:49:15 +02:00
Takashi Sakamoto b7ab614f30 ALSA: firewire-tascam: use better name for local variables to describe their intension
In the callback function of asynchronous MIDI port, the intension of some
local variables are not clear.

This commit improves them. The 'len' variable is used to calculate the
number of MIDI bytes including in the transaction. The 'consume' variable
is used to return the actual number of consumed bytes in ALSA MIDI buffer.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-20 17:49:14 +02:00
Takashi Sakamoto 516a306156 ALSA: firewire-tascam: change type of valiables according to function prototype
In the callback function of asynchronous MIDI port, some local variables
are declared 'unsigned int', while they're assigned to int value of return
from snd_rawmidi_transmit_peek().

This commit fixes the type.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-20 17:49:14 +02:00
Takashi Sakamoto 9f9c5617c8 ALSA: firewire-tascam: remove buffer initialization in driver side
The given buffer to callback function is cleared in caller side.

This commit removes buffer initialization in callee side.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-20 17:49:13 +02:00
Dan Carpenter 9a30ae2df2 ALSA: firewire-tascam: off by one in identify_model()
Let's leave space for the NUL char otherwise the static checkers
complain that we go beyond the end of the array.

Fixes: 53b3ffee78 ('ALSA: firewire-tascam: change device probing processing')
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>
2015-10-19 14:00:49 +02:00
Takashi Sakamoto 759a2f40c9 ALSA: oxfw: add an entry for TASCAM FireOne
TASCAM FireOne is based on OXFW971 and ALSA OXFW driver can support it.
These are values of identical registers.

$ ./firewire-request /dev/fw1 read 0xfffff0050000
result: 97100105

$ ./firewire-request /dev/fw1 read 0xfffff0090020
result: 39373100

This commit adds an entry for this model. This model has physical controls
and its MIDI control messages are transferred to second MIDI data stream
multiplexed in one MIDI conformant data channel.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-19 12:01:22 +02:00
Takashi Sakamoto bb71da4346 ALSA: oxfw: support more MIDI ports
In IEC 61883-6, sequence multiplexing is applied to MIDI conformant data
channel. As a result, eight MIDI data streams are included in the channel.
Although ALSA AM824 data block processing layer implements this
multiplexing, current OXFW driver doesn't utilize it due to wrong
calculation of MIDI ports.

This commit fixes this bug to add proper calculation. Although this commit
allows to use 8 MIDI data streams, the number of available MIDI ports is
limited by the number of ALSA MIDI ports added by the driver.

Fixes: df075feefbd3('ALSA: firewire-lib: complete AM824 data block processing layer')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-19 12:01:07 +02:00
Takashi Sakamoto 3205604101 ALSA: oxfw: calculating MIDI ports in stream discover
Current OXFW driver calculates the number of MIDI ports just before adding
ALSA MIDI ports. It's convenient for some devices with quirks to move
these codes before handling quirks.

This commit implements this idea.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-19 12:00:47 +02:00
Takashi Sakamoto 56b1c72a75 ALSA: firewire-lib: avoid NULL pointer dereference after closing MIDI port
When asynchronous MIDI port is closed before callbacked, the callback
function causes NULL pointer dereference to missing MIDI substream.

This commit fixes this bug.

Fixes: e8a40d9bcb23('ALSA: firewire-lib: schedule work again when MIDI substream has rest of MIDI messages')
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-10-19 11:58:21 +02:00
Takashi Sakamoto bd04809bbe ALSA: firewire-digi00x/firewire-tascam: remove wrong conversion for Config ROM
The contents of Config ROM in firewire device structure are already
aligned to CPU-endianness. Thus, no need to convert it again.

This commit removes needless conversions

Fixes: 9edf723fd858('ALSA: firewire-digi00x: add skeleton for Digi 002/003 family')
Fixes: c0949b278515('ALSA: firewire-tascam: add skeleton for TASCAM FireWire series')
Reported-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-19 11:57:03 +02:00
Takashi Sakamoto fef586d589 ALSA: bebob: use correct type for __be32 data
In former commit, metering is supported for BeBoB based models
customized by M-Audio. The data in transaction is aligned to
big-endianness, while in the driver code u16 typed variable is assigned
to the data. This causes sparse warnings.

bebob_maudio.c:651:31: warning: cast to restricted __be16
bebob_maudio.c:651:31: warning: cast to restricted __be16
bebob_maudio.c:651:31: warning: cast to restricted __be16
bebob_maudio.c:651:31: warning: cast to restricted __be16

This commit fixes this bug by using __be16 variable for the data.

Fixes: 3149ac489ff8('ALSA: bebob: Add support for M-Audio special Firewire series')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-19 11:57:03 +02:00
Takashi Sakamoto 463543ac2e ALSA: fireworks: use u32 type for be32_to_cpup() macro
In former commit, snd_efw_command_get_phys_meters() was added to handle
metering data. The given buffer is used to save transaction result and to
convert between endianness. But this causes sparse warnings.

fireworks_command.c:269:25: warning: incorrect type in argument 1 (different base types)
fireworks_command.c:269:25:    expected unsigned int [usertype] *p
fireworks_command.c:269:25:    got restricted __be32 [usertype] *

This commit fixes this bug.

Fixes: bde8a8f23bbe('ALSA: fireworks: Add transaction and some commands')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-19 11:57:02 +02:00
Takashi Sakamoto cbc6f28067 ALSA: dice: assign converted data to the same type of variable
In former commit, u32 data was assigned to __be32 variable instead of an
int variable. This is not enough solution because it still causes sparse
warnings.

dice.c:80:23: warning: incorrect type in assignment (different base types)
dice.c:80:23:    expected restricted __be32 [usertype] value
dice.c:80:23:    got unsigned int
dice.c:81:21: warning: restricted __be32 degrades to integer
dice.c:81:46: warning: restricted __be32 degrades to integer

This commit fixes this bug.

Fixes: 7c2d4c0cf5ba('ALSA: dice: Split transaction functionality into a file')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-19 11:57:01 +02:00
Takashi Sakamoto 3e93d42a04 ALSA: dice: correct variable types for __be32 data
Some local variables in some functions are typed as unsigned int, while
__be32 value is assigned to them. This causes sparse warnings.

dice-stream.c:50:17: warning: incorrect type in assignment (different base types)
dice-stream.c:50:17:    expected unsigned int [unsigned] channel
dice-stream.c:50:17:    got restricted __be32 [usertype] <noident>
dice-stream.c:74:17: warning: incorrect type in assignment (different base types)
dice-stream.c:74:17:    expected unsigned int [unsigned] channel
dice-stream.c:74:17:    got restricted __be32 [usertype] <noident>

This commit fixes this bug.

Fixes: 288a8d0cb04f('ALSA: dice: Change the way to start stream')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-19 11:57:01 +02:00
Takashi Sakamoto ad4401e53d ALSA: oxfw: remove a meaningless entry from firewire Makefile
A former commit moves oxfw-related codes to a sub-directory, while it
forgot to remove an entry from Makefile in parent directory.

Fixes: 1a4e39c2e5ca('ALSA: oxfw: Move to its own directory')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-18 09:10:11 +02:00
Takashi Sakamoto df4833886f ALSA: fireworks/bebob/oxfw/dice: enable to make as built-in
When committed to upstream, these four modules had wrong entries for
Makefile. This forces them to be loadable modules even if they're set
as built-in.

This commit fixes this bug.

Fixes: b5b04336015e('ALSA: fireworks: Add skelton for Fireworks based devices')
Fixes: fd6f4b0dc167('ALSA: bebob: Add skelton for BeBoB based devices')
Fixes: 1a4e39c2e5ca('ALSA: oxfw: Move to its own directory')
Fixes: 14ff6a094815('ALSA: dice: Move file to its own directory')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-18 09:08:11 +02:00
Dan Carpenter 724097059a ALSA: firewire-tascam: off by one in handle_midi_tx()
My static checker complains because tscm->spec->midi_capture_ports is
either 2 or 4 but the tscm->tx_midi_substreams[] array has 4 elements so
this is possibly off by one.  I have looked at the code and I think it
should be >= instead of > as well.

Fixes: 107cc0129a ('ALSA: firewire-tascam: add support for incoming MIDI messages by asynchronous transaction')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-17 12:06:28 +02:00
Dan Carpenter 69ec98d7e5 ALSA: firewire-tascam: fix an LED bug
We recently tried to add some new code to support turning the LED on and
off but the code in snd_tscm_transaction_reregister() is unreachable.

Fixes: e65e2cb99e ('ALSA: firewire-tascam: Turn on/off FireWire LED')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-17 12:04:16 +02:00
Takashi Sakamoto 53b3ffee78 ALSA: firewire-tascam: change device probing processing
Currently, this driver picks up model name with be32_to_cpu() macro
to align characters. This is wrong operation because the result is
different depending on CPU endiannness.

Additionally, vendor released several versions of firmware for this
series. It's not better to assign model-dependent information to
device entry according to the version field.

This commit fixes these bugs. The name of model is picked up correctly
and used to identify model-dependent information.

Cc: Stefan Richter <stefanr@s5r6.in-berlin.de>
Fixes: c0949b2785 ('ALSA: firewire-tascam: add skeleton for TASCAM FireWire series')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-12 14:17:02 +02:00
Takashi Sakamoto e65e2cb99e ALSA: firewire-tascam: Turn on/off FireWire LED
TASCAM FireWire series has some LEDs on its surface. These LEDs can be
turned on/off by receiving asynchronous transactions to a certain
address. One of the LEDs is labels as 'FireWire'. It's better to light it
up when this driver starts to work. Besides, the LED for 'FireWire' is
turned off at bus reset.

This commit implements this idea.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-12 14:16:19 +02:00
Takashi Sakamoto 0db18e7eec ALSA: firewire-tascam: add support for MIDI functionality
In former commits, this driver got functionalities to transfer/receive
MIDI messages to/from TASCAM FireWire series.

This commit adds some ALSA MIDI ports to enable userspace applications
to use the functionalities.

I note that this commit doesn't support virtual MIDI ports which console
models support. A physical controls can be assigned to a certain MIDI
ports including physical and virtual. But the way is not clear.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-12 14:16:18 +02:00
Takashi Sakamoto 3beab0f844 ALSA: firewire-tascam: add support for outgoing MIDI messages by asynchronous transaction
TASCAM FireWire series use asynchronous transaction to receive MIDI
messages. The transaction should be sent to a certain address.

This commit supports the outgoing MIDI messages. The messages in the
transaction includes some quirks:
 * One MIDI message is transferred in one quadlet transaction, except for
   system exclusives.
 * MIDI running status is not allowed, thus transactions always include
   status byte.
 * The basic data format is the same as transferring MIDI messages
   supported in previous commit.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-12 14:16:18 +02:00
Takashi Sakamoto 107cc0129a ALSA: firewire-tascam: add support for incoming MIDI messages by asynchronous transaction
TASCAM FireWire series use asynchronous transaction to transfer MIDI
messages. The transaction is sent to a registered address.

This commit supports the incoming MIDI messages. The messages in the
transaction include some quirks:
 * Two quadlets are used for one MIDI message and one timestamp.
 * Usually, the first byte of the first quadlet includes MIDI port and MSB
   4 bit of MIDI status. For system exclusive message, the first byte
   includes MIDI port and 0x04, or 0x07 in the end of the message.
 * The rest of the first quadlet includes MIDI bytes up to 3.
 * Several set of MIDI messages and timestamp can be transferred in one
   block transaction, up to 8 sets.

I note that TASCAM FireWire series ignores ID bytes of system exclusive
message. When receiving system exclusive messages with ID bytes on physical
MIDI bus, the series transfers the messages without ID bytes on IEEE 1394
bus, and vice versa.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-12 14:16:17 +02:00
Takashi Sakamoto e8bd577ae6 ALSA: firewire-digi00x: add support for MIDI ports for physical controls
In former commits, asynchronous transactions are supported for physical
controls. This commit adds a pair of MIDI ports for them.

This driver already adds diferrent number of ALSA MIDI ports for physical
MIDI ports, and the number of in/out ports are different. As seeing as
'amidi' program in alsa-utils package, a pair of in/out MIDI ports is
expected with the same name. Therefore, this commit adds a pair of new
ports to the first.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-11 18:26:21 +02:00
Takashi Sakamoto b47f525f76 ALSA: firewire-digi00x: add support of asynchronous transaction for outgoing MIDI messages to physical controls
In previous commit, asynchronous transaction for incoming MIDI messages
from physical controls is supported. The physical controls may be
controlled by receiving MIDI messages at a certain address.

This commit supports asynchronous transaction for this purpose.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-11 18:26:14 +02:00
Takashi Sakamoto 3646a54acd ALSA: firewire-digi00x: add support of asynchronous transaction for incoming MIDI messages from physical controls
Digi 00x series has two types of model; rack and console. The console
models have physical controls. The model can transmit control messages.
These control messages are transferred by asynchronous transactions to
registered address.

This commit supports the asynchronous transaction.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-11 18:26:09 +02:00
Takashi Sakamoto 9fbfd38b20 ALSA: firewire-digi00x: add support for MIDI ports corresponding to isochronous packet streaming
This commit adds MIDI functionality to capture/playback MIDI messages
from/to physical MIDI ports. These messages are transferred in isochronous
packets.

When no substreams request AMDTP streams to run, this driver starts the
streams at current sampling rate. When other substreams start at different
sampling rate, the streams are stopped temporarily, then start again at
requested sampling rate. This operation can generate missing MIDI bytes,
thus it's preferable to start PCM substreams at favorite sampling rate in
advance.

Digi 002/003 console also has a set of MIDI port for physical controls.
These ports are added in later commits.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-11 18:26:04 +02:00
Takashi Sakamoto 9dc5d31cdc ALSA: firewire-digi00x: handle MIDI messages in isochronous packets
In Digi 002/003 protocol, MIDI messages are transferred in the last data
channel of data blocks. Although this data channel has a label of 0x80,
it's not fully MIDI conformant data channel especially because the Counter
field always zero independently of included MIDI bytes. The 4th byte of
the data channel in LSB tells the number of included MIDI bytes. This byte
also includes the number of MIDI port. Therefore, the data format in this
data channel is:
 * 1st: 0x80 as label
 * 2nd: MIDI bytes
 * 3rd: 0 or MIDI bytes
 * 4th: the number of MIDI byte and the number of MIDI port

This commit adds support of MIDI messages in data block processing layer.

Like AM824 data format, this data channel has a capability to transfer
more MIDI messages than the capability of phisical MIDI bus. Therefore, a
throttle for data rate is  required to prevent devices' internal buffer to
overflow.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-11 18:25:57 +02:00
Takashi Sakamoto 17385a386c ALSA: firewire-digi00x: use in-kernel representation for the type of 8 bits
Original code for 'DoubleOhThree' encoding was written with '__u8' type,
while the type is usually used to export something to userspace.

This commit replaces the type with 'u8'.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-11 18:25:46 +02:00
Takashi Sakamoto 2a7e1713cd ALSA: firewire-lib: continue packet processing at detecting wrong CIP headers
In firewire-lib, isochronous packet streaming is stopped when detecting
wrong value for FMT field of CIP headers. Although this is appropriate
to IEC 61883-1 and 6, some BeBoB based devices with vendors' customization
use invalid value to FMT field of CIP headers in the beginning of
streaming.

$ journalctl
  snd-bebob fw1.0: Detect unexpected protocol: 01000000 8000ffff

I got this log with M-Audio FireWire 1814. In this line, the value of FMT
field is 0x00, while it should be 0x10 in usual AMDTP.

Except for the beginning, these devices continue to transfer packets with
valid value for FMT field, except for the beginning. Therefore, in this
case, firewire-lib should continue to process packets. The former
implementation of firewire-lib performs it.

This commit loosens the handling of wrong value, to continue packet
processing in the case.

Fixes: 414ba022a5 ('ALSA: firewire-lib: add support arbitrary value for fmt/fdf fields in CIP header')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-11 18:14:01 +02:00
Julia Lawall 6b9866c893 ALSA: bebob: constify various snd_bebob structures
The structures of type snd_bebob_clock_spec, snd_bebob_rate_spec,
snd_bebob_meter_spec, and snd_bebob_spec are never modified after they are
initialized.  Make them all const.

Done with the help of Coccinelle.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Tested-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-11 18:12:37 +02:00
Takashi Sakamoto bde3e2880f ALSA: firewire-lib: avoid endless loop to transfer MIDI messages at fatal error
Currently, when asynchronous transactions finish in error state and
retries, work scheduling and work running also continues. This
should be canceled at fatal error because it can cause endless loop.

This commit enables to cancel transferring MIDI messages when transactions
encounter fatal errors. This is achieved by setting error state.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-09 09:57:06 +02:00
Takashi Sakamoto ea848b7b62 ALSA: firewire-lib: add throttle for MIDI data rate
Typically, the target devices have internal buffer to adjust output of
received MIDI messages for MIDI serial bus, while the capacity of the
buffer is limited. IEEE 1394 transactions can transfer more MIDI messages
than MIDI serial bus can. This can cause buffer over flow in device side.

This commit adds throttle to limit MIDI data rate by counting intervals
between two MIDI messages. Usual MIDI messages consists of two or three
bytes. This requires 1.302 to 1.953 mili-seconds interval between these
messages. This commit uses kernel monotonic time service to calculate the
time of next transaction.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-09 09:57:06 +02:00
Takashi Sakamoto e8a40d9bcb ALSA: firewire-lib: schedule work again when MIDI substream has rest of MIDI messages
Currently, when two MIDI trigger callbacks can be called immediately,
transactions for the second MIDI messages can be postpone till next trigger
callback. This is not good for real-time message transmission.

This commit schedules work again at response handling callback if the
MIDI substream still includes untransferred MIDI messages.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-09 09:57:05 +02:00
Takashi Sakamoto d3ef9cb93a ALSA: firewire-lib: add a restriction for a transaction at once
Currently, when waiting for a response, callers can start another
transaction by scheduling another work. This is not good for error
processing of transaction, especially the first response is too late.

This commit serialize request/response transactions, by adding one
boolean member to represent idling state.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-09 09:57:05 +02:00
Takashi Sakamoto 585d7cba5e ALSA: firewire-lib: add helper functions for asynchronous transactions to transfer MIDI messages
Some models receive MIDI messages via IEEE 1394 asynchronous transactions.
In this case, MIDI messages are transferred in fixed-length payload. It's
nice that firewire-lib module has common helper functions.

This commit implements this idea. Each driver adds
'struct snd_fw_async_midi_port' in its instance structure. In probing,
it should call snd_fw_async_midi_port_init() to initialize the
structure with some parameters such as target address, the length
of payload in a transaction and a pointer for callback function
to fill the payload buffer. At 'struct snd_rawmidi_ops.trigger()'
callback, it should call 'snd_fw_async_midi_port_run()' to start
transactions. Each driver should ensure that the lifetime of MIDI
substream continues till calling 'snd_fw_async_midi_port_finish()'.

The helper functions support retries to transferring MIDI messages when
transmission errors occur. When transactions are successful, the helper
functions call 'snd_rawmidi_transmit_ack()' internally to consume MIDI
bytes in the buffer. Therefore, Each driver is expected to use
'snd_rawmidi_transmit_peek()' to tell the number of bytes to transfer to
return value of 'fill' callback.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-09 09:57:04 +02:00
Takashi Sakamoto 425a570e1b ALSA: bebob: support Firewire I/O card of Mackie Onyx 1220/1620/1640
Current ALSA BeBoB drivers has an entry for this model, while the value of
vendor ID seems to be wrong according to an user's report.

The vendor had released no updated firmware, thus we can judge that this
model had not changed the content of its config ROM. It's reasonable to fix
the ID according to the report.

$ ./linux-firewire-utils/src/crpp < /sys/bus/firewire/devices/fw1/config_rom

               ROM header and bus information block
               -----------------------------------------------------------------
400  0425720f  bus_info_length 4, crc_length 37, crc 29199
404  31333934  bus_name "1394"
408  f0646122  irmc 1, cmc 1, isc 1, bmc 1, pmc 0, cyc_clk_acc 100,
               max_rec 6 (128), max_rom 1, gen 2, spd 2 (S400)
40c  00000ff2  company_id 00000f     |
410  00004697  device_id f200004697  | EUI-64 00000ff200004697

               root directory
               -----------------------------------------------------------------
414  000859be  directory_length 8, crc 22974
418  04000082  hardware version
41c  0c0083c0  node capabilities per IEEE 1394
420  03000ff2  vendor
424  8100000a  --> descriptor leaf at 44c
428  17010065  model
42c  8100000d  --> descriptor leaf at 460
430  13000910  version
434  d1000001  --> unit directory at 438

               unit directory at 438
               -----------------------------------------------------------------
438  0004ccec  directory_length 4, crc 52460
43c  1200a02d  specifier id: 1394 TA
440  13010001  version: AV/C
444  17010065  model
448  8100000d  --> descriptor leaf at 47c

               descriptor leaf at 44c
               -----------------------------------------------------------------
44c  0004152a  leaf_length 4, crc 5418
450  00000000  textual descriptor
454  00000000  minimal ASCII
458  4d61636b  "Mack"
45c  69650000  "ie"

               descriptor leaf at 460
               -----------------------------------------------------------------
460  000612b5  leaf_length 6, crc 4789
464  00000000  textual descriptor
468  00000000  minimal ASCII
46c  4f6e7978  "Onyx"
470  20466972  " Fir"
474  65776972  "ewir"
478  65000000  "e"

               descriptor leaf at 47c
               -----------------------------------------------------------------
47c  000612b5  leaf_length 6, crc 4789
480  00000000  textual descriptor
484  00000000  minimal ASCII
488  4f6e7978  "Onyx"
48c  20466972  " Fir"
490  65776972  "ewir"
494  65000000  "e"

$ cat /proc/asound/card3/firewire/firmware
Manufacturer:   bridgeCo
Protocol Ver:   1
Build Ver:      0
GUID:           0x00000FF200004697
Model ID:       0x82
Model Rev:      1
Firmware Date:  20040430
Firmware Time:  131527
Firmware ID:    0x10065
Firmware Ver:   2320
Base Addr:      0x20080000
Max Size:       1572864
Loader Date:    20040430
Loader Time:    112036

Reported-by: Andrzej Gansiniec <andrzej@gansiniec.pl>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-04 17:21:34 +02:00
Takashi Sakamoto e5e0c3dd25 ALSA: firewire-tascam: add hwdep interface
This commit adds hwdep interface so as the other IEEE 1394 sound devices
has.

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-10-02 18:17:04 +02:00
Takashi Sakamoto e453df44f0 ALSA: firewire-tascam: add PCM functionality
This commit adds PCM functionality to transmit/receive PCM samples.

When one of PCM substreams are 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-10-02 18:17:03 +02:00
Takashi Sakamoto 35efa5c489 ALSA: firewire-tascam: add streaming functionality
This commit adds streaming functionality for both direction. To utilize
the sequence of the number of data blocks in packets, full duplex with
synchronization is applied.

Besides, TASCAM FireWire series allows drivers to decide which PCM data
channels are enabled. For convenience, this driver always enable whole the
data channels.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-02 18:17:02 +02:00
Takashi Sakamoto 47faeea25e ALSA: firewire-tascam: add data block processing layer
TASCAM FireWire series uses non-blocking transmission for AMDTP packet
streaming, while the format of data blocks is unique.

The CIP headers includes specific value in FMT field and no SYT
information.

In transmitted packets, the first data channel represents event counter,
and the last data channel has status and control information. The rest
has 24bit PCM samples with right padding.

In received packets, all of data channels include 16, 24, 32bit PCM
samples. There's no other kind of information.

This commit adds support for this protocol. For convenience, the size of
PCM samples in outgoing packet is limited by 16 and 24bit. The status and
control information will be supported in future commits.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-02 18:17:01 +02:00
Takashi Sakamoto 96e5fbb0dd ALSA: firewire-tascam: add proc node to show firmware information
TASCAM FireWire series has certain registers for firmware information.

This commit adds proc node to show the information.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-02 18:17:01 +02:00
Takashi Sakamoto 6f81ba19ac ALSA: firewire-tascam: add a structure for model-dependent parameters.
TASCAM FireWire series doesn't tell drivers their capabilities, thus
the drivers should have model-dependent parameters and apply it to
detected devices.

This commit adds a structure to represent such parameters.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-02 18:17:00 +02:00
Takashi Sakamoto c0949b2785 ALSA: firewire-tascam: add skeleton for TASCAM FireWire series
This commit adds a new driver for TASCAM FireWire series. In this commit,
this driver just creates/removes card instance according to bus event.
More functionalities will be added in following commits.

TASCAM FireWire series consists of:
 * PDI 1394P23 for IEEE 1394 PHY layer
 * PDI 1394L40 for IEEE 1394 LINK layer and IEC 61883 interface
 * XILINX XC9536XL
 * XILINX Spartan-II XC2S100
 * ATMEL AT91M42800A

Ilya Zimnovich had investigated TASCAM FireWire series in 2011, and
discover some features of his FW-1804. You can see a part of his research
in FFADO project.
http://subversion.ffado.org/wiki/Tascam

A part of my work are based on Ilya's investigation, while this series
doesn't support the FW-1804, because of a lack of config ROM
information and its protocol detail, especially for PCM channels.

I observed that FW-1884 and FW-1082 don't work properly with 1394 OHCI
controller based on VT6315. The controller can actually communicate packets
to these models, while these models generate no sounds. It may be due to
the PHY/LINK layer issues. Using 1394 OHCI controller produced by the other
vendors such as Texas Instruments may work. Or adding another node on the
bus.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-02 18:16:59 +02:00
Takashi Sakamoto 44b7308871 ALSA: firewire-digi00x: add support for asynchronous messaging
Digi 002/003 family uses asynchronous transaction for messaging.
The address to transmit this message is stored on a certain register.

This commit allocates a range of address on OHCI 1394 host controller
to handle the messaging. As long as I know, the purpose of this message
seems to notify lost of synchronization. While, the meaning of content
of the message is not clear.

Actual examples of this messaging:
 * When clock source is set as internal:
 - 0x00007051
 - 0x00007052
 - 0x00007054
 - 0x00007057
 - 0x00007058
 * When clock source is set as somewhat external:
 - 0x00009000
 - 0x00009010
 - 0x00009020
 - 0x00009021
 - 0x00009022

The lost often occurs when using internal clock source. In this case,
users hear sounds with quite short gap every several minutes. In fact,
the lost is recovered temporarily.

When using with external clock source, the lost seems not to occur. The
mechanism is not clear yet.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-09-30 15:37:55 +02:00
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