2019-05-29 16:57:59 -07:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2014-04-25 22:45:15 +09:00
|
|
|
|
/*
|
|
|
|
|
* bebob_stream.c - a part of driver for BeBoB based devices
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2013-2014 Takashi Sakamoto
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "./bebob.h"
|
|
|
|
|
|
2021-05-24 12:13:46 +09:00
|
|
|
|
#define READY_TIMEOUT_MS 4000
|
2014-04-25 22:45:15 +09:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* NOTE;
|
|
|
|
|
* For BeBoB streams, Both of input and output CMP connection are important.
|
|
|
|
|
*
|
|
|
|
|
* For most devices, each CMP connection starts to transmit/receive a
|
|
|
|
|
* corresponding stream. But for a few devices, both of CMP connection needs
|
|
|
|
|
* to start transmitting stream. An example is 'M-Audio Firewire 410'.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* 128 is an arbitrary length but it seems to be enough */
|
|
|
|
|
#define FORMAT_MAXIMUM_LENGTH 128
|
|
|
|
|
|
|
|
|
|
const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES] = {
|
|
|
|
|
[0] = 32000,
|
|
|
|
|
[1] = 44100,
|
|
|
|
|
[2] = 48000,
|
|
|
|
|
[3] = 88200,
|
|
|
|
|
[4] = 96000,
|
|
|
|
|
[5] = 176400,
|
|
|
|
|
[6] = 192000,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* See: Table 51: Extended Stream Format Info ‘Sampling Frequency’
|
|
|
|
|
* in Additional AVC commands (Nov 2003, BridgeCo)
|
|
|
|
|
*/
|
|
|
|
|
static const unsigned int bridgeco_freq_table[] = {
|
|
|
|
|
[0] = 0x02,
|
|
|
|
|
[1] = 0x03,
|
|
|
|
|
[2] = 0x04,
|
|
|
|
|
[3] = 0x0a,
|
|
|
|
|
[4] = 0x05,
|
|
|
|
|
[5] = 0x06,
|
|
|
|
|
[6] = 0x07,
|
|
|
|
|
};
|
|
|
|
|
|
2016-01-25 19:30:23 -02:00
|
|
|
|
static int
|
|
|
|
|
get_formation_index(unsigned int rate, unsigned int *index)
|
2014-04-25 22:45:15 +09:00
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(snd_bebob_rate_table); i++) {
|
2016-01-25 19:30:23 -02:00
|
|
|
|
if (snd_bebob_rate_table[i] == rate) {
|
|
|
|
|
*index = i;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2014-04-25 22:45:15 +09:00
|
|
|
|
}
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *curr_rate)
|
|
|
|
|
{
|
|
|
|
|
unsigned int tx_rate, rx_rate, trials;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
trials = 0;
|
|
|
|
|
do {
|
|
|
|
|
err = avc_general_get_sig_fmt(bebob->unit, &tx_rate,
|
|
|
|
|
AVC_GENERAL_PLUG_DIR_OUT, 0);
|
|
|
|
|
} while (err == -EAGAIN && ++trials < 3);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
trials = 0;
|
|
|
|
|
do {
|
|
|
|
|
err = avc_general_get_sig_fmt(bebob->unit, &rx_rate,
|
|
|
|
|
AVC_GENERAL_PLUG_DIR_IN, 0);
|
|
|
|
|
} while (err == -EAGAIN && ++trials < 3);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
*curr_rate = rx_rate;
|
|
|
|
|
if (rx_rate == tx_rate)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
/* synchronize receive stream rate to transmit stream rate */
|
|
|
|
|
err = avc_general_set_sig_fmt(bebob->unit, rx_rate,
|
|
|
|
|
AVC_GENERAL_PLUG_DIR_IN, 0);
|
|
|
|
|
end:
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
err = avc_general_set_sig_fmt(bebob->unit, rate,
|
|
|
|
|
AVC_GENERAL_PLUG_DIR_OUT, 0);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
err = avc_general_set_sig_fmt(bebob->unit, rate,
|
|
|
|
|
AVC_GENERAL_PLUG_DIR_IN, 0);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Some devices need a bit time for transition.
|
|
|
|
|
* 300msec is got by some experiments.
|
|
|
|
|
*/
|
|
|
|
|
msleep(300);
|
|
|
|
|
end:
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-14 12:49:30 +09:00
|
|
|
|
int snd_bebob_stream_get_clock_src(struct snd_bebob *bebob,
|
|
|
|
|
enum snd_bebob_clock_type *src)
|
2014-04-25 22:45:15 +09:00
|
|
|
|
{
|
2015-10-11 08:10:55 +02:00
|
|
|
|
const struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
u8 addr[AVC_BRIDGECO_ADDR_BYTES], input[7];
|
2014-04-25 22:45:21 +09:00
|
|
|
|
unsigned int id;
|
ALSA: bebob: improve signal mode detection for clock source
With BeBoB version 3, current ALSA BeBoB driver detects the type of
current clock signal source wrongly. This is due to a lack of proper
implementation to parse the information.
This commit renews the parser. As a result, this driver detects
SYT-Match clock signal, thus it can start streams with two modes;
SYT-Match mode and the others. SYT-Match mode will be supported in future
commits.
There's a constrain about detected internal/external clock source.
When detecting external clock source, this driver allows userspace
applications to use current sampling rate only. This is due to consider
abour synchronization to external clock sources such as S/PDIF, ADAT or
word-clock.
According to several information from some devices, I guesss that the
internal clock of most devices synchronize to IEEE 1394 cycle start
packet. In this case, by a usual way, it's detect as 'Sync type
of output Music Sub-Unit' connected to 'Sync type of PCR output Unit
(oPCR)', and this driver judges it as internal clock. Therefore,
userspace applications is allowed to request arbitrary supported sampling
rates.
On the other hand, several devices based on BeBoB version 3 have
additional internal clock. In this case, by a usual way, it's detect as
'Sync/Additional type of External input Unit'. Unfortunately, there's no
way to distinguish this sync type from the other external clock sources
such as word-clock. In this case, this driver handles it as external and
userspace applications is forced to use current sampling rate.
I note that when the source of clock is detected as 'Isochronous stream
type of input PCR[0]', it's under 'SYT-Match' mode. In this mode, the
synchronization clock is generated according to SYT-series in received
packets. In this case, this driver generates the series by myself. I
experienced this mode often make the device silent suddenly during
playbacking. This means that the mode is easy to lost synchronization.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-14 12:49:27 +09:00
|
|
|
|
enum avc_bridgeco_plug_type type;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
int err = 0;
|
|
|
|
|
|
2014-04-25 22:45:21 +09:00
|
|
|
|
/* 1.The device has its own operation to switch source of clock */
|
|
|
|
|
if (clk_spec) {
|
|
|
|
|
err = clk_spec->get(bebob, &id);
|
2014-10-25 13:40:41 +02:00
|
|
|
|
if (err < 0) {
|
2014-04-25 22:45:21 +09:00
|
|
|
|
dev_err(&bebob->unit->device,
|
|
|
|
|
"fail to get clock source: %d\n", err);
|
2014-10-25 13:40:41 +02:00
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id >= clk_spec->num) {
|
|
|
|
|
dev_err(&bebob->unit->device,
|
|
|
|
|
"clock source %d out of range 0..%d\n",
|
|
|
|
|
id, clk_spec->num - 1);
|
|
|
|
|
err = -EIO;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-14 12:49:30 +09:00
|
|
|
|
*src = clk_spec->types[id];
|
2014-04-25 22:45:21 +09:00
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-25 22:45:15 +09:00
|
|
|
|
/*
|
2014-04-25 22:45:21 +09:00
|
|
|
|
* 2.The device don't support to switch source of clock then assumed
|
2014-04-25 22:45:15 +09:00
|
|
|
|
* to use internal clock always
|
|
|
|
|
*/
|
|
|
|
|
if (bebob->sync_input_plug < 0) {
|
2015-06-14 12:49:30 +09:00
|
|
|
|
*src = SND_BEBOB_CLOCK_TYPE_INTERNAL;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2014-04-25 22:45:21 +09:00
|
|
|
|
* 3.The device supports to switch source of clock by an usual way.
|
2014-04-25 22:45:15 +09:00
|
|
|
|
* Let's check input for 'Music Sub Unit Sync Input' plug.
|
|
|
|
|
*/
|
|
|
|
|
avc_bridgeco_fill_msu_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN,
|
|
|
|
|
bebob->sync_input_plug);
|
|
|
|
|
err = avc_bridgeco_get_plug_input(bebob->unit, addr, input);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
dev_err(&bebob->unit->device,
|
|
|
|
|
"fail to get an input for MSU in plug %d: %d\n",
|
|
|
|
|
bebob->sync_input_plug, err);
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If there are no input plugs, all of fields are 0xff.
|
|
|
|
|
* Here check the first field. This field is used for direction.
|
|
|
|
|
*/
|
|
|
|
|
if (input[0] == 0xff) {
|
2015-06-14 12:49:30 +09:00
|
|
|
|
*src = SND_BEBOB_CLOCK_TYPE_INTERNAL;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
ALSA: bebob: improve signal mode detection for clock source
With BeBoB version 3, current ALSA BeBoB driver detects the type of
current clock signal source wrongly. This is due to a lack of proper
implementation to parse the information.
This commit renews the parser. As a result, this driver detects
SYT-Match clock signal, thus it can start streams with two modes;
SYT-Match mode and the others. SYT-Match mode will be supported in future
commits.
There's a constrain about detected internal/external clock source.
When detecting external clock source, this driver allows userspace
applications to use current sampling rate only. This is due to consider
abour synchronization to external clock sources such as S/PDIF, ADAT or
word-clock.
According to several information from some devices, I guesss that the
internal clock of most devices synchronize to IEEE 1394 cycle start
packet. In this case, by a usual way, it's detect as 'Sync type
of output Music Sub-Unit' connected to 'Sync type of PCR output Unit
(oPCR)', and this driver judges it as internal clock. Therefore,
userspace applications is allowed to request arbitrary supported sampling
rates.
On the other hand, several devices based on BeBoB version 3 have
additional internal clock. In this case, by a usual way, it's detect as
'Sync/Additional type of External input Unit'. Unfortunately, there's no
way to distinguish this sync type from the other external clock sources
such as word-clock. In this case, this driver handles it as external and
userspace applications is forced to use current sampling rate.
I note that when the source of clock is detected as 'Isochronous stream
type of input PCR[0]', it's under 'SYT-Match' mode. In this mode, the
synchronization clock is generated according to SYT-series in received
packets. In this case, this driver generates the series by myself. I
experienced this mode often make the device silent suddenly during
playbacking. This means that the mode is easy to lost synchronization.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-14 12:49:27 +09:00
|
|
|
|
/* The source from any output plugs is for one purpose only. */
|
|
|
|
|
if (input[0] == AVC_BRIDGECO_PLUG_DIR_OUT) {
|
|
|
|
|
/*
|
|
|
|
|
* In BeBoB architecture, the source from music subunit may
|
|
|
|
|
* bypass from oPCR[0]. This means that this source gives
|
|
|
|
|
* synchronization to IEEE 1394 cycle start packet.
|
|
|
|
|
*/
|
|
|
|
|
if (input[1] == AVC_BRIDGECO_PLUG_MODE_SUBUNIT &&
|
|
|
|
|
input[2] == 0x0c) {
|
2015-06-14 12:49:30 +09:00
|
|
|
|
*src = SND_BEBOB_CLOCK_TYPE_INTERNAL;
|
ALSA: bebob: improve signal mode detection for clock source
With BeBoB version 3, current ALSA BeBoB driver detects the type of
current clock signal source wrongly. This is due to a lack of proper
implementation to parse the information.
This commit renews the parser. As a result, this driver detects
SYT-Match clock signal, thus it can start streams with two modes;
SYT-Match mode and the others. SYT-Match mode will be supported in future
commits.
There's a constrain about detected internal/external clock source.
When detecting external clock source, this driver allows userspace
applications to use current sampling rate only. This is due to consider
abour synchronization to external clock sources such as S/PDIF, ADAT or
word-clock.
According to several information from some devices, I guesss that the
internal clock of most devices synchronize to IEEE 1394 cycle start
packet. In this case, by a usual way, it's detect as 'Sync type
of output Music Sub-Unit' connected to 'Sync type of PCR output Unit
(oPCR)', and this driver judges it as internal clock. Therefore,
userspace applications is allowed to request arbitrary supported sampling
rates.
On the other hand, several devices based on BeBoB version 3 have
additional internal clock. In this case, by a usual way, it's detect as
'Sync/Additional type of External input Unit'. Unfortunately, there's no
way to distinguish this sync type from the other external clock sources
such as word-clock. In this case, this driver handles it as external and
userspace applications is forced to use current sampling rate.
I note that when the source of clock is detected as 'Isochronous stream
type of input PCR[0]', it's under 'SYT-Match' mode. In this mode, the
synchronization clock is generated according to SYT-series in received
packets. In this case, this driver generates the series by myself. I
experienced this mode often make the device silent suddenly during
playbacking. This means that the mode is easy to lost synchronization.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-14 12:49:27 +09:00
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
/* The source from any input units is for several purposes. */
|
|
|
|
|
} else if (input[1] == AVC_BRIDGECO_PLUG_MODE_UNIT) {
|
|
|
|
|
if (input[2] == AVC_BRIDGECO_PLUG_UNIT_ISOC) {
|
|
|
|
|
if (input[3] == 0x00) {
|
|
|
|
|
/*
|
|
|
|
|
* This source comes from iPCR[0]. This means
|
|
|
|
|
* that presentation timestamp calculated by
|
|
|
|
|
* SYT series of the received packets. In
|
|
|
|
|
* short, this driver is the master of
|
|
|
|
|
* synchronization.
|
|
|
|
|
*/
|
2015-06-14 12:49:30 +09:00
|
|
|
|
*src = SND_BEBOB_CLOCK_TYPE_SYT;
|
ALSA: bebob: improve signal mode detection for clock source
With BeBoB version 3, current ALSA BeBoB driver detects the type of
current clock signal source wrongly. This is due to a lack of proper
implementation to parse the information.
This commit renews the parser. As a result, this driver detects
SYT-Match clock signal, thus it can start streams with two modes;
SYT-Match mode and the others. SYT-Match mode will be supported in future
commits.
There's a constrain about detected internal/external clock source.
When detecting external clock source, this driver allows userspace
applications to use current sampling rate only. This is due to consider
abour synchronization to external clock sources such as S/PDIF, ADAT or
word-clock.
According to several information from some devices, I guesss that the
internal clock of most devices synchronize to IEEE 1394 cycle start
packet. In this case, by a usual way, it's detect as 'Sync type
of output Music Sub-Unit' connected to 'Sync type of PCR output Unit
(oPCR)', and this driver judges it as internal clock. Therefore,
userspace applications is allowed to request arbitrary supported sampling
rates.
On the other hand, several devices based on BeBoB version 3 have
additional internal clock. In this case, by a usual way, it's detect as
'Sync/Additional type of External input Unit'. Unfortunately, there's no
way to distinguish this sync type from the other external clock sources
such as word-clock. In this case, this driver handles it as external and
userspace applications is forced to use current sampling rate.
I note that when the source of clock is detected as 'Isochronous stream
type of input PCR[0]', it's under 'SYT-Match' mode. In this mode, the
synchronization clock is generated according to SYT-series in received
packets. In this case, this driver generates the series by myself. I
experienced this mode often make the device silent suddenly during
playbacking. This means that the mode is easy to lost synchronization.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-14 12:49:27 +09:00
|
|
|
|
goto end;
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* This source comes from iPCR[1-29]. This
|
|
|
|
|
* means that the synchronization stream is not
|
|
|
|
|
* the Audio/MIDI compound stream.
|
|
|
|
|
*/
|
2015-06-14 12:49:30 +09:00
|
|
|
|
*src = SND_BEBOB_CLOCK_TYPE_EXTERNAL;
|
ALSA: bebob: improve signal mode detection for clock source
With BeBoB version 3, current ALSA BeBoB driver detects the type of
current clock signal source wrongly. This is due to a lack of proper
implementation to parse the information.
This commit renews the parser. As a result, this driver detects
SYT-Match clock signal, thus it can start streams with two modes;
SYT-Match mode and the others. SYT-Match mode will be supported in future
commits.
There's a constrain about detected internal/external clock source.
When detecting external clock source, this driver allows userspace
applications to use current sampling rate only. This is due to consider
abour synchronization to external clock sources such as S/PDIF, ADAT or
word-clock.
According to several information from some devices, I guesss that the
internal clock of most devices synchronize to IEEE 1394 cycle start
packet. In this case, by a usual way, it's detect as 'Sync type
of output Music Sub-Unit' connected to 'Sync type of PCR output Unit
(oPCR)', and this driver judges it as internal clock. Therefore,
userspace applications is allowed to request arbitrary supported sampling
rates.
On the other hand, several devices based on BeBoB version 3 have
additional internal clock. In this case, by a usual way, it's detect as
'Sync/Additional type of External input Unit'. Unfortunately, there's no
way to distinguish this sync type from the other external clock sources
such as word-clock. In this case, this driver handles it as external and
userspace applications is forced to use current sampling rate.
I note that when the source of clock is detected as 'Isochronous stream
type of input PCR[0]', it's under 'SYT-Match' mode. In this mode, the
synchronization clock is generated according to SYT-series in received
packets. In this case, this driver generates the series by myself. I
experienced this mode often make the device silent suddenly during
playbacking. This means that the mode is easy to lost synchronization.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-14 12:49:27 +09:00
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
} else if (input[2] == AVC_BRIDGECO_PLUG_UNIT_EXT) {
|
|
|
|
|
/* Check type of this plug. */
|
|
|
|
|
avc_bridgeco_fill_unit_addr(addr,
|
|
|
|
|
AVC_BRIDGECO_PLUG_DIR_IN,
|
|
|
|
|
AVC_BRIDGECO_PLUG_UNIT_EXT,
|
|
|
|
|
input[3]);
|
|
|
|
|
err = avc_bridgeco_get_plug_type(bebob->unit, addr,
|
|
|
|
|
&type);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
if (type == AVC_BRIDGECO_PLUG_TYPE_DIG) {
|
|
|
|
|
/*
|
|
|
|
|
* SPDIF/ADAT or sometimes (not always) word
|
|
|
|
|
* clock.
|
|
|
|
|
*/
|
2015-06-14 12:49:30 +09:00
|
|
|
|
*src = SND_BEBOB_CLOCK_TYPE_EXTERNAL;
|
ALSA: bebob: improve signal mode detection for clock source
With BeBoB version 3, current ALSA BeBoB driver detects the type of
current clock signal source wrongly. This is due to a lack of proper
implementation to parse the information.
This commit renews the parser. As a result, this driver detects
SYT-Match clock signal, thus it can start streams with two modes;
SYT-Match mode and the others. SYT-Match mode will be supported in future
commits.
There's a constrain about detected internal/external clock source.
When detecting external clock source, this driver allows userspace
applications to use current sampling rate only. This is due to consider
abour synchronization to external clock sources such as S/PDIF, ADAT or
word-clock.
According to several information from some devices, I guesss that the
internal clock of most devices synchronize to IEEE 1394 cycle start
packet. In this case, by a usual way, it's detect as 'Sync type
of output Music Sub-Unit' connected to 'Sync type of PCR output Unit
(oPCR)', and this driver judges it as internal clock. Therefore,
userspace applications is allowed to request arbitrary supported sampling
rates.
On the other hand, several devices based on BeBoB version 3 have
additional internal clock. In this case, by a usual way, it's detect as
'Sync/Additional type of External input Unit'. Unfortunately, there's no
way to distinguish this sync type from the other external clock sources
such as word-clock. In this case, this driver handles it as external and
userspace applications is forced to use current sampling rate.
I note that when the source of clock is detected as 'Isochronous stream
type of input PCR[0]', it's under 'SYT-Match' mode. In this mode, the
synchronization clock is generated according to SYT-series in received
packets. In this case, this driver generates the series by myself. I
experienced this mode often make the device silent suddenly during
playbacking. This means that the mode is easy to lost synchronization.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-14 12:49:27 +09:00
|
|
|
|
goto end;
|
|
|
|
|
} else if (type == AVC_BRIDGECO_PLUG_TYPE_SYNC) {
|
|
|
|
|
/* Often word clock. */
|
2015-06-14 12:49:30 +09:00
|
|
|
|
*src = SND_BEBOB_CLOCK_TYPE_EXTERNAL;
|
ALSA: bebob: improve signal mode detection for clock source
With BeBoB version 3, current ALSA BeBoB driver detects the type of
current clock signal source wrongly. This is due to a lack of proper
implementation to parse the information.
This commit renews the parser. As a result, this driver detects
SYT-Match clock signal, thus it can start streams with two modes;
SYT-Match mode and the others. SYT-Match mode will be supported in future
commits.
There's a constrain about detected internal/external clock source.
When detecting external clock source, this driver allows userspace
applications to use current sampling rate only. This is due to consider
abour synchronization to external clock sources such as S/PDIF, ADAT or
word-clock.
According to several information from some devices, I guesss that the
internal clock of most devices synchronize to IEEE 1394 cycle start
packet. In this case, by a usual way, it's detect as 'Sync type
of output Music Sub-Unit' connected to 'Sync type of PCR output Unit
(oPCR)', and this driver judges it as internal clock. Therefore,
userspace applications is allowed to request arbitrary supported sampling
rates.
On the other hand, several devices based on BeBoB version 3 have
additional internal clock. In this case, by a usual way, it's detect as
'Sync/Additional type of External input Unit'. Unfortunately, there's no
way to distinguish this sync type from the other external clock sources
such as word-clock. In this case, this driver handles it as external and
userspace applications is forced to use current sampling rate.
I note that when the source of clock is detected as 'Isochronous stream
type of input PCR[0]', it's under 'SYT-Match' mode. In this mode, the
synchronization clock is generated according to SYT-series in received
packets. In this case, this driver generates the series by myself. I
experienced this mode often make the device silent suddenly during
playbacking. This means that the mode is easy to lost synchronization.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-14 12:49:27 +09:00
|
|
|
|
goto end;
|
|
|
|
|
} else if (type == AVC_BRIDGECO_PLUG_TYPE_ADDITION) {
|
|
|
|
|
/*
|
|
|
|
|
* Not standard.
|
|
|
|
|
* Mostly, additional internal clock.
|
|
|
|
|
*/
|
2015-06-14 12:49:30 +09:00
|
|
|
|
*src = SND_BEBOB_CLOCK_TYPE_INTERNAL;
|
ALSA: bebob: improve signal mode detection for clock source
With BeBoB version 3, current ALSA BeBoB driver detects the type of
current clock signal source wrongly. This is due to a lack of proper
implementation to parse the information.
This commit renews the parser. As a result, this driver detects
SYT-Match clock signal, thus it can start streams with two modes;
SYT-Match mode and the others. SYT-Match mode will be supported in future
commits.
There's a constrain about detected internal/external clock source.
When detecting external clock source, this driver allows userspace
applications to use current sampling rate only. This is due to consider
abour synchronization to external clock sources such as S/PDIF, ADAT or
word-clock.
According to several information from some devices, I guesss that the
internal clock of most devices synchronize to IEEE 1394 cycle start
packet. In this case, by a usual way, it's detect as 'Sync type
of output Music Sub-Unit' connected to 'Sync type of PCR output Unit
(oPCR)', and this driver judges it as internal clock. Therefore,
userspace applications is allowed to request arbitrary supported sampling
rates.
On the other hand, several devices based on BeBoB version 3 have
additional internal clock. In this case, by a usual way, it's detect as
'Sync/Additional type of External input Unit'. Unfortunately, there's no
way to distinguish this sync type from the other external clock sources
such as word-clock. In this case, this driver handles it as external and
userspace applications is forced to use current sampling rate.
I note that when the source of clock is detected as 'Isochronous stream
type of input PCR[0]', it's under 'SYT-Match' mode. In this mode, the
synchronization clock is generated according to SYT-series in received
packets. In this case, this driver generates the series by myself. I
experienced this mode often make the device silent suddenly during
playbacking. This means that the mode is easy to lost synchronization.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-14 12:49:27 +09:00
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Not supported. */
|
|
|
|
|
err = -EIO;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
end:
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-26 12:06:20 +09:00
|
|
|
|
static int map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s)
|
2014-04-25 22:45:15 +09:00
|
|
|
|
{
|
|
|
|
|
unsigned int sec, sections, ch, channels;
|
|
|
|
|
unsigned int pcm, midi, location;
|
|
|
|
|
unsigned int stm_pos, sec_loc, pos;
|
|
|
|
|
u8 *buf, addr[AVC_BRIDGECO_ADDR_BYTES], type;
|
|
|
|
|
enum avc_bridgeco_plug_dir dir;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The length of return value of this command cannot be expected. Here
|
|
|
|
|
* use the maximum length of FCP.
|
|
|
|
|
*/
|
|
|
|
|
buf = kzalloc(256, GFP_KERNEL);
|
|
|
|
|
if (buf == NULL)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
if (s == &bebob->tx_stream)
|
|
|
|
|
dir = AVC_BRIDGECO_PLUG_DIR_OUT;
|
|
|
|
|
else
|
|
|
|
|
dir = AVC_BRIDGECO_PLUG_DIR_IN;
|
|
|
|
|
|
|
|
|
|
avc_bridgeco_fill_unit_addr(addr, dir, AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
|
|
|
|
|
err = avc_bridgeco_get_plug_ch_pos(bebob->unit, addr, buf, 256);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
dev_err(&bebob->unit->device,
|
|
|
|
|
"fail to get channel position for isoc %s plug 0: %d\n",
|
|
|
|
|
(dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" : "out",
|
|
|
|
|
err);
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
|
|
/* positions in I/O buffer */
|
|
|
|
|
pcm = 0;
|
|
|
|
|
midi = 0;
|
|
|
|
|
|
|
|
|
|
/* the number of sections in AMDTP packet */
|
|
|
|
|
sections = buf[pos++];
|
|
|
|
|
|
|
|
|
|
for (sec = 0; sec < sections; sec++) {
|
|
|
|
|
/* type of this section */
|
|
|
|
|
avc_bridgeco_fill_unit_addr(addr, dir,
|
|
|
|
|
AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
|
|
|
|
|
err = avc_bridgeco_get_plug_section_type(bebob->unit, addr,
|
|
|
|
|
sec, &type);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
dev_err(&bebob->unit->device,
|
|
|
|
|
"fail to get section type for isoc %s plug 0: %d\n",
|
|
|
|
|
(dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" :
|
|
|
|
|
"out",
|
|
|
|
|
err);
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
/* NoType */
|
|
|
|
|
if (type == 0xff) {
|
|
|
|
|
err = -ENOSYS;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* the number of channels in this section */
|
|
|
|
|
channels = buf[pos++];
|
|
|
|
|
|
|
|
|
|
for (ch = 0; ch < channels; ch++) {
|
|
|
|
|
/* position of this channel in AMDTP packet */
|
|
|
|
|
stm_pos = buf[pos++] - 1;
|
|
|
|
|
/* location of this channel in this section */
|
|
|
|
|
sec_loc = buf[pos++] - 1;
|
|
|
|
|
|
2014-04-25 22:45:25 +09:00
|
|
|
|
/*
|
|
|
|
|
* Basically the number of location is within the
|
|
|
|
|
* number of channels in this section. But some models
|
|
|
|
|
* of M-Audio don't follow this. Its location for MIDI
|
|
|
|
|
* is the position of MIDI channels in AMDTP packet.
|
|
|
|
|
*/
|
|
|
|
|
if (sec_loc >= channels)
|
|
|
|
|
sec_loc = ch;
|
|
|
|
|
|
2014-04-25 22:45:15 +09:00
|
|
|
|
switch (type) {
|
|
|
|
|
/* for MIDI conformant data channel */
|
|
|
|
|
case 0x0a:
|
|
|
|
|
/* AMDTP_MAX_CHANNELS_FOR_MIDI is 1. */
|
|
|
|
|
if ((midi > 0) && (stm_pos != midi)) {
|
|
|
|
|
err = -ENOSYS;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
2015-09-19 11:21:58 +09:00
|
|
|
|
amdtp_am824_set_midi_position(s, stm_pos);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
midi = stm_pos;
|
|
|
|
|
break;
|
|
|
|
|
/* for PCM data channel */
|
|
|
|
|
case 0x01: /* Headphone */
|
|
|
|
|
case 0x02: /* Microphone */
|
|
|
|
|
case 0x03: /* Line */
|
|
|
|
|
case 0x04: /* SPDIF */
|
|
|
|
|
case 0x05: /* ADAT */
|
|
|
|
|
case 0x06: /* TDIF */
|
|
|
|
|
case 0x07: /* MADI */
|
|
|
|
|
/* for undefined/changeable signal */
|
|
|
|
|
case 0x08: /* Analog */
|
|
|
|
|
case 0x09: /* Digital */
|
|
|
|
|
default:
|
|
|
|
|
location = pcm + sec_loc;
|
2015-09-19 11:22:01 +09:00
|
|
|
|
if (location >= AM824_MAX_CHANNELS_FOR_PCM) {
|
2014-04-25 22:45:15 +09:00
|
|
|
|
err = -ENOSYS;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
2015-09-19 11:21:58 +09:00
|
|
|
|
amdtp_am824_set_pcm_position(s, location,
|
|
|
|
|
stm_pos);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type != 0x0a)
|
|
|
|
|
pcm += channels;
|
|
|
|
|
else
|
|
|
|
|
midi += channels;
|
|
|
|
|
}
|
|
|
|
|
end:
|
|
|
|
|
kfree(buf);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
check_connection_used_by_others(struct snd_bebob *bebob, struct amdtp_stream *s)
|
|
|
|
|
{
|
|
|
|
|
struct cmp_connection *conn;
|
|
|
|
|
bool used;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if (s == &bebob->tx_stream)
|
|
|
|
|
conn = &bebob->out_conn;
|
|
|
|
|
else
|
|
|
|
|
conn = &bebob->in_conn;
|
|
|
|
|
|
|
|
|
|
err = cmp_connection_check_used(conn, &used);
|
|
|
|
|
if ((err >= 0) && used && !amdtp_stream_running(s)) {
|
|
|
|
|
dev_err(&bebob->unit->device,
|
|
|
|
|
"Connection established by others: %cPCR[%d]\n",
|
|
|
|
|
(conn->direction == CMP_OUTPUT) ? 'o' : 'i',
|
|
|
|
|
conn->pcr_index);
|
|
|
|
|
err = -EBUSY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-01 22:13:21 +09:00
|
|
|
|
static void break_both_connections(struct snd_bebob *bebob)
|
2014-04-25 22:45:15 +09:00
|
|
|
|
{
|
|
|
|
|
cmp_connection_break(&bebob->in_conn);
|
|
|
|
|
cmp_connection_break(&bebob->out_conn);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-01 22:13:23 +09:00
|
|
|
|
static int start_stream(struct snd_bebob *bebob, struct amdtp_stream *stream)
|
2014-04-25 22:45:15 +09:00
|
|
|
|
{
|
|
|
|
|
struct cmp_connection *conn;
|
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
|
|
if (stream == &bebob->rx_stream)
|
|
|
|
|
conn = &bebob->in_conn;
|
|
|
|
|
else
|
|
|
|
|
conn = &bebob->out_conn;
|
|
|
|
|
|
2019-11-01 22:13:23 +09:00
|
|
|
|
// channel mapping.
|
2014-04-25 22:45:26 +09:00
|
|
|
|
if (bebob->maudio_special_quirk == NULL) {
|
|
|
|
|
err = map_data_channels(bebob, stream);
|
|
|
|
|
if (err < 0)
|
2019-11-01 22:13:23 +09:00
|
|
|
|
return err;
|
2014-04-25 22:45:26 +09:00
|
|
|
|
}
|
2014-04-25 22:45:15 +09:00
|
|
|
|
|
2019-11-01 22:13:23 +09:00
|
|
|
|
err = cmp_connection_establish(conn);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
return amdtp_domain_add_stream(&bebob->domain, stream,
|
|
|
|
|
conn->resources.channel, conn->speed);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 17:44:07 +09:00
|
|
|
|
static int init_stream(struct snd_bebob *bebob, struct amdtp_stream *stream)
|
2014-04-25 22:45:15 +09:00
|
|
|
|
{
|
2021-06-11 12:50:03 +09:00
|
|
|
|
unsigned int flags = CIP_BLOCKING;
|
2019-06-12 17:44:07 +09:00
|
|
|
|
enum amdtp_stream_direction dir_stream;
|
|
|
|
|
struct cmp_connection *conn;
|
|
|
|
|
enum cmp_direction dir_conn;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
int err;
|
|
|
|
|
|
2019-06-12 17:44:07 +09:00
|
|
|
|
if (stream == &bebob->tx_stream) {
|
|
|
|
|
dir_stream = AMDTP_IN_STREAM;
|
|
|
|
|
conn = &bebob->out_conn;
|
|
|
|
|
dir_conn = CMP_OUTPUT;
|
|
|
|
|
} else {
|
|
|
|
|
dir_stream = AMDTP_OUT_STREAM;
|
|
|
|
|
conn = &bebob->in_conn;
|
|
|
|
|
dir_conn = CMP_INPUT;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-11 12:50:03 +09:00
|
|
|
|
if (stream == &bebob->tx_stream) {
|
|
|
|
|
if (bebob->quirks & SND_BEBOB_QUIRK_WRONG_DBC)
|
|
|
|
|
flags |= CIP_EMPTY_HAS_WRONG_DBC;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 17:44:07 +09:00
|
|
|
|
err = cmp_connection_init(conn, bebob->unit, dir_conn, 0);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
if (err < 0)
|
2019-06-12 17:44:07 +09:00
|
|
|
|
return err;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
|
2021-06-11 12:50:03 +09:00
|
|
|
|
err = amdtp_am824_init(stream, bebob->unit, dir_stream, flags);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
if (err < 0) {
|
2019-06-12 17:44:07 +09:00
|
|
|
|
cmp_connection_destroy(conn);
|
|
|
|
|
return err;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
}
|
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 16:18:56 +09:00
|
|
|
|
|
2019-06-12 17:44:07 +09:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void destroy_stream(struct snd_bebob *bebob, struct amdtp_stream *stream)
|
|
|
|
|
{
|
|
|
|
|
amdtp_stream_destroy(stream);
|
|
|
|
|
|
|
|
|
|
if (stream == &bebob->tx_stream)
|
|
|
|
|
cmp_connection_destroy(&bebob->out_conn);
|
|
|
|
|
else
|
|
|
|
|
cmp_connection_destroy(&bebob->in_conn);
|
|
|
|
|
}
|
2014-04-25 22:45:15 +09:00
|
|
|
|
|
2019-06-12 17:44:07 +09:00
|
|
|
|
int snd_bebob_stream_init_duplex(struct snd_bebob *bebob)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
err = init_stream(bebob, &bebob->tx_stream);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
err = init_stream(bebob, &bebob->rx_stream);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
if (err < 0) {
|
2019-06-12 17:44:07 +09:00
|
|
|
|
destroy_stream(bebob, &bebob->tx_stream);
|
|
|
|
|
return err;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
}
|
2019-06-12 17:44:07 +09:00
|
|
|
|
|
2019-08-04 15:21:30 +09:00
|
|
|
|
err = amdtp_domain_init(&bebob->domain);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
destroy_stream(bebob, &bebob->tx_stream);
|
|
|
|
|
destroy_stream(bebob, &bebob->rx_stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 17:44:04 +09:00
|
|
|
|
static int keep_resources(struct snd_bebob *bebob, struct amdtp_stream *stream,
|
|
|
|
|
unsigned int rate, unsigned int index)
|
2014-04-25 22:45:15 +09:00
|
|
|
|
{
|
2021-03-21 12:28:31 +09:00
|
|
|
|
unsigned int pcm_channels;
|
|
|
|
|
unsigned int midi_ports;
|
2019-06-15 18:11:01 +09:00
|
|
|
|
struct cmp_connection *conn;
|
|
|
|
|
int err;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
|
2019-06-15 18:11:01 +09:00
|
|
|
|
if (stream == &bebob->tx_stream) {
|
2021-03-21 12:28:31 +09:00
|
|
|
|
pcm_channels = bebob->tx_stream_formations[index].pcm;
|
|
|
|
|
midi_ports = bebob->midi_input_ports;
|
2019-06-15 18:11:01 +09:00
|
|
|
|
conn = &bebob->out_conn;
|
|
|
|
|
} else {
|
2021-03-21 12:28:31 +09:00
|
|
|
|
pcm_channels = bebob->rx_stream_formations[index].pcm;
|
|
|
|
|
midi_ports = bebob->midi_output_ports;
|
2019-06-15 18:11:01 +09:00
|
|
|
|
conn = &bebob->in_conn;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-21 12:28:31 +09:00
|
|
|
|
err = amdtp_am824_set_parameters(stream, rate, pcm_channels, midi_ports, false);
|
2019-06-15 18:11:01 +09:00
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
|
2019-06-15 18:11:01 +09:00
|
|
|
|
return cmp_connection_reserve(conn, amdtp_stream_get_max_payload(stream));
|
2019-06-12 17:44:04 +09:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 20:05:17 +09:00
|
|
|
|
int snd_bebob_stream_reserve_duplex(struct snd_bebob *bebob, unsigned int rate,
|
2019-10-18 00:54:14 +09:00
|
|
|
|
unsigned int frames_per_period,
|
|
|
|
|
unsigned int frames_per_buffer)
|
2019-06-12 17:44:04 +09:00
|
|
|
|
{
|
|
|
|
|
unsigned int curr_rate;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
// Considering JACK/FFADO streaming:
|
|
|
|
|
// TODO: This can be removed hwdep functionality becomes popular.
|
2016-05-09 23:15:50 +09:00
|
|
|
|
err = check_connection_used_by_others(bebob, &bebob->rx_stream);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
if (err < 0)
|
2019-06-12 17:44:04 +09:00
|
|
|
|
return err;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
|
2019-06-12 17:44:04 +09:00
|
|
|
|
err = bebob->spec->rate->get(bebob, &curr_rate);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
if (rate == 0)
|
|
|
|
|
rate = curr_rate;
|
|
|
|
|
if (curr_rate != rate) {
|
2019-08-04 15:21:30 +09:00
|
|
|
|
amdtp_domain_stop(&bebob->domain);
|
2014-04-25 22:45:16 +09:00
|
|
|
|
break_both_connections(bebob);
|
2019-06-18 22:26:20 +09:00
|
|
|
|
|
|
|
|
|
cmp_connection_release(&bebob->out_conn);
|
|
|
|
|
cmp_connection_release(&bebob->in_conn);
|
2019-06-12 17:44:04 +09:00
|
|
|
|
}
|
2014-04-25 22:45:15 +09:00
|
|
|
|
|
2019-06-12 17:44:04 +09:00
|
|
|
|
if (bebob->substreams_counter == 0 || curr_rate != rate) {
|
|
|
|
|
unsigned int index;
|
|
|
|
|
|
|
|
|
|
// NOTE:
|
|
|
|
|
// If establishing connections at first, Yamaha GO46
|
|
|
|
|
// (and maybe Terratec X24) don't generate sound.
|
|
|
|
|
//
|
|
|
|
|
// For firmware customized by M-Audio, refer to next NOTE.
|
|
|
|
|
err = bebob->spec->rate->set(bebob, rate);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
dev_err(&bebob->unit->device,
|
|
|
|
|
"fail to set sampling rate: %d\n",
|
|
|
|
|
err);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = get_formation_index(rate, &index);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
err = keep_resources(bebob, &bebob->tx_stream, rate, index);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
err = keep_resources(bebob, &bebob->rx_stream, rate, index);
|
2019-06-15 18:11:01 +09:00
|
|
|
|
if (err < 0) {
|
|
|
|
|
cmp_connection_release(&bebob->out_conn);
|
2019-06-12 17:44:04 +09:00
|
|
|
|
return err;
|
2019-06-15 18:11:01 +09:00
|
|
|
|
}
|
2019-10-07 20:05:17 +09:00
|
|
|
|
|
|
|
|
|
err = amdtp_domain_set_events_per_period(&bebob->domain,
|
2019-10-18 00:54:14 +09:00
|
|
|
|
frames_per_period, frames_per_buffer);
|
2019-10-07 20:05:17 +09:00
|
|
|
|
if (err < 0) {
|
|
|
|
|
cmp_connection_release(&bebob->out_conn);
|
|
|
|
|
cmp_connection_release(&bebob->in_conn);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2014-04-25 22:45:15 +09:00
|
|
|
|
}
|
2019-06-12 17:44:04 +09:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int snd_bebob_stream_start_duplex(struct snd_bebob *bebob)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
// Need no substreams.
|
|
|
|
|
if (bebob->substreams_counter == 0)
|
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
|
|
// packet queueing error or detecting discontinuity
|
|
|
|
|
if (amdtp_streaming_error(&bebob->rx_stream) ||
|
|
|
|
|
amdtp_streaming_error(&bebob->tx_stream)) {
|
2019-08-04 15:21:30 +09:00
|
|
|
|
amdtp_domain_stop(&bebob->domain);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
break_both_connections(bebob);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-09 23:15:50 +09:00
|
|
|
|
if (!amdtp_stream_running(&bebob->rx_stream)) {
|
2019-11-01 22:13:23 +09:00
|
|
|
|
enum snd_bebob_clock_type src;
|
2019-06-12 17:44:04 +09:00
|
|
|
|
unsigned int curr_rate;
|
2021-05-20 13:01:51 +09:00
|
|
|
|
unsigned int tx_init_skip_cycles;
|
2019-06-12 17:44:04 +09:00
|
|
|
|
|
|
|
|
|
if (bebob->maudio_special_quirk) {
|
|
|
|
|
err = bebob->spec->rate->get(bebob, &curr_rate);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-01 22:13:23 +09:00
|
|
|
|
err = snd_bebob_stream_get_clock_src(bebob, &src);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
if (err < 0)
|
2019-06-12 17:44:04 +09:00
|
|
|
|
return err;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
|
2021-05-24 12:13:45 +09:00
|
|
|
|
err = start_stream(bebob, &bebob->rx_stream);
|
2019-08-04 15:21:30 +09:00
|
|
|
|
if (err < 0)
|
|
|
|
|
goto error;
|
|
|
|
|
|
2021-05-24 12:13:45 +09:00
|
|
|
|
err = start_stream(bebob, &bebob->tx_stream);
|
2019-08-04 15:21:30 +09:00
|
|
|
|
if (err < 0)
|
|
|
|
|
goto error;
|
|
|
|
|
|
2021-06-11 12:50:03 +09:00
|
|
|
|
if (!(bebob->quirks & SND_BEBOB_QUIRK_INITIAL_DISCONTINUOUS_DBC))
|
2021-05-24 12:13:46 +09:00
|
|
|
|
tx_init_skip_cycles = 0;
|
2019-11-01 22:13:22 +09:00
|
|
|
|
else
|
2021-05-20 13:01:51 +09:00
|
|
|
|
tx_init_skip_cycles = 16000;
|
2021-05-24 12:13:46 +09:00
|
|
|
|
|
ALSA: bebob: perform sequence replay for media clock recovery
This commit takes ALSA bebob driver to perform sequence replay for media
clock recovery.
Many users have reported discontinuity of data block counter field of CIP
header in tx packet from the devices based on BeBoB ASICs. In the worst
case, the device corrupts not to respond to any transaction, then generate
bus-reset voluntarily for recovery. The sequence replay for media clock
recovery is expected to suppress most of the problems.
In the beginning of packet streaming, the device transfers NODATA packets
for a while, then multiplexes any event and syt information. ALSA
IEC 61883-1/6 packet streaming engine has implementation for it to drop
the initial NODATA packets. It starts sequence replay when detecting any
event multiplexed to tx packets.
The sequence replay is tested with below models:
* Focusrite Saffire
* Focusrite Saffire LE
* Focusrite Saffire Pro 10 I/O
* Focusrite Saffire Pro 26 I/O
* M-Audio FireWire Solo
* M-Audio FireWire Audiophile
* M-Audio Ozonic
* M-Audio FireWire 410
* M-Audio FireWire 1814
* Edirol FA-66
* ESI Quatafire 610
* Apogee Ensemble
* Phonic Firefly 202
* Behringer F-Control Audio 610
Unfortunately, below models doesn't generate sound. This seems regression
introduced recent few years:
* Stanton Final Scratch ScratchAmp at middle sampling transfer frequency
* Yamaha GO44
* Yamaha GO46
* Terratec Phase x24
As I reported, below model has quirk of discontinuity:
* M-Audio ProFire Lightbridge
DM1000/DM1100 ASICs in BeBoB solution are known to have bugs at switch of
sampling transfer frequency between low/middle/high rates. The switch
generates the similar problems about which I mention in the above. Some
vendors customizes firmware so that the switch of frequency is done in
vendor-specific registers, then restrict users to switch the frequency.
For example of Focusrite Saffire Pro 10 i/o and 26 i/o, users allows to
switch the frequency within the three steps; e.g. 44.1/48.0 kHz are
available at low step. Between the steps, extra operation is required and
it always generates bus-reset.
Another example of Edirol FA-66, users are prohibited to switch the
frequency by software. It's done by hardware switch and power-off.
I note that the sequence replay is not a solution for the ASIC bugs. Users
need to disconnect the device corrupted by the bug, then reconnect it to
refresh state machine inner the ASIC.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Link: https://lore.kernel.org/r/20210601081753.9191-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-06-01 17:17:53 +09:00
|
|
|
|
// MEMO: Some devices start packet transmission long enough after establishment of
|
|
|
|
|
// CMP connection. In the early stage of packet streaming, any device transfers
|
|
|
|
|
// NODATA packets. After several hundred cycles, it begins to multiplex event into
|
|
|
|
|
// the packet with adequate value of syt field in CIP header. Some devices are
|
|
|
|
|
// strictly to generate any discontinuity in the sequence of tx packet when they
|
|
|
|
|
// receives inadequate sequence of value in syt field of CIP header. In the case,
|
|
|
|
|
// the request to break CMP connection is often corrupted, then any transaction
|
|
|
|
|
// results in unrecoverable error, sometimes generate bus-reset.
|
|
|
|
|
err = amdtp_domain_start(&bebob->domain, tx_init_skip_cycles, true, false);
|
2019-08-04 15:21:30 +09:00
|
|
|
|
if (err < 0)
|
2019-06-12 17:44:04 +09:00
|
|
|
|
goto error;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
|
2019-06-12 17:44:04 +09:00
|
|
|
|
// NOTE:
|
|
|
|
|
// The firmware customized by M-Audio uses these commands to
|
|
|
|
|
// start transmitting stream. This is not usual way.
|
|
|
|
|
if (bebob->maudio_special_quirk) {
|
|
|
|
|
err = bebob->spec->rate->set(bebob, curr_rate);
|
2014-04-25 22:45:26 +09:00
|
|
|
|
if (err < 0) {
|
|
|
|
|
dev_err(&bebob->unit->device,
|
|
|
|
|
"fail to ensure sampling rate: %d\n",
|
|
|
|
|
err);
|
2019-06-12 17:44:04 +09:00
|
|
|
|
goto error;
|
2014-04-25 22:45:26 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 13:01:51 +09:00
|
|
|
|
// Some devices postpone start of transmission mostly for 1 sec after receives
|
|
|
|
|
// packets firstly.
|
2021-05-20 13:01:54 +09:00
|
|
|
|
if (!amdtp_domain_wait_ready(&bebob->domain, READY_TIMEOUT_MS)) {
|
2014-04-25 22:45:15 +09:00
|
|
|
|
err = -ETIMEDOUT;
|
2019-06-12 17:44:04 +09:00
|
|
|
|
goto error;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-12 17:44:04 +09:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
error:
|
2019-08-04 15:21:30 +09:00
|
|
|
|
amdtp_domain_stop(&bebob->domain);
|
2019-06-12 17:44:04 +09:00
|
|
|
|
break_both_connections(bebob);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob)
|
|
|
|
|
{
|
2016-02-20 16:18:58 +09:00
|
|
|
|
if (bebob->substreams_counter == 0) {
|
2019-08-04 15:21:30 +09:00
|
|
|
|
amdtp_domain_stop(&bebob->domain);
|
2015-06-14 12:49:36 +09:00
|
|
|
|
break_both_connections(bebob);
|
2019-06-15 18:11:01 +09:00
|
|
|
|
|
|
|
|
|
cmp_connection_release(&bebob->out_conn);
|
|
|
|
|
cmp_connection_release(&bebob->in_conn);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-21 23:54:59 +09:00
|
|
|
|
/*
|
|
|
|
|
* This function should be called before starting streams or after stopping
|
|
|
|
|
* streams.
|
|
|
|
|
*/
|
2014-04-25 22:45:15 +09:00
|
|
|
|
void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob)
|
|
|
|
|
{
|
2019-08-04 15:21:30 +09:00
|
|
|
|
amdtp_domain_destroy(&bebob->domain);
|
|
|
|
|
|
2019-06-12 17:44:07 +09:00
|
|
|
|
destroy_stream(bebob, &bebob->tx_stream);
|
|
|
|
|
destroy_stream(bebob, &bebob->rx_stream);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* See: Table 50: Extended Stream Format Info Format Hierarchy Level 2’
|
|
|
|
|
* in Additional AVC commands (Nov 2003, BridgeCo)
|
|
|
|
|
* Also 'Clause 12 AM824 sequence adaption layers' in IEC 61883-6:2005
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
parse_stream_formation(u8 *buf, unsigned int len,
|
|
|
|
|
struct snd_bebob_stream_formation *formation)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i, e, channels, format;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* this module can support a hierarchy combination that:
|
|
|
|
|
* Root: Audio and Music (0x90)
|
|
|
|
|
* Level 1: AM824 Compound (0x40)
|
|
|
|
|
*/
|
|
|
|
|
if ((buf[0] != 0x90) || (buf[1] != 0x40))
|
|
|
|
|
return -ENOSYS;
|
|
|
|
|
|
|
|
|
|
/* check sampling rate */
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(bridgeco_freq_table); i++) {
|
|
|
|
|
if (buf[2] == bridgeco_freq_table[i])
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-05-28 19:43:30 +03:00
|
|
|
|
if (i == ARRAY_SIZE(bridgeco_freq_table))
|
2014-04-25 22:45:15 +09:00
|
|
|
|
return -ENOSYS;
|
|
|
|
|
|
|
|
|
|
/* Avoid double count by different entries for the same rate. */
|
|
|
|
|
memset(&formation[i], 0, sizeof(struct snd_bebob_stream_formation));
|
|
|
|
|
|
|
|
|
|
for (e = 0; e < buf[4]; e++) {
|
|
|
|
|
channels = buf[5 + e * 2];
|
|
|
|
|
format = buf[6 + e * 2];
|
|
|
|
|
|
|
|
|
|
switch (format) {
|
2014-05-28 00:14:47 +09:00
|
|
|
|
/* IEC 60958 Conformant, currently handled as MBLA */
|
2014-04-25 22:45:15 +09:00
|
|
|
|
case 0x00:
|
|
|
|
|
/* Multi bit linear audio */
|
|
|
|
|
case 0x06: /* Raw */
|
|
|
|
|
formation[i].pcm += channels;
|
|
|
|
|
break;
|
|
|
|
|
/* MIDI Conformant */
|
|
|
|
|
case 0x0d:
|
|
|
|
|
formation[i].midi += channels;
|
|
|
|
|
break;
|
|
|
|
|
/* IEC 61937-3 to 7 */
|
|
|
|
|
case 0x01:
|
|
|
|
|
case 0x02:
|
|
|
|
|
case 0x03:
|
|
|
|
|
case 0x04:
|
|
|
|
|
case 0x05:
|
|
|
|
|
/* Multi bit linear audio */
|
|
|
|
|
case 0x07: /* DVD-Audio */
|
|
|
|
|
case 0x0c: /* High Precision */
|
|
|
|
|
/* One Bit Audio */
|
|
|
|
|
case 0x08: /* (Plain) Raw */
|
|
|
|
|
case 0x09: /* (Plain) SACD */
|
|
|
|
|
case 0x0a: /* (Encoded) Raw */
|
|
|
|
|
case 0x0b: /* (Encoded) SACD */
|
|
|
|
|
/* Synchronization Stream (Stereo Raw audio) */
|
|
|
|
|
case 0x40:
|
|
|
|
|
/* Don't care */
|
|
|
|
|
case 0xff:
|
|
|
|
|
default:
|
|
|
|
|
return -ENOSYS; /* not supported */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-19 11:22:01 +09:00
|
|
|
|
if (formation[i].pcm > AM824_MAX_CHANNELS_FOR_PCM ||
|
|
|
|
|
formation[i].midi > AM824_MAX_CHANNELS_FOR_MIDI)
|
2014-04-25 22:45:15 +09:00
|
|
|
|
return -ENOSYS;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-21 12:28:29 +09:00
|
|
|
|
static int fill_stream_formations(struct snd_bebob *bebob, u8 addr[AVC_BRIDGECO_ADDR_BYTES],
|
|
|
|
|
enum avc_bridgeco_plug_dir plug_dir, unsigned int plug_id,
|
|
|
|
|
struct snd_bebob_stream_formation *formations)
|
2014-04-25 22:45:15 +09:00
|
|
|
|
{
|
2021-03-21 12:28:29 +09:00
|
|
|
|
enum avc_bridgeco_plug_type plug_type;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
u8 *buf;
|
|
|
|
|
unsigned int len, eid;
|
|
|
|
|
int err;
|
|
|
|
|
|
2021-03-21 12:28:29 +09:00
|
|
|
|
avc_bridgeco_fill_unit_addr(addr, plug_dir, AVC_BRIDGECO_PLUG_UNIT_ISOC, plug_id);
|
|
|
|
|
|
|
|
|
|
err = avc_bridgeco_get_plug_type(bebob->unit, addr, &plug_type);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
dev_err(&bebob->unit->device,
|
|
|
|
|
"Fail to get type for isoc %d plug 0: %d\n", plug_dir, err);
|
|
|
|
|
return err;
|
|
|
|
|
} else if (plug_type != AVC_BRIDGECO_PLUG_TYPE_ISOC)
|
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
2014-04-25 22:45:15 +09:00
|
|
|
|
buf = kmalloc(FORMAT_MAXIMUM_LENGTH, GFP_KERNEL);
|
|
|
|
|
if (buf == NULL)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
2021-03-21 12:28:29 +09:00
|
|
|
|
for (eid = 0; eid < SND_BEBOB_STRM_FMT_ENTRIES; ++eid) {
|
|
|
|
|
avc_bridgeco_fill_unit_addr(addr, plug_dir, AVC_BRIDGECO_PLUG_UNIT_ISOC, plug_id);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
|
|
|
|
|
len = FORMAT_MAXIMUM_LENGTH;
|
2021-03-21 12:28:29 +09:00
|
|
|
|
err = avc_bridgeco_get_plug_strm_fmt(bebob->unit, addr, buf, &len, eid);
|
|
|
|
|
// No entries remained.
|
2014-04-25 22:45:15 +09:00
|
|
|
|
if (err == -EINVAL && eid > 0) {
|
|
|
|
|
err = 0;
|
|
|
|
|
break;
|
|
|
|
|
} else if (err < 0) {
|
|
|
|
|
dev_err(&bebob->unit->device,
|
2021-03-21 12:28:29 +09:00
|
|
|
|
"fail to get stream format %d for isoc %d plug %d:%d\n",
|
|
|
|
|
eid, plug_dir, plug_id, err);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = parse_stream_formation(buf, len, formations);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kfree(buf);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-21 12:28:30 +09:00
|
|
|
|
static int detect_midi_ports(struct snd_bebob *bebob,
|
|
|
|
|
const struct snd_bebob_stream_formation *formats,
|
|
|
|
|
u8 addr[AVC_BRIDGECO_ADDR_BYTES], enum avc_bridgeco_plug_dir plug_dir,
|
|
|
|
|
unsigned int plug_count, unsigned int *midi_ports)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
|
|
*midi_ports = 0;
|
|
|
|
|
|
|
|
|
|
/// Detect the number of available MIDI ports when packet has MIDI conformant data channel.
|
|
|
|
|
for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; ++i) {
|
|
|
|
|
if (formats[i].midi > 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (i >= SND_BEBOB_STRM_FMT_ENTRIES)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < plug_count; ++i) {
|
|
|
|
|
enum avc_bridgeco_plug_type plug_type;
|
|
|
|
|
unsigned int ch_count;
|
|
|
|
|
|
|
|
|
|
avc_bridgeco_fill_unit_addr(addr, plug_dir, AVC_BRIDGECO_PLUG_UNIT_EXT, i);
|
|
|
|
|
|
|
|
|
|
err = avc_bridgeco_get_plug_type(bebob->unit, addr, &plug_type);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
dev_err(&bebob->unit->device,
|
|
|
|
|
"fail to get type for external %d plug %d: %d\n",
|
|
|
|
|
plug_dir, i, err);
|
|
|
|
|
break;
|
|
|
|
|
} else if (plug_type != AVC_BRIDGECO_PLUG_TYPE_MIDI) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = avc_bridgeco_get_plug_ch_count(bebob->unit, addr, &ch_count);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
break;
|
2021-06-18 13:04:47 +09:00
|
|
|
|
// Yamaha GO44, GO46, Terratec Phase 24, Phase x24 reports 0 for the number of
|
|
|
|
|
// channels in external output plug 3 (MIDI type) even if it has a pair of physical
|
|
|
|
|
// MIDI jacks. As a workaround, assume it as one.
|
|
|
|
|
if (ch_count == 0)
|
|
|
|
|
ch_count = 1;
|
2021-03-21 12:28:30 +09:00
|
|
|
|
*midi_ports += ch_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-25 22:45:15 +09:00
|
|
|
|
static int
|
|
|
|
|
seek_msu_sync_input_plug(struct snd_bebob *bebob)
|
|
|
|
|
{
|
|
|
|
|
u8 plugs[AVC_PLUG_INFO_BUF_BYTES], addr[AVC_BRIDGECO_ADDR_BYTES];
|
2014-05-28 00:14:41 +09:00
|
|
|
|
unsigned int i;
|
|
|
|
|
enum avc_bridgeco_plug_type type;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
/* Get the number of Music Sub Unit for both direction. */
|
|
|
|
|
err = avc_general_get_plug_info(bebob->unit, 0x0c, 0x00, 0x00, plugs);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
dev_err(&bebob->unit->device,
|
|
|
|
|
"fail to get info for MSU in/out plugs: %d\n",
|
|
|
|
|
err);
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* seek destination plugs for 'MSU sync input' */
|
|
|
|
|
bebob->sync_input_plug = -1;
|
|
|
|
|
for (i = 0; i < plugs[0]; i++) {
|
|
|
|
|
avc_bridgeco_fill_msu_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN, i);
|
|
|
|
|
err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
dev_err(&bebob->unit->device,
|
|
|
|
|
"fail to get type for MSU in plug %d: %d\n",
|
|
|
|
|
i, err);
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type == AVC_BRIDGECO_PLUG_TYPE_SYNC) {
|
|
|
|
|
bebob->sync_input_plug = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
end:
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int snd_bebob_stream_discover(struct snd_bebob *bebob)
|
|
|
|
|
{
|
2015-10-11 08:10:55 +02:00
|
|
|
|
const struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
u8 plugs[AVC_PLUG_INFO_BUF_BYTES], addr[AVC_BRIDGECO_ADDR_BYTES];
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
/* the number of plugs for isoc in/out, ext in/out */
|
|
|
|
|
err = avc_general_get_plug_info(bebob->unit, 0x1f, 0x07, 0x00, plugs);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
dev_err(&bebob->unit->device,
|
|
|
|
|
"fail to get info for isoc/external in/out plugs: %d\n",
|
|
|
|
|
err);
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This module supports at least one isoc input plug and one isoc
|
|
|
|
|
* output plug.
|
|
|
|
|
*/
|
|
|
|
|
if ((plugs[0] == 0) || (plugs[1] == 0)) {
|
|
|
|
|
err = -ENOSYS;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-21 12:28:29 +09:00
|
|
|
|
err = fill_stream_formations(bebob, addr, AVC_BRIDGECO_PLUG_DIR_IN, 0,
|
|
|
|
|
bebob->rx_stream_formations);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
if (err < 0)
|
|
|
|
|
goto end;
|
|
|
|
|
|
2021-03-21 12:28:29 +09:00
|
|
|
|
err = fill_stream_formations(bebob, addr, AVC_BRIDGECO_PLUG_DIR_OUT, 0,
|
|
|
|
|
bebob->tx_stream_formations);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
if (err < 0)
|
|
|
|
|
goto end;
|
|
|
|
|
|
2021-06-18 13:04:47 +09:00
|
|
|
|
err = detect_midi_ports(bebob, bebob->tx_stream_formations, addr, AVC_BRIDGECO_PLUG_DIR_IN,
|
2021-03-21 12:28:30 +09:00
|
|
|
|
plugs[2], &bebob->midi_input_ports);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
goto end;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
|
2021-06-18 13:04:47 +09:00
|
|
|
|
err = detect_midi_ports(bebob, bebob->rx_stream_formations, addr, AVC_BRIDGECO_PLUG_DIR_OUT,
|
2021-03-21 12:28:30 +09:00
|
|
|
|
plugs[3], &bebob->midi_output_ports);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
goto end;
|
2014-04-25 22:45:15 +09:00
|
|
|
|
|
|
|
|
|
/* for check source of clock later */
|
2014-04-25 22:45:21 +09:00
|
|
|
|
if (!clk_spec)
|
|
|
|
|
err = seek_msu_sync_input_plug(bebob);
|
2014-04-25 22:45:15 +09:00
|
|
|
|
end:
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2014-04-25 22:45:20 +09:00
|
|
|
|
|
|
|
|
|
void snd_bebob_stream_lock_changed(struct snd_bebob *bebob)
|
|
|
|
|
{
|
|
|
|
|
bebob->dev_lock_changed = true;
|
|
|
|
|
wake_up(&bebob->hwdep_wait);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int snd_bebob_stream_lock_try(struct snd_bebob *bebob)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
spin_lock_irq(&bebob->lock);
|
|
|
|
|
|
|
|
|
|
/* user land lock this */
|
|
|
|
|
if (bebob->dev_lock_count < 0) {
|
|
|
|
|
err = -EBUSY;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* this is the first time */
|
|
|
|
|
if (bebob->dev_lock_count++ == 0)
|
|
|
|
|
snd_bebob_stream_lock_changed(bebob);
|
|
|
|
|
err = 0;
|
|
|
|
|
end:
|
|
|
|
|
spin_unlock_irq(&bebob->lock);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void snd_bebob_stream_lock_release(struct snd_bebob *bebob)
|
|
|
|
|
{
|
|
|
|
|
spin_lock_irq(&bebob->lock);
|
|
|
|
|
|
|
|
|
|
if (WARN_ON(bebob->dev_lock_count <= 0))
|
|
|
|
|
goto end;
|
|
|
|
|
if (--bebob->dev_lock_count == 0)
|
|
|
|
|
snd_bebob_stream_lock_changed(bebob);
|
|
|
|
|
end:
|
|
|
|
|
spin_unlock_irq(&bebob->lock);
|
|
|
|
|
}
|