2 * ff.c - a part of driver for RME Fireface series
4 * Copyright (c) 2015-2017 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
11 #define OUI_RME 0x000a35
13 MODULE_DESCRIPTION("RME Fireface series Driver");
14 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
15 MODULE_LICENSE("GPL v2");
17 static void name_card(struct snd_ff *ff)
19 struct fw_device *fw_dev = fw_parent_device(ff->unit);
21 strcpy(ff->card->driver, "Fireface");
22 strcpy(ff->card->shortname, ff->spec->name);
23 strcpy(ff->card->mixername, ff->spec->name);
24 snprintf(ff->card->longname, sizeof(ff->card->longname),
25 "RME %s, GUID %08x%08x at %s, S%d", ff->spec->name,
26 fw_dev->config_rom[3], fw_dev->config_rom[4],
27 dev_name(&ff->unit->device), 100 << fw_dev->max_speed);
30 static void ff_card_free(struct snd_card *card)
32 struct snd_ff *ff = card->private_data;
34 snd_ff_stream_destroy_duplex(ff);
35 snd_ff_transaction_unregister(ff);
38 static void do_registration(struct work_struct *work)
40 struct snd_ff *ff = container_of(work, struct snd_ff, dwork.work);
46 err = snd_card_new(&ff->unit->device, -1, NULL, THIS_MODULE, 0,
50 ff->card->private_free = ff_card_free;
51 ff->card->private_data = ff;
53 err = snd_ff_transaction_register(ff);
59 err = snd_ff_stream_init_duplex(ff);
65 err = snd_ff_create_midi_devices(ff);
69 err = snd_ff_create_pcm_devices(ff);
73 err = snd_ff_create_hwdep_devices(ff);
77 err = snd_card_register(ff->card);
81 ff->registered = true;
85 snd_card_free(ff->card);
86 dev_info(&ff->unit->device,
87 "Sound card registration failed: %d\n", err);
90 static int snd_ff_probe(struct fw_unit *unit,
91 const struct ieee1394_device_id *entry)
95 ff = devm_kzalloc(&unit->device, sizeof(struct snd_ff), GFP_KERNEL);
98 ff->unit = fw_unit_get(unit);
99 dev_set_drvdata(&unit->device, ff);
101 mutex_init(&ff->mutex);
102 spin_lock_init(&ff->lock);
103 init_waitqueue_head(&ff->hwdep_wait);
105 ff->spec = (const struct snd_ff_spec *)entry->driver_data;
107 /* Register this sound card later. */
108 INIT_DEFERRABLE_WORK(&ff->dwork, do_registration);
109 snd_fw_schedule_registration(unit, &ff->dwork);
114 static void snd_ff_update(struct fw_unit *unit)
116 struct snd_ff *ff = dev_get_drvdata(&unit->device);
118 /* Postpone a workqueue for deferred registration. */
120 snd_fw_schedule_registration(unit, &ff->dwork);
122 snd_ff_transaction_reregister(ff);
125 snd_ff_stream_update_duplex(ff);
128 static void snd_ff_remove(struct fw_unit *unit)
130 struct snd_ff *ff = dev_get_drvdata(&unit->device);
133 * Confirm to stop the work for registration before the sound card is
134 * going to be released. The work is not scheduled again because bus
135 * reset handler is not called anymore.
137 cancel_work_sync(&ff->dwork.work);
139 if (ff->registered) {
140 // Block till all of ALSA character devices are released.
141 snd_card_free(ff->card);
144 mutex_destroy(&ff->mutex);
145 fw_unit_put(ff->unit);
148 static const struct snd_ff_spec spec_ff800 = {
149 .name = "Fireface800",
150 .pcm_capture_channels = {28, 20, 12},
151 .pcm_playback_channels = {28, 20, 12},
154 .protocol = &snd_ff_protocol_ff800,
155 .midi_high_addr = 0x000200000320ull,
156 .midi_addr_range = 12,
157 .midi_rx_addrs = {0x000080180000ull, 0},
160 static const struct snd_ff_spec spec_ff400 = {
161 .name = "Fireface400",
162 .pcm_capture_channels = {18, 14, 10},
163 .pcm_playback_channels = {18, 14, 10},
166 .protocol = &snd_ff_protocol_ff400,
167 .midi_high_addr = 0x0000801003f4ull,
168 .midi_addr_range = SND_FF_MAXIMIM_MIDI_QUADS * 4,
169 .midi_rx_addrs = {0x000080180000ull, 0x000080190000ull},
172 static const struct snd_ff_spec spec_ucx = {
173 .name = "FirefaceUCX",
174 .pcm_capture_channels = {18, 14, 12},
175 .pcm_playback_channels = {18, 14, 12},
178 .protocol = &snd_ff_protocol_latter,
179 .midi_high_addr = 0xffff00000034ull,
180 .midi_addr_range = 0x80,
181 .midi_rx_addrs = {0xffff00000030ull, 0xffff00000030ull},
184 static const struct ieee1394_device_id snd_ff_id_table[] = {
187 .match_flags = IEEE1394_MATCH_VENDOR_ID |
188 IEEE1394_MATCH_SPECIFIER_ID |
189 IEEE1394_MATCH_VERSION |
190 IEEE1394_MATCH_MODEL_ID,
191 .vendor_id = OUI_RME,
192 .specifier_id = OUI_RME,
194 .model_id = 0x101800,
195 .driver_data = (kernel_ulong_t)&spec_ff800,
199 .match_flags = IEEE1394_MATCH_VENDOR_ID |
200 IEEE1394_MATCH_SPECIFIER_ID |
201 IEEE1394_MATCH_VERSION |
202 IEEE1394_MATCH_MODEL_ID,
203 .vendor_id = OUI_RME,
204 .specifier_id = OUI_RME,
206 .model_id = 0x101800,
207 .driver_data = (kernel_ulong_t)&spec_ff400,
211 .match_flags = IEEE1394_MATCH_VENDOR_ID |
212 IEEE1394_MATCH_SPECIFIER_ID |
213 IEEE1394_MATCH_VERSION |
214 IEEE1394_MATCH_MODEL_ID,
215 .vendor_id = OUI_RME,
216 .specifier_id = OUI_RME,
218 .model_id = 0x101800,
219 .driver_data = (kernel_ulong_t)&spec_ucx,
223 MODULE_DEVICE_TABLE(ieee1394, snd_ff_id_table);
225 static struct fw_driver ff_driver = {
227 .owner = THIS_MODULE,
228 .name = "snd-fireface",
231 .probe = snd_ff_probe,
232 .update = snd_ff_update,
233 .remove = snd_ff_remove,
234 .id_table = snd_ff_id_table,
237 static int __init snd_ff_init(void)
239 return driver_register(&ff_driver.driver);
242 static void __exit snd_ff_exit(void)
244 driver_unregister(&ff_driver.driver);
247 module_init(snd_ff_init);
248 module_exit(snd_ff_exit);