bcb46a0e0e
you might feel like a deja vu to receive a bulk of changes at rc5, and it happens again; we've got a collection of fixes for ASoC. Most of fixes are targeted for the newly merged SOF (Sound Open Firmware) stuff and the relevant fixes for Intel platforms. Other than that, there are a few regression fixes for the recent ASoC core changes and HD-audio quirk, as well as a couple of FireWire fixes and for other ASoC codecs. -----BEGIN PGP SIGNATURE----- iQJCBAABCAAsFiEEIXTw5fNLNI7mMiVaLtJE4w1nLE8FAl0DY4YOHHRpd2FpQHN1 c2UuZGUACgkQLtJE4w1nLE/X9BAAzLc3OXBQhnQfFGvAmW8ro/bRuhwg3KjptwNe Zd/y6V4ru2Lhuqbr+EZMZqu665EkTg1CpHydMwsmD7bbmi47Xet7ocufjQMgHKcX l+QVRvzB+Ve5ARdUww8B6jqoc7CvZiM/tcW9VP3kphXOD4/iY1VcnRbVzHGYrAgI drLCnlC91Z5ssWPmAjuju6vZUwqCQupALs0wtdRFnwRonz0sCcPKjKzPAoS6KVQS 6kzRW3nLqKMpatbXdaSjb5tdVxRax8042sqaCqppvE1ToxvkbvSZykOwLQGDdCDn zkHUv+hmS76IV2Q4baCkAl4fkborKOJXgNQnoxQ5VDbOzBbOMy6867jQ+Y3gEx8k UqGpS2AA46c3pQcUvos0KqqHaSe3ESP2sH02k0BWWpmnyo927MAYE7qm80BnqjmJ emXXs0I5u5MkUBb00jP2QpvZqhoKzRLD84BWuHSlg5gIDCQ1cn1WIQaq8YIT4+Bf V50QUZMPI3PIw1g81XYLZXbhT/0b3zurOOhwEChPyJdz1ZoIyEeGMxt1rsZWD64B qn24AzRfIQTDteIYUmYovUtzZeFcAqQDsbtLQa98BzDHAYhvJEc+1bbT/NYgtv7/ zJqeFX9CbOcDihmiThvZKVAfThQeUCSWFBXk5JgBxs19uUa4et7XCHbXmPeyBJiq gF2xAhs= =9U0L -----END PGP SIGNATURE----- Merge tag 'sound-5.2-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound Pull sound fixes from Takashi Iwai: "It might feel like deja vu to receive a bulk of changes at rc5, and it happens again; we've got a collection of fixes for ASoC. Most of fixes are targeted for the newly merged SOF (Sound Open Firmware) stuff and the relevant fixes for Intel platforms. Other than that, there are a few regression fixes for the recent ASoC core changes and HD-audio quirk, as well as a couple of FireWire fixes and for other ASoC codecs" * tag 'sound-5.2-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: (54 commits) Revert "ALSA: hda/realtek - Improve the headset mic for Acer Aspire laptops" ALSA: ice1712: Check correct return value to snd_i2c_sendbytes (EWS/DMX 6Fire) ALSA: oxfw: allow PCM capture for Stanton SCS.1m ALSA: firewire-motu: fix destruction of data for isochronous resources ASoC: Intel: sst: fix kmalloc call with wrong flags ASoC: core: Fix deadlock in snd_soc_instantiate_card() SoC: rt274: Fix internal jack assignment in set_jack callback ALSA: hdac: fix memory release for SST and SOF drivers ASoC: SOF: Intel: hda: use the defined ppcap functions ASoC: core: move DAI pre-links initiation to snd_soc_instantiate_card ASoC: Intel: cht_bsw_rt5672: fix kernel oops with platform_name override ASoC: Intel: cht_bsw_nau8824: fix kernel oops with platform_name override ASoC: Intel: bytcht_es8316: fix kernel oops with platform_name override ASoC: Intel: cht_bsw_max98090: fix kernel oops with platform_name override ASoC: sun4i-i2s: Add offset to RX channel select ASoC: sun4i-i2s: Fix sun8i tx channel offset mask ASoC: max98090: remove 24-bit format support if RJ is 0 ASoC: da7219: Fix build error without CONFIG_I2C ASoC: SOF: Intel: hda: Fix COMPILE_TEST build error ASoC: SOF: fix DSP oops definitions in FW ABI ...
415 lines
10 KiB
C
415 lines
10 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* motu-stream.c - a part of driver for MOTU FireWire series
|
|
*
|
|
* Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
|
|
*/
|
|
|
|
#include "motu.h"
|
|
|
|
#define CALLBACK_TIMEOUT 200
|
|
|
|
#define ISOC_COMM_CONTROL_OFFSET 0x0b00
|
|
#define ISOC_COMM_CONTROL_MASK 0xffff0000
|
|
#define CHANGE_RX_ISOC_COMM_STATE 0x80000000
|
|
#define RX_ISOC_COMM_IS_ACTIVATED 0x40000000
|
|
#define RX_ISOC_COMM_CHANNEL_MASK 0x3f000000
|
|
#define RX_ISOC_COMM_CHANNEL_SHIFT 24
|
|
#define CHANGE_TX_ISOC_COMM_STATE 0x00800000
|
|
#define TX_ISOC_COMM_IS_ACTIVATED 0x00400000
|
|
#define TX_ISOC_COMM_CHANNEL_MASK 0x003f0000
|
|
#define TX_ISOC_COMM_CHANNEL_SHIFT 16
|
|
|
|
#define PACKET_FORMAT_OFFSET 0x0b10
|
|
#define TX_PACKET_EXCLUDE_DIFFERED_DATA_CHUNKS 0x00000080
|
|
#define RX_PACKET_EXCLUDE_DIFFERED_DATA_CHUNKS 0x00000040
|
|
#define TX_PACKET_TRANSMISSION_SPEED_MASK 0x0000000f
|
|
|
|
static int start_both_streams(struct snd_motu *motu, unsigned int rate)
|
|
{
|
|
unsigned int midi_ports = 0;
|
|
__be32 reg;
|
|
u32 data;
|
|
int err;
|
|
|
|
if ((motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_2ND_Q) ||
|
|
(motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_3RD_Q))
|
|
midi_ports = 1;
|
|
|
|
/* Set packet formation to our packet streaming engine. */
|
|
err = amdtp_motu_set_parameters(&motu->rx_stream, rate, midi_ports,
|
|
&motu->rx_packet_formats);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
if ((motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_2ND_Q) ||
|
|
(motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_3RD_Q))
|
|
midi_ports = 1;
|
|
else
|
|
midi_ports = 0;
|
|
|
|
err = amdtp_motu_set_parameters(&motu->tx_stream, rate, midi_ports,
|
|
&motu->tx_packet_formats);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
/* Get isochronous resources on the bus. */
|
|
err = fw_iso_resources_allocate(&motu->rx_resources,
|
|
amdtp_stream_get_max_payload(&motu->rx_stream),
|
|
fw_parent_device(motu->unit)->max_speed);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
err = fw_iso_resources_allocate(&motu->tx_resources,
|
|
amdtp_stream_get_max_payload(&motu->tx_stream),
|
|
fw_parent_device(motu->unit)->max_speed);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
/* Configure the unit to start isochronous communication. */
|
|
err = snd_motu_transaction_read(motu, ISOC_COMM_CONTROL_OFFSET, ®,
|
|
sizeof(reg));
|
|
if (err < 0)
|
|
return err;
|
|
data = be32_to_cpu(reg) & ~ISOC_COMM_CONTROL_MASK;
|
|
|
|
data |= CHANGE_RX_ISOC_COMM_STATE | RX_ISOC_COMM_IS_ACTIVATED |
|
|
(motu->rx_resources.channel << RX_ISOC_COMM_CHANNEL_SHIFT) |
|
|
CHANGE_TX_ISOC_COMM_STATE | TX_ISOC_COMM_IS_ACTIVATED |
|
|
(motu->tx_resources.channel << TX_ISOC_COMM_CHANNEL_SHIFT);
|
|
|
|
reg = cpu_to_be32(data);
|
|
return snd_motu_transaction_write(motu, ISOC_COMM_CONTROL_OFFSET, ®,
|
|
sizeof(reg));
|
|
}
|
|
|
|
static void stop_both_streams(struct snd_motu *motu)
|
|
{
|
|
__be32 reg;
|
|
u32 data;
|
|
int err;
|
|
|
|
err = motu->spec->protocol->switch_fetching_mode(motu, false);
|
|
if (err < 0)
|
|
return;
|
|
|
|
err = snd_motu_transaction_read(motu, ISOC_COMM_CONTROL_OFFSET, ®,
|
|
sizeof(reg));
|
|
if (err < 0)
|
|
return;
|
|
data = be32_to_cpu(reg);
|
|
|
|
data &= ~(RX_ISOC_COMM_IS_ACTIVATED | TX_ISOC_COMM_IS_ACTIVATED);
|
|
data |= CHANGE_RX_ISOC_COMM_STATE | CHANGE_TX_ISOC_COMM_STATE;
|
|
|
|
reg = cpu_to_be32(data);
|
|
snd_motu_transaction_write(motu, ISOC_COMM_CONTROL_OFFSET, ®,
|
|
sizeof(reg));
|
|
|
|
fw_iso_resources_free(&motu->tx_resources);
|
|
fw_iso_resources_free(&motu->rx_resources);
|
|
}
|
|
|
|
static int start_isoc_ctx(struct snd_motu *motu, struct amdtp_stream *stream)
|
|
{
|
|
struct fw_iso_resources *resources;
|
|
int err;
|
|
|
|
if (stream == &motu->rx_stream)
|
|
resources = &motu->rx_resources;
|
|
else
|
|
resources = &motu->tx_resources;
|
|
|
|
err = amdtp_stream_start(stream, resources->channel,
|
|
fw_parent_device(motu->unit)->max_speed);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
if (!amdtp_stream_wait_callback(stream, CALLBACK_TIMEOUT)) {
|
|
amdtp_stream_stop(stream);
|
|
fw_iso_resources_free(resources);
|
|
return -ETIMEDOUT;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void stop_isoc_ctx(struct snd_motu *motu, struct amdtp_stream *stream)
|
|
{
|
|
struct fw_iso_resources *resources;
|
|
|
|
if (stream == &motu->rx_stream)
|
|
resources = &motu->rx_resources;
|
|
else
|
|
resources = &motu->tx_resources;
|
|
|
|
amdtp_stream_stop(stream);
|
|
fw_iso_resources_free(resources);
|
|
}
|
|
|
|
int snd_motu_stream_cache_packet_formats(struct snd_motu *motu)
|
|
{
|
|
int err;
|
|
|
|
err = motu->spec->protocol->cache_packet_formats(motu);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
if (motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_2ND_Q) {
|
|
motu->tx_packet_formats.midi_flag_offset = 4;
|
|
motu->tx_packet_formats.midi_byte_offset = 6;
|
|
} else if (motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_3RD_Q) {
|
|
motu->tx_packet_formats.midi_flag_offset = 8;
|
|
motu->tx_packet_formats.midi_byte_offset = 7;
|
|
}
|
|
|
|
if (motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_2ND_Q) {
|
|
motu->rx_packet_formats.midi_flag_offset = 4;
|
|
motu->rx_packet_formats.midi_byte_offset = 6;
|
|
} else if (motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_3RD_Q) {
|
|
motu->rx_packet_formats.midi_flag_offset = 8;
|
|
motu->rx_packet_formats.midi_byte_offset = 7;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ensure_packet_formats(struct snd_motu *motu)
|
|
{
|
|
__be32 reg;
|
|
u32 data;
|
|
int err;
|
|
|
|
err = snd_motu_transaction_read(motu, PACKET_FORMAT_OFFSET, ®,
|
|
sizeof(reg));
|
|
if (err < 0)
|
|
return err;
|
|
data = be32_to_cpu(reg);
|
|
|
|
data &= ~(TX_PACKET_EXCLUDE_DIFFERED_DATA_CHUNKS |
|
|
RX_PACKET_EXCLUDE_DIFFERED_DATA_CHUNKS|
|
|
TX_PACKET_TRANSMISSION_SPEED_MASK);
|
|
if (motu->tx_packet_formats.differed_part_pcm_chunks[0] == 0)
|
|
data |= TX_PACKET_EXCLUDE_DIFFERED_DATA_CHUNKS;
|
|
if (motu->rx_packet_formats.differed_part_pcm_chunks[0] == 0)
|
|
data |= RX_PACKET_EXCLUDE_DIFFERED_DATA_CHUNKS;
|
|
data |= fw_parent_device(motu->unit)->max_speed;
|
|
|
|
reg = cpu_to_be32(data);
|
|
return snd_motu_transaction_write(motu, PACKET_FORMAT_OFFSET, ®,
|
|
sizeof(reg));
|
|
}
|
|
|
|
int snd_motu_stream_start_duplex(struct snd_motu *motu, unsigned int rate)
|
|
{
|
|
const struct snd_motu_protocol *protocol = motu->spec->protocol;
|
|
unsigned int curr_rate;
|
|
int err = 0;
|
|
|
|
if (motu->capture_substreams == 0 && motu->playback_substreams == 0)
|
|
return 0;
|
|
|
|
/* Some packet queueing errors. */
|
|
if (amdtp_streaming_error(&motu->rx_stream) ||
|
|
amdtp_streaming_error(&motu->tx_stream)) {
|
|
amdtp_stream_stop(&motu->rx_stream);
|
|
amdtp_stream_stop(&motu->tx_stream);
|
|
stop_both_streams(motu);
|
|
}
|
|
|
|
err = snd_motu_stream_cache_packet_formats(motu);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
/* Stop stream if rate is different. */
|
|
err = protocol->get_clock_rate(motu, &curr_rate);
|
|
if (err < 0) {
|
|
dev_err(&motu->unit->device,
|
|
"fail to get sampling rate: %d\n", err);
|
|
return err;
|
|
}
|
|
if (rate == 0)
|
|
rate = curr_rate;
|
|
if (rate != curr_rate) {
|
|
amdtp_stream_stop(&motu->rx_stream);
|
|
amdtp_stream_stop(&motu->tx_stream);
|
|
stop_both_streams(motu);
|
|
}
|
|
|
|
if (!amdtp_stream_running(&motu->rx_stream)) {
|
|
err = protocol->set_clock_rate(motu, rate);
|
|
if (err < 0) {
|
|
dev_err(&motu->unit->device,
|
|
"fail to set sampling rate: %d\n", err);
|
|
return err;
|
|
}
|
|
|
|
err = ensure_packet_formats(motu);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
err = start_both_streams(motu, rate);
|
|
if (err < 0) {
|
|
dev_err(&motu->unit->device,
|
|
"fail to start isochronous comm: %d\n", err);
|
|
goto stop_streams;
|
|
}
|
|
|
|
err = start_isoc_ctx(motu, &motu->rx_stream);
|
|
if (err < 0) {
|
|
dev_err(&motu->unit->device,
|
|
"fail to start IT context: %d\n", err);
|
|
goto stop_streams;
|
|
}
|
|
|
|
err = protocol->switch_fetching_mode(motu, true);
|
|
if (err < 0) {
|
|
dev_err(&motu->unit->device,
|
|
"fail to enable frame fetching: %d\n", err);
|
|
goto stop_streams;
|
|
}
|
|
}
|
|
|
|
if (!amdtp_stream_running(&motu->tx_stream) &&
|
|
motu->capture_substreams > 0) {
|
|
err = start_isoc_ctx(motu, &motu->tx_stream);
|
|
if (err < 0) {
|
|
dev_err(&motu->unit->device,
|
|
"fail to start IR context: %d", err);
|
|
amdtp_stream_stop(&motu->rx_stream);
|
|
goto stop_streams;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
|
|
stop_streams:
|
|
stop_both_streams(motu);
|
|
return err;
|
|
}
|
|
|
|
void snd_motu_stream_stop_duplex(struct snd_motu *motu)
|
|
{
|
|
if (motu->capture_substreams == 0) {
|
|
if (amdtp_stream_running(&motu->tx_stream))
|
|
stop_isoc_ctx(motu, &motu->tx_stream);
|
|
|
|
if (motu->playback_substreams == 0) {
|
|
if (amdtp_stream_running(&motu->rx_stream))
|
|
stop_isoc_ctx(motu, &motu->rx_stream);
|
|
stop_both_streams(motu);
|
|
}
|
|
}
|
|
}
|
|
|
|
static int init_stream(struct snd_motu *motu, enum amdtp_stream_direction dir)
|
|
{
|
|
int err;
|
|
struct amdtp_stream *stream;
|
|
struct fw_iso_resources *resources;
|
|
|
|
if (dir == AMDTP_IN_STREAM) {
|
|
stream = &motu->tx_stream;
|
|
resources = &motu->tx_resources;
|
|
} else {
|
|
stream = &motu->rx_stream;
|
|
resources = &motu->rx_resources;
|
|
}
|
|
|
|
err = fw_iso_resources_init(resources, motu->unit);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
err = amdtp_motu_init(stream, motu->unit, dir, motu->spec->protocol);
|
|
if (err < 0) {
|
|
amdtp_stream_destroy(stream);
|
|
fw_iso_resources_destroy(resources);
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
static void destroy_stream(struct snd_motu *motu,
|
|
enum amdtp_stream_direction dir)
|
|
{
|
|
struct amdtp_stream *stream;
|
|
struct fw_iso_resources *resources;
|
|
|
|
if (dir == AMDTP_IN_STREAM) {
|
|
stream = &motu->tx_stream;
|
|
resources = &motu->tx_resources;
|
|
} else {
|
|
stream = &motu->rx_stream;
|
|
resources = &motu->rx_resources;
|
|
}
|
|
|
|
amdtp_stream_destroy(stream);
|
|
fw_iso_resources_destroy(resources);
|
|
}
|
|
|
|
int snd_motu_stream_init_duplex(struct snd_motu *motu)
|
|
{
|
|
int err;
|
|
|
|
err = init_stream(motu, AMDTP_IN_STREAM);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
err = init_stream(motu, AMDTP_OUT_STREAM);
|
|
if (err < 0)
|
|
destroy_stream(motu, AMDTP_IN_STREAM);
|
|
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* This function should be called before starting streams or after stopping
|
|
* streams.
|
|
*/
|
|
void snd_motu_stream_destroy_duplex(struct snd_motu *motu)
|
|
{
|
|
destroy_stream(motu, AMDTP_IN_STREAM);
|
|
destroy_stream(motu, AMDTP_OUT_STREAM);
|
|
|
|
motu->playback_substreams = 0;
|
|
motu->capture_substreams = 0;
|
|
}
|
|
|
|
static void motu_lock_changed(struct snd_motu *motu)
|
|
{
|
|
motu->dev_lock_changed = true;
|
|
wake_up(&motu->hwdep_wait);
|
|
}
|
|
|
|
int snd_motu_stream_lock_try(struct snd_motu *motu)
|
|
{
|
|
int err;
|
|
|
|
spin_lock_irq(&motu->lock);
|
|
|
|
if (motu->dev_lock_count < 0) {
|
|
err = -EBUSY;
|
|
goto out;
|
|
}
|
|
|
|
if (motu->dev_lock_count++ == 0)
|
|
motu_lock_changed(motu);
|
|
err = 0;
|
|
out:
|
|
spin_unlock_irq(&motu->lock);
|
|
return err;
|
|
}
|
|
|
|
void snd_motu_stream_lock_release(struct snd_motu *motu)
|
|
{
|
|
spin_lock_irq(&motu->lock);
|
|
|
|
if (WARN_ON(motu->dev_lock_count <= 0))
|
|
goto out;
|
|
|
|
if (--motu->dev_lock_count == 0)
|
|
motu_lock_changed(motu);
|
|
out:
|
|
spin_unlock_irq(&motu->lock);
|
|
}
|