1 // SPDX-License-Identifier: GPL-2.0-only
3 * ff.c - a part of driver for RME Fireface series
5 * Copyright (c) 2015-2017 Takashi Sakamoto
10 #define OUI_RME 0x000a35
12 MODULE_DESCRIPTION("RME Fireface series Driver");
13 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
14 MODULE_LICENSE("GPL v2");
16 static void name_card(struct snd_ff *ff)
18 struct fw_device *fw_dev = fw_parent_device(ff->unit);
19 const char *const names[] = {
20 [SND_FF_UNIT_VERSION_FF800] = "Fireface800",
21 [SND_FF_UNIT_VERSION_FF400] = "Fireface400",
22 [SND_FF_UNIT_VERSION_UFX] = "FirefaceUFX",
23 [SND_FF_UNIT_VERSION_UCX] = "FirefaceUCX",
24 [SND_FF_UNIT_VERSION_802] = "Fireface802",
28 name = names[ff->unit_version];
30 strcpy(ff->card->driver, "Fireface");
31 strcpy(ff->card->shortname, name);
32 strcpy(ff->card->mixername, name);
33 snprintf(ff->card->longname, sizeof(ff->card->longname),
34 "RME %s, GUID %08x%08x at %s, S%d", name,
35 fw_dev->config_rom[3], fw_dev->config_rom[4],
36 dev_name(&ff->unit->device), 100 << fw_dev->max_speed);
39 static void ff_card_free(struct snd_card *card)
41 struct snd_ff *ff = card->private_data;
43 snd_ff_stream_destroy_duplex(ff);
44 snd_ff_transaction_unregister(ff);
46 kfree(ff->msg_parser);
48 mutex_destroy(&ff->mutex);
49 fw_unit_put(ff->unit);
52 static int snd_ff_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry)
54 struct snd_card *card;
58 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, sizeof(*ff), &card);
61 card->private_free = ff_card_free;
63 ff = card->private_data;
64 ff->unit = fw_unit_get(unit);
65 dev_set_drvdata(&unit->device, ff);
68 mutex_init(&ff->mutex);
69 spin_lock_init(&ff->lock);
70 init_waitqueue_head(&ff->hwdep_wait);
72 ff->unit_version = entry->version;
73 ff->spec = (const struct snd_ff_spec *)entry->driver_data;
75 err = snd_ff_transaction_register(ff);
81 err = snd_ff_stream_init_duplex(ff);
87 err = snd_ff_create_midi_devices(ff);
91 err = snd_ff_create_pcm_devices(ff);
95 err = snd_ff_create_hwdep_devices(ff);
99 if (ff->spec->protocol->msg_parser_size > 0) {
100 ff->msg_parser = kzalloc(ff->spec->protocol->msg_parser_size, GFP_KERNEL);
101 if (!ff->msg_parser) {
107 err = snd_card_register(card);
117 static void snd_ff_update(struct fw_unit *unit)
119 struct snd_ff *ff = dev_get_drvdata(&unit->device);
121 snd_ff_transaction_reregister(ff);
123 snd_ff_stream_update_duplex(ff);
126 static void snd_ff_remove(struct fw_unit *unit)
128 struct snd_ff *ff = dev_get_drvdata(&unit->device);
130 // Block till all of ALSA character devices are released.
131 snd_card_free(ff->card);
134 static const struct snd_ff_spec spec_ff800 = {
135 .pcm_capture_channels = {28, 20, 12},
136 .pcm_playback_channels = {28, 20, 12},
139 .protocol = &snd_ff_protocol_ff800,
140 .midi_high_addr = 0x000200000320ull,
141 .midi_addr_range = 12,
142 .midi_rx_addrs = {0x000080180000ull, 0},
145 static const struct snd_ff_spec spec_ff400 = {
146 .pcm_capture_channels = {18, 14, 10},
147 .pcm_playback_channels = {18, 14, 10},
150 .protocol = &snd_ff_protocol_ff400,
151 .midi_high_addr = 0x0000801003f4ull,
152 .midi_addr_range = SND_FF_MAXIMIM_MIDI_QUADS * 4,
153 .midi_rx_addrs = {0x000080180000ull, 0x000080190000ull},
156 static const struct snd_ff_spec spec_ucx = {
157 .pcm_capture_channels = {18, 14, 12},
158 .pcm_playback_channels = {18, 14, 12},
161 .protocol = &snd_ff_protocol_latter,
162 .midi_high_addr = 0xffff00000034ull,
163 .midi_addr_range = 0x80,
164 .midi_rx_addrs = {0xffff00000030ull, 0xffff00000030ull},
167 static const struct snd_ff_spec spec_ufx_802 = {
168 .pcm_capture_channels = {30, 22, 14},
169 .pcm_playback_channels = {30, 22, 14},
172 .protocol = &snd_ff_protocol_latter,
173 .midi_high_addr = 0xffff00000034ull,
174 .midi_addr_range = 0x80,
175 .midi_rx_addrs = {0xffff00000030ull, 0xffff00000030ull},
178 static const struct ieee1394_device_id snd_ff_id_table[] = {
181 .match_flags = IEEE1394_MATCH_VENDOR_ID |
182 IEEE1394_MATCH_SPECIFIER_ID |
183 IEEE1394_MATCH_VERSION |
184 IEEE1394_MATCH_MODEL_ID,
185 .vendor_id = OUI_RME,
186 .specifier_id = OUI_RME,
187 .version = SND_FF_UNIT_VERSION_FF800,
188 .model_id = 0x101800,
189 .driver_data = (kernel_ulong_t)&spec_ff800,
193 .match_flags = IEEE1394_MATCH_VENDOR_ID |
194 IEEE1394_MATCH_SPECIFIER_ID |
195 IEEE1394_MATCH_VERSION |
196 IEEE1394_MATCH_MODEL_ID,
197 .vendor_id = OUI_RME,
198 .specifier_id = OUI_RME,
199 .version = SND_FF_UNIT_VERSION_FF400,
200 .model_id = 0x101800,
201 .driver_data = (kernel_ulong_t)&spec_ff400,
205 .match_flags = IEEE1394_MATCH_VENDOR_ID |
206 IEEE1394_MATCH_SPECIFIER_ID |
207 IEEE1394_MATCH_VERSION |
208 IEEE1394_MATCH_MODEL_ID,
209 .vendor_id = OUI_RME,
210 .specifier_id = OUI_RME,
211 .version = SND_FF_UNIT_VERSION_UFX,
212 .model_id = 0x101800,
213 .driver_data = (kernel_ulong_t)&spec_ufx_802,
217 .match_flags = IEEE1394_MATCH_VENDOR_ID |
218 IEEE1394_MATCH_SPECIFIER_ID |
219 IEEE1394_MATCH_VERSION |
220 IEEE1394_MATCH_MODEL_ID,
221 .vendor_id = OUI_RME,
222 .specifier_id = OUI_RME,
223 .version = SND_FF_UNIT_VERSION_UCX,
224 .model_id = 0x101800,
225 .driver_data = (kernel_ulong_t)&spec_ucx,
229 .match_flags = IEEE1394_MATCH_VENDOR_ID |
230 IEEE1394_MATCH_SPECIFIER_ID |
231 IEEE1394_MATCH_VERSION |
232 IEEE1394_MATCH_MODEL_ID,
233 .vendor_id = OUI_RME,
234 .specifier_id = OUI_RME,
235 .version = SND_FF_UNIT_VERSION_802,
236 .model_id = 0x101800,
237 .driver_data = (kernel_ulong_t)&spec_ufx_802,
241 MODULE_DEVICE_TABLE(ieee1394, snd_ff_id_table);
243 static struct fw_driver ff_driver = {
245 .owner = THIS_MODULE,
246 .name = KBUILD_MODNAME,
249 .probe = snd_ff_probe,
250 .update = snd_ff_update,
251 .remove = snd_ff_remove,
252 .id_table = snd_ff_id_table,
255 static int __init snd_ff_init(void)
257 return driver_register(&ff_driver.driver);
260 static void __exit snd_ff_exit(void)
262 driver_unregister(&ff_driver.driver);
265 module_init(snd_ff_init);
266 module_exit(snd_ff_exit);