2019-05-30 07:57:59 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-03-22 20:30:11 +08:00
|
|
|
/*
|
|
|
|
* motu.c - a part of driver for MOTU FireWire series
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "motu.h"
|
|
|
|
|
|
|
|
#define OUI_MOTU 0x0001f2
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("MOTU FireWire driver");
|
|
|
|
MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
|
ALSA: firewire-motu: add an abstraction layer for three types of protocols
In an aspect of used protocols to communicate, models of MOTU FireWire
units are categorized to three generations.
This commit adds an abstraction layer of the protocols for features
related to packet streaming functionality. This layer includes 5
operations.
When configuring packet streaming functionality with sampling rate and
sampling transmission frequency, .get_clock_rate and .set_clock_rate are
called with proper arguments. MOTU FireWire series supports up to 192.0kHz.
When checking current source of sampling clock (not clock for packetization
layer), .get_clock_source is used. Enumeration is added to represent the
sources supported by this series. This operation can be used to expose
available sampling rate to user space applications when the unit is
configured to use any input signal as source of clock instead of crystal
clock.
In the protocols, the path between packet processing layer and digital
signal processing layer can be controlled. This looks a functionality to
'mute' the unit. For this feature, .switch_fetching_mode is added. This
can be used to suppress noises every time packet streaming starts/stops.
In a point of the size of data blocks at a certain sampling transmission
frequency, the most units accept several modes. This is due to usage of
optical interfaces. The size differs depending on which modes are
configured to the interfaces; None, S/PDIF and ADAT. Additionally, format
of packet is different depending on protocols. To cache current size of
data blocks and its format, .cache_packet_formats is added. This is used
by PCM functionality, packet streaming functionality and data block
processing layer.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-03-22 20:30:14 +08:00
|
|
|
const unsigned int snd_motu_clock_rates[SND_MOTU_CLOCK_RATE_COUNT] = {
|
|
|
|
/* mode 0 */
|
|
|
|
[0] = 44100,
|
|
|
|
[1] = 48000,
|
|
|
|
/* mode 1 */
|
|
|
|
[2] = 88200,
|
|
|
|
[3] = 96000,
|
|
|
|
/* mode 2 */
|
|
|
|
[4] = 176400,
|
|
|
|
[5] = 192000,
|
|
|
|
};
|
|
|
|
|
2017-03-22 20:30:11 +08:00
|
|
|
static void name_card(struct snd_motu *motu)
|
|
|
|
{
|
|
|
|
struct fw_device *fw_dev = fw_parent_device(motu->unit);
|
|
|
|
struct fw_csr_iterator it;
|
|
|
|
int key, val;
|
|
|
|
u32 version = 0;
|
|
|
|
|
|
|
|
fw_csr_iterator_init(&it, motu->unit->directory);
|
|
|
|
while (fw_csr_iterator_next(&it, &key, &val)) {
|
|
|
|
switch (key) {
|
2019-03-17 14:49:29 +08:00
|
|
|
case CSR_MODEL:
|
2017-03-22 20:30:11 +08:00
|
|
|
version = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(motu->card->driver, "FW-MOTU");
|
2017-03-22 20:30:13 +08:00
|
|
|
strcpy(motu->card->shortname, motu->spec->name);
|
|
|
|
strcpy(motu->card->mixername, motu->spec->name);
|
2017-03-22 20:30:11 +08:00
|
|
|
snprintf(motu->card->longname, sizeof(motu->card->longname),
|
2019-03-17 14:49:29 +08:00
|
|
|
"MOTU %s (version:%06x), GUID %08x%08x at %s, S%d",
|
2017-03-22 20:30:13 +08:00
|
|
|
motu->spec->name, version,
|
2017-03-22 20:30:11 +08:00
|
|
|
fw_dev->config_rom[3], fw_dev->config_rom[4],
|
|
|
|
dev_name(&motu->unit->device), 100 << fw_dev->max_speed);
|
|
|
|
}
|
|
|
|
|
2018-10-10 14:35:02 +08:00
|
|
|
static void motu_card_free(struct snd_card *card)
|
2017-03-22 20:30:11 +08:00
|
|
|
{
|
2018-10-10 14:35:02 +08:00
|
|
|
struct snd_motu *motu = card->private_data;
|
2017-03-22 20:30:19 +08:00
|
|
|
|
2018-10-10 14:35:02 +08:00
|
|
|
snd_motu_transaction_unregister(motu);
|
2017-03-22 20:30:20 +08:00
|
|
|
snd_motu_stream_destroy_duplex(motu);
|
2017-03-22 20:30:11 +08:00
|
|
|
}
|
|
|
|
|
2017-03-22 20:30:12 +08:00
|
|
|
static void do_registration(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct snd_motu *motu = container_of(work, struct snd_motu, dwork.work);
|
|
|
|
int err;
|
2017-03-22 20:30:11 +08:00
|
|
|
|
2017-03-22 20:30:12 +08:00
|
|
|
if (motu->registered)
|
|
|
|
return;
|
2017-03-22 20:30:11 +08:00
|
|
|
|
2017-03-22 20:30:12 +08:00
|
|
|
err = snd_card_new(&motu->unit->device, -1, NULL, THIS_MODULE, 0,
|
|
|
|
&motu->card);
|
|
|
|
if (err < 0)
|
|
|
|
return;
|
2018-10-10 14:35:02 +08:00
|
|
|
motu->card->private_free = motu_card_free;
|
|
|
|
motu->card->private_data = motu;
|
2017-03-22 20:30:11 +08:00
|
|
|
|
|
|
|
name_card(motu);
|
|
|
|
|
2017-03-22 20:30:19 +08:00
|
|
|
err = snd_motu_transaction_register(motu);
|
|
|
|
if (err < 0)
|
|
|
|
goto error;
|
|
|
|
|
2017-03-22 20:30:20 +08:00
|
|
|
err = snd_motu_stream_init_duplex(motu);
|
|
|
|
if (err < 0)
|
|
|
|
goto error;
|
|
|
|
|
2017-03-22 20:30:21 +08:00
|
|
|
snd_motu_proc_init(motu);
|
|
|
|
|
2017-03-22 20:30:22 +08:00
|
|
|
err = snd_motu_create_pcm_devices(motu);
|
|
|
|
if (err < 0)
|
|
|
|
goto error;
|
|
|
|
|
2017-08-20 20:25:03 +08:00
|
|
|
if ((motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_2ND_Q) ||
|
|
|
|
(motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_3RD_Q) ||
|
|
|
|
(motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_2ND_Q) ||
|
|
|
|
(motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_3RD_Q)) {
|
2017-03-22 20:30:23 +08:00
|
|
|
err = snd_motu_create_midi_devices(motu);
|
|
|
|
if (err < 0)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2017-03-22 20:30:24 +08:00
|
|
|
err = snd_motu_create_hwdep_device(motu);
|
|
|
|
if (err < 0)
|
|
|
|
goto error;
|
|
|
|
|
2017-03-22 20:30:12 +08:00
|
|
|
err = snd_card_register(motu->card);
|
2017-03-22 20:30:11 +08:00
|
|
|
if (err < 0)
|
|
|
|
goto error;
|
|
|
|
|
2017-03-22 20:30:12 +08:00
|
|
|
motu->registered = true;
|
|
|
|
|
|
|
|
return;
|
|
|
|
error:
|
|
|
|
snd_card_free(motu->card);
|
|
|
|
dev_info(&motu->unit->device,
|
|
|
|
"Sound card registration failed: %d\n", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int motu_probe(struct fw_unit *unit,
|
|
|
|
const struct ieee1394_device_id *entry)
|
|
|
|
{
|
|
|
|
struct snd_motu *motu;
|
|
|
|
|
|
|
|
/* Allocate this independently of sound card instance. */
|
2018-10-03 07:21:50 +08:00
|
|
|
motu = devm_kzalloc(&unit->device, sizeof(struct snd_motu), GFP_KERNEL);
|
|
|
|
if (!motu)
|
2017-03-22 20:30:12 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
motu->unit = fw_unit_get(unit);
|
2017-03-22 20:30:11 +08:00
|
|
|
dev_set_drvdata(&unit->device, motu);
|
|
|
|
|
2018-10-03 07:21:50 +08:00
|
|
|
motu->spec = (const struct snd_motu_spec *)entry->driver_data;
|
2017-03-22 20:30:12 +08:00
|
|
|
mutex_init(&motu->mutex);
|
2017-03-22 20:30:23 +08:00
|
|
|
spin_lock_init(&motu->lock);
|
2017-03-22 20:30:24 +08:00
|
|
|
init_waitqueue_head(&motu->hwdep_wait);
|
2017-03-22 20:30:12 +08:00
|
|
|
|
|
|
|
/* Allocate and register this sound card later. */
|
|
|
|
INIT_DEFERRABLE_WORK(&motu->dwork, do_registration);
|
|
|
|
snd_fw_schedule_registration(unit, &motu->dwork);
|
|
|
|
|
2017-03-22 20:30:11 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void motu_remove(struct fw_unit *unit)
|
|
|
|
{
|
|
|
|
struct snd_motu *motu = dev_get_drvdata(&unit->device);
|
|
|
|
|
2017-03-22 20:30:12 +08:00
|
|
|
/*
|
|
|
|
* Confirm to stop the work for registration before the sound card is
|
|
|
|
* going to be released. The work is not scheduled again because bus
|
|
|
|
* reset handler is not called anymore.
|
|
|
|
*/
|
|
|
|
cancel_delayed_work_sync(&motu->dwork);
|
|
|
|
|
|
|
|
if (motu->registered) {
|
2018-10-10 14:34:59 +08:00
|
|
|
// Block till all of ALSA character devices are released.
|
|
|
|
snd_card_free(motu->card);
|
2017-03-22 20:30:12 +08:00
|
|
|
}
|
2018-10-10 14:35:00 +08:00
|
|
|
|
|
|
|
mutex_destroy(&motu->mutex);
|
|
|
|
fw_unit_put(motu->unit);
|
2017-03-22 20:30:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void motu_bus_update(struct fw_unit *unit)
|
|
|
|
{
|
2017-03-22 20:30:12 +08:00
|
|
|
struct snd_motu *motu = dev_get_drvdata(&unit->device);
|
|
|
|
|
|
|
|
/* Postpone a workqueue for deferred registration. */
|
|
|
|
if (!motu->registered)
|
|
|
|
snd_fw_schedule_registration(unit, &motu->dwork);
|
2017-03-22 20:30:19 +08:00
|
|
|
|
|
|
|
/* The handler address register becomes initialized. */
|
|
|
|
snd_motu_transaction_reregister(motu);
|
2017-03-22 20:30:11 +08:00
|
|
|
}
|
|
|
|
|
2017-03-22 20:30:13 +08:00
|
|
|
#define SND_MOTU_DEV_ENTRY(model, data) \
|
2017-03-22 20:30:11 +08:00
|
|
|
{ \
|
|
|
|
.match_flags = IEEE1394_MATCH_VENDOR_ID | \
|
2019-03-17 14:49:29 +08:00
|
|
|
IEEE1394_MATCH_SPECIFIER_ID | \
|
|
|
|
IEEE1394_MATCH_VERSION, \
|
2017-03-22 20:30:11 +08:00
|
|
|
.vendor_id = OUI_MOTU, \
|
|
|
|
.specifier_id = OUI_MOTU, \
|
2019-03-17 14:49:29 +08:00
|
|
|
.version = model, \
|
2017-03-22 20:30:13 +08:00
|
|
|
.driver_data = (kernel_ulong_t)data, \
|
2017-03-22 20:30:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ieee1394_device_id motu_id_table[] = {
|
2019-10-30 16:06:43 +08:00
|
|
|
SND_MOTU_DEV_ENTRY(0x000003, &snd_motu_spec_828mk2),
|
2020-05-19 19:16:28 +08:00
|
|
|
SND_MOTU_DEV_ENTRY(0x000009, &snd_motu_spec_traveler),
|
|
|
|
SND_MOTU_DEV_ENTRY(0x00000d, &snd_motu_spec_ultralite),
|
|
|
|
SND_MOTU_DEV_ENTRY(0x00000f, &snd_motu_spec_8pre),
|
2020-05-19 19:16:29 +08:00
|
|
|
SND_MOTU_DEV_ENTRY(0x000015, &snd_motu_spec_828mk3), // FireWire only.
|
ALSA: firewire-motu: add support for MOTU UltraLite-mk3 (FireWire only model)
UltraLite-mk3 was shipped 2008 by MOTU. This model has two lineups;
FireWire-only and FireWire/USB2.0 Hybrid model. Additionally, the latter
has two variants in respect of the type of IEEE 1394 connector; alpha
and beta connector.
This commit adds support for the FireWire-only model, which is already
discontinued.
$ python3 crpp < /sys/bus/firewire/devices/fw1/config_rom
ROM header and bus information block
-----------------------------------------------------------------
400 0410353a bus_info_length 4, crc_length 16, crc 13626
404 31333934 bus_name "1394"
408 20ff7000 irmc 0, cmc 0, isc 1, bmc 0, cyc_clk_acc 255, max_rec 7 (256)
40c 0001f200 company_id 0001f2 |
410 000902c7 device_id 00000902c7 | EUI-64 0001f200000902c7
root directory
-----------------------------------------------------------------
414 0004ef04 directory_length 4, crc 61188
418 030001f2 vendor
41c 0c0083c0 node capabilities per IEEE 1394
420 d1000002 --> unit directory at 428
424 8d000005 --> eui-64 leaf at 438
unit directory at 428
-----------------------------------------------------------------
428 00035556 directory_length 3, crc 21846
42c 120001f2 specifier id
430 13000019 version
434 17100800 model
eui-64 leaf at 438
-----------------------------------------------------------------
438 0002f3c5 leaf_length 2, crc 62405
43c 0001f200 company_id 0001f2 |
440 000902c7 device_id 00000902c7 | EUI-64 0001f200000902c7
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Link: https://lore.kernel.org/r/20200523071733.170129-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-05-23 15:17:33 +08:00
|
|
|
SND_MOTU_DEV_ENTRY(0x000019, &snd_motu_spec_ultralite_mk3), // FireWire only.
|
2020-05-19 19:16:29 +08:00
|
|
|
SND_MOTU_DEV_ENTRY(0x000035, &snd_motu_spec_828mk3), // Hybrid.
|
|
|
|
SND_MOTU_DEV_ENTRY(0x000033, &snd_motu_spec_audio_express),
|
|
|
|
SND_MOTU_DEV_ENTRY(0x000045, &snd_motu_spec_4pre),
|
2017-03-22 20:30:11 +08:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(ieee1394, motu_id_table);
|
|
|
|
|
|
|
|
static struct fw_driver motu_driver = {
|
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = KBUILD_MODNAME,
|
|
|
|
.bus = &fw_bus_type,
|
|
|
|
},
|
|
|
|
.probe = motu_probe,
|
|
|
|
.update = motu_bus_update,
|
|
|
|
.remove = motu_remove,
|
|
|
|
.id_table = motu_id_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init alsa_motu_init(void)
|
|
|
|
{
|
|
|
|
return driver_register(&motu_driver.driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit alsa_motu_exit(void)
|
|
|
|
{
|
|
|
|
driver_unregister(&motu_driver.driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(alsa_motu_init);
|
|
|
|
module_exit(alsa_motu_exit);
|