
Fireface UCX transfers asynchronous transactions for MIDI messages. One transaction includes quadlet data therefore it can transfer 3 message bytes as maximum. Base address of the destination is configured by two settings; a register for higher 8 byte of the address, and a bitflag to option register indicates lower 8byte. The register for higher address is 0x'ffff'0000'0034. Unfortunately, firmware v24 includes a bug to ignore registered value for the destination address and transfers to 0x0001xxxxxxxx always. This driver doesn't work well if the bug exists, therefore users should install the latest firmware (v27). The bitflag is a part of value to be written to option register (0x'ffff'0000'0014). lower addr: bitflag (little endian) '0000'0000: 0x00002000 '0000'0080: 0x00004000 '0000'0100: 0x00008000 '0000'0180: 0x00010000 This register includes more options but they are not relevant to packet streaming or MIDI functionality. This driver don't touch it. Furthermore, the transaction is sent to address offset incremented by 4 byte to the offset in previous time. When it reaches base address plus 0x7c, next offset is the base address. Content of the transaction includes a prefix byte. Upper 4 bits of the byte indicates port number, and the rest 4 bits indicate the way to decode rest of bytes for MIDI message. Except for system exclusive messages, the rest bits are the same as status bits of the message without channel bits. For system exclusive messages, the rest bits are encoded according to included message bytes. For example: message: f0 7e 7f 09 01 f7 offset: content (little endian, port 0) '0000: 0x04f07e7f '0004: 0x070901f7 message: f0 00 00 66 14 20 00 00 00 f7 offset: content (little endian, port 1) '0014: 0x14f00000 '0018: 0x14661420 '001c: 0x14000000 '0020: 0x15f70000 message: f0 00 00 66 14 20 00 00 f7 offset: content (little endian, port 0) '0078: 0x04f00000 '007c: 0x04661420 '0000: 0x070000f7 This commit supports decoding scheme for the above and allows applications to receive MIDI messages via ALSA rawmidi interface. The lower 8 bytes of destination address is fixed to 0x'0000'0000, thus this driver expects userspace applications to configure option register with bitflag 0x00002000 in advance. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
245 lines
5.6 KiB
C
245 lines
5.6 KiB
C
/*
|
|
* ff.c - a part of driver for RME Fireface series
|
|
*
|
|
* Copyright (c) 2015-2017 Takashi Sakamoto
|
|
*
|
|
* Licensed under the terms of the GNU General Public License, version 2.
|
|
*/
|
|
|
|
#include "ff.h"
|
|
|
|
#define OUI_RME 0x000a35
|
|
|
|
MODULE_DESCRIPTION("RME Fireface series Driver");
|
|
MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
static void name_card(struct snd_ff *ff)
|
|
{
|
|
struct fw_device *fw_dev = fw_parent_device(ff->unit);
|
|
|
|
strcpy(ff->card->driver, "Fireface");
|
|
strcpy(ff->card->shortname, ff->spec->name);
|
|
strcpy(ff->card->mixername, ff->spec->name);
|
|
snprintf(ff->card->longname, sizeof(ff->card->longname),
|
|
"RME %s, GUID %08x%08x at %s, S%d", ff->spec->name,
|
|
fw_dev->config_rom[3], fw_dev->config_rom[4],
|
|
dev_name(&ff->unit->device), 100 << fw_dev->max_speed);
|
|
}
|
|
|
|
static void ff_card_free(struct snd_card *card)
|
|
{
|
|
struct snd_ff *ff = card->private_data;
|
|
|
|
snd_ff_stream_destroy_duplex(ff);
|
|
snd_ff_transaction_unregister(ff);
|
|
}
|
|
|
|
static void do_registration(struct work_struct *work)
|
|
{
|
|
struct snd_ff *ff = container_of(work, struct snd_ff, dwork.work);
|
|
int err;
|
|
|
|
if (ff->registered)
|
|
return;
|
|
|
|
err = snd_card_new(&ff->unit->device, -1, NULL, THIS_MODULE, 0,
|
|
&ff->card);
|
|
if (err < 0)
|
|
return;
|
|
ff->card->private_free = ff_card_free;
|
|
ff->card->private_data = ff;
|
|
|
|
err = snd_ff_transaction_register(ff);
|
|
if (err < 0)
|
|
goto error;
|
|
|
|
name_card(ff);
|
|
|
|
err = snd_ff_stream_init_duplex(ff);
|
|
if (err < 0)
|
|
goto error;
|
|
|
|
snd_ff_proc_init(ff);
|
|
|
|
err = snd_ff_create_midi_devices(ff);
|
|
if (err < 0)
|
|
goto error;
|
|
|
|
err = snd_ff_create_pcm_devices(ff);
|
|
if (err < 0)
|
|
goto error;
|
|
|
|
err = snd_ff_create_hwdep_devices(ff);
|
|
if (err < 0)
|
|
goto error;
|
|
|
|
err = snd_card_register(ff->card);
|
|
if (err < 0)
|
|
goto error;
|
|
|
|
ff->registered = true;
|
|
|
|
return;
|
|
error:
|
|
snd_card_free(ff->card);
|
|
dev_info(&ff->unit->device,
|
|
"Sound card registration failed: %d\n", err);
|
|
}
|
|
|
|
static int snd_ff_probe(struct fw_unit *unit,
|
|
const struct ieee1394_device_id *entry)
|
|
{
|
|
struct snd_ff *ff;
|
|
|
|
ff = devm_kzalloc(&unit->device, sizeof(struct snd_ff), GFP_KERNEL);
|
|
if (!ff)
|
|
return -ENOMEM;
|
|
ff->unit = fw_unit_get(unit);
|
|
dev_set_drvdata(&unit->device, ff);
|
|
|
|
mutex_init(&ff->mutex);
|
|
spin_lock_init(&ff->lock);
|
|
init_waitqueue_head(&ff->hwdep_wait);
|
|
|
|
ff->spec = (const struct snd_ff_spec *)entry->driver_data;
|
|
|
|
/* Register this sound card later. */
|
|
INIT_DEFERRABLE_WORK(&ff->dwork, do_registration);
|
|
snd_fw_schedule_registration(unit, &ff->dwork);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void snd_ff_update(struct fw_unit *unit)
|
|
{
|
|
struct snd_ff *ff = dev_get_drvdata(&unit->device);
|
|
|
|
/* Postpone a workqueue for deferred registration. */
|
|
if (!ff->registered)
|
|
snd_fw_schedule_registration(unit, &ff->dwork);
|
|
|
|
snd_ff_transaction_reregister(ff);
|
|
|
|
if (ff->registered)
|
|
snd_ff_stream_update_duplex(ff);
|
|
}
|
|
|
|
static void snd_ff_remove(struct fw_unit *unit)
|
|
{
|
|
struct snd_ff *ff = dev_get_drvdata(&unit->device);
|
|
|
|
/*
|
|
* 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_work_sync(&ff->dwork.work);
|
|
|
|
if (ff->registered) {
|
|
// Block till all of ALSA character devices are released.
|
|
snd_card_free(ff->card);
|
|
}
|
|
|
|
mutex_destroy(&ff->mutex);
|
|
fw_unit_put(ff->unit);
|
|
}
|
|
|
|
static const struct snd_ff_spec spec_ff800 = {
|
|
.name = "Fireface800",
|
|
.pcm_capture_channels = {28, 20, 12},
|
|
.pcm_playback_channels = {28, 20, 12},
|
|
.midi_in_ports = 1,
|
|
.midi_out_ports = 1,
|
|
.protocol = &snd_ff_protocol_ff800,
|
|
.midi_high_addr = 0x000200000320ull,
|
|
.midi_addr_range = 12,
|
|
};
|
|
|
|
static const struct snd_ff_spec spec_ff400 = {
|
|
.name = "Fireface400",
|
|
.pcm_capture_channels = {18, 14, 10},
|
|
.pcm_playback_channels = {18, 14, 10},
|
|
.midi_in_ports = 2,
|
|
.midi_out_ports = 2,
|
|
.protocol = &snd_ff_protocol_ff400,
|
|
.midi_high_addr = 0x0000801003f4ull,
|
|
.midi_addr_range = SND_FF_MAXIMIM_MIDI_QUADS * 4,
|
|
};
|
|
|
|
static const struct snd_ff_spec spec_ucx = {
|
|
.name = "FirefaceUCX",
|
|
.pcm_capture_channels = {18, 14, 12},
|
|
.pcm_playback_channels = {18, 14, 12},
|
|
.midi_in_ports = 2,
|
|
.protocol = &snd_ff_protocol_latter,
|
|
.midi_high_addr = 0xffff00000034ull,
|
|
.midi_addr_range = 0x80,
|
|
};
|
|
|
|
static const struct ieee1394_device_id snd_ff_id_table[] = {
|
|
/* Fireface 800 */
|
|
{
|
|
.match_flags = IEEE1394_MATCH_VENDOR_ID |
|
|
IEEE1394_MATCH_SPECIFIER_ID |
|
|
IEEE1394_MATCH_VERSION |
|
|
IEEE1394_MATCH_MODEL_ID,
|
|
.vendor_id = OUI_RME,
|
|
.specifier_id = OUI_RME,
|
|
.version = 0x000001,
|
|
.model_id = 0x101800,
|
|
.driver_data = (kernel_ulong_t)&spec_ff800,
|
|
},
|
|
/* Fireface 400 */
|
|
{
|
|
.match_flags = IEEE1394_MATCH_VENDOR_ID |
|
|
IEEE1394_MATCH_SPECIFIER_ID |
|
|
IEEE1394_MATCH_VERSION |
|
|
IEEE1394_MATCH_MODEL_ID,
|
|
.vendor_id = OUI_RME,
|
|
.specifier_id = OUI_RME,
|
|
.version = 0x000002,
|
|
.model_id = 0x101800,
|
|
.driver_data = (kernel_ulong_t)&spec_ff400,
|
|
},
|
|
// Fireface UCX.
|
|
{
|
|
.match_flags = IEEE1394_MATCH_VENDOR_ID |
|
|
IEEE1394_MATCH_SPECIFIER_ID |
|
|
IEEE1394_MATCH_VERSION |
|
|
IEEE1394_MATCH_MODEL_ID,
|
|
.vendor_id = OUI_RME,
|
|
.specifier_id = OUI_RME,
|
|
.version = 0x000004,
|
|
.model_id = 0x101800,
|
|
.driver_data = (kernel_ulong_t)&spec_ucx,
|
|
},
|
|
{}
|
|
};
|
|
MODULE_DEVICE_TABLE(ieee1394, snd_ff_id_table);
|
|
|
|
static struct fw_driver ff_driver = {
|
|
.driver = {
|
|
.owner = THIS_MODULE,
|
|
.name = "snd-fireface",
|
|
.bus = &fw_bus_type,
|
|
},
|
|
.probe = snd_ff_probe,
|
|
.update = snd_ff_update,
|
|
.remove = snd_ff_remove,
|
|
.id_table = snd_ff_id_table,
|
|
};
|
|
|
|
static int __init snd_ff_init(void)
|
|
{
|
|
return driver_register(&ff_driver.driver);
|
|
}
|
|
|
|
static void __exit snd_ff_exit(void)
|
|
{
|
|
driver_unregister(&ff_driver.driver);
|
|
}
|
|
|
|
module_init(snd_ff_init);
|
|
module_exit(snd_ff_exit);
|