2 * motu.c - a part of driver for MOTU FireWire series
4 * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6 * Licensed under the terms of the GNU General Public License, version 2.
11 #define OUI_MOTU 0x0001f2
13 MODULE_DESCRIPTION("MOTU FireWire driver");
14 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
15 MODULE_LICENSE("GPL v2");
17 const unsigned int snd_motu_clock_rates[SND_MOTU_CLOCK_RATE_COUNT] = {
29 static void name_card(struct snd_motu *motu)
31 struct fw_device *fw_dev = fw_parent_device(motu->unit);
32 struct fw_csr_iterator it;
36 fw_csr_iterator_init(&it, motu->unit->directory);
37 while (fw_csr_iterator_next(&it, &key, &val)) {
45 strcpy(motu->card->driver, "FW-MOTU");
46 strcpy(motu->card->shortname, motu->spec->name);
47 strcpy(motu->card->mixername, motu->spec->name);
48 snprintf(motu->card->longname, sizeof(motu->card->longname),
49 "MOTU %s (version:%06x), GUID %08x%08x at %s, S%d",
50 motu->spec->name, version,
51 fw_dev->config_rom[3], fw_dev->config_rom[4],
52 dev_name(&motu->unit->device), 100 << fw_dev->max_speed);
55 static void motu_free(struct snd_motu *motu)
57 snd_motu_transaction_unregister(motu);
59 snd_motu_stream_destroy_duplex(motu);
60 fw_unit_put(motu->unit);
62 mutex_destroy(&motu->mutex);
67 * This module releases the FireWire unit data after all ALSA character devices
68 * are released by applications. This is for releasing stream data or finishing
69 * transactions safely. Thus at returning from .remove(), this module still keep
70 * references for the unit.
72 static void motu_card_free(struct snd_card *card)
74 motu_free(card->private_data);
77 static void do_registration(struct work_struct *work)
79 struct snd_motu *motu = container_of(work, struct snd_motu, dwork.work);
85 err = snd_card_new(&motu->unit->device, -1, NULL, THIS_MODULE, 0,
92 err = snd_motu_transaction_register(motu);
96 err = snd_motu_stream_init_duplex(motu);
100 snd_motu_proc_init(motu);
102 err = snd_motu_create_pcm_devices(motu);
106 if ((motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_2ND_Q) ||
107 (motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_3RD_Q) ||
108 (motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_2ND_Q) ||
109 (motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_3RD_Q)) {
110 err = snd_motu_create_midi_devices(motu);
115 err = snd_motu_create_hwdep_device(motu);
119 err = snd_card_register(motu->card);
124 * After registered, motu instance can be released corresponding to
125 * releasing the sound card instance.
127 motu->card->private_free = motu_card_free;
128 motu->card->private_data = motu;
129 motu->registered = true;
133 snd_motu_transaction_unregister(motu);
134 snd_motu_stream_destroy_duplex(motu);
135 snd_card_free(motu->card);
136 dev_info(&motu->unit->device,
137 "Sound card registration failed: %d\n", err);
140 static int motu_probe(struct fw_unit *unit,
141 const struct ieee1394_device_id *entry)
143 struct snd_motu *motu;
145 /* Allocate this independently of sound card instance. */
146 motu = kzalloc(sizeof(struct snd_motu), GFP_KERNEL);
150 motu->spec = (const struct snd_motu_spec *)entry->driver_data;
151 motu->unit = fw_unit_get(unit);
152 dev_set_drvdata(&unit->device, motu);
154 mutex_init(&motu->mutex);
155 spin_lock_init(&motu->lock);
156 init_waitqueue_head(&motu->hwdep_wait);
158 /* Allocate and register this sound card later. */
159 INIT_DEFERRABLE_WORK(&motu->dwork, do_registration);
160 snd_fw_schedule_registration(unit, &motu->dwork);
165 static void motu_remove(struct fw_unit *unit)
167 struct snd_motu *motu = dev_get_drvdata(&unit->device);
170 * Confirm to stop the work for registration before the sound card is
171 * going to be released. The work is not scheduled again because bus
172 * reset handler is not called anymore.
174 cancel_delayed_work_sync(&motu->dwork);
176 if (motu->registered) {
177 /* No need to wait for releasing card object in this context. */
178 snd_card_free_when_closed(motu->card);
180 /* Don't forget this case. */
185 static void motu_bus_update(struct fw_unit *unit)
187 struct snd_motu *motu = dev_get_drvdata(&unit->device);
189 /* Postpone a workqueue for deferred registration. */
190 if (!motu->registered)
191 snd_fw_schedule_registration(unit, &motu->dwork);
193 /* The handler address register becomes initialized. */
194 snd_motu_transaction_reregister(motu);
197 static const struct snd_motu_spec motu_828mk2 = {
199 .protocol = &snd_motu_protocol_v2,
200 .flags = SND_MOTU_SPEC_SUPPORT_CLOCK_X2 |
201 SND_MOTU_SPEC_TX_MICINST_CHUNK |
202 SND_MOTU_SPEC_TX_RETURN_CHUNK |
203 SND_MOTU_SPEC_RX_SEPARETED_MAIN |
204 SND_MOTU_SPEC_HAS_OPT_IFACE_A |
205 SND_MOTU_SPEC_RX_MIDI_2ND_Q |
206 SND_MOTU_SPEC_TX_MIDI_2ND_Q,
208 .analog_in_ports = 8,
209 .analog_out_ports = 8,
212 const struct snd_motu_spec snd_motu_spec_traveler = {
214 .protocol = &snd_motu_protocol_v2,
215 .flags = SND_MOTU_SPEC_SUPPORT_CLOCK_X2 |
216 SND_MOTU_SPEC_SUPPORT_CLOCK_X4 |
217 SND_MOTU_SPEC_TX_RETURN_CHUNK |
218 SND_MOTU_SPEC_HAS_AESEBU_IFACE |
219 SND_MOTU_SPEC_HAS_OPT_IFACE_A |
220 SND_MOTU_SPEC_RX_MIDI_2ND_Q |
221 SND_MOTU_SPEC_TX_MIDI_2ND_Q,
223 .analog_in_ports = 8,
224 .analog_out_ports = 8,
227 static const struct snd_motu_spec motu_828mk3 = {
229 .protocol = &snd_motu_protocol_v3,
230 .flags = SND_MOTU_SPEC_SUPPORT_CLOCK_X2 |
231 SND_MOTU_SPEC_SUPPORT_CLOCK_X4 |
232 SND_MOTU_SPEC_TX_MICINST_CHUNK |
233 SND_MOTU_SPEC_TX_RETURN_CHUNK |
234 SND_MOTU_SPEC_TX_REVERB_CHUNK |
235 SND_MOTU_SPEC_RX_SEPARETED_MAIN |
236 SND_MOTU_SPEC_HAS_OPT_IFACE_A |
237 SND_MOTU_SPEC_HAS_OPT_IFACE_B |
238 SND_MOTU_SPEC_RX_MIDI_3RD_Q |
239 SND_MOTU_SPEC_TX_MIDI_3RD_Q,
241 .analog_in_ports = 8,
242 .analog_out_ports = 8,
245 static const struct snd_motu_spec motu_audio_express = {
246 .name = "AudioExpress",
247 .protocol = &snd_motu_protocol_v3,
248 .flags = SND_MOTU_SPEC_SUPPORT_CLOCK_X2 |
249 SND_MOTU_SPEC_TX_MICINST_CHUNK |
250 SND_MOTU_SPEC_TX_RETURN_CHUNK |
251 SND_MOTU_SPEC_RX_SEPARETED_MAIN |
252 SND_MOTU_SPEC_RX_MIDI_2ND_Q |
253 SND_MOTU_SPEC_TX_MIDI_3RD_Q,
254 .analog_in_ports = 2,
255 .analog_out_ports = 4,
258 static const struct snd_motu_spec motu_4pre = {
260 .protocol = &snd_motu_protocol_v3,
261 .flags = SND_MOTU_SPEC_SUPPORT_CLOCK_X2 |
262 SND_MOTU_SPEC_TX_MICINST_CHUNK |
263 SND_MOTU_SPEC_TX_RETURN_CHUNK |
264 SND_MOTU_SPEC_RX_SEPARETED_MAIN,
265 .analog_in_ports = 2,
266 .analog_out_ports = 2,
269 #define SND_MOTU_DEV_ENTRY(model, data) \
271 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
272 IEEE1394_MATCH_SPECIFIER_ID | \
273 IEEE1394_MATCH_VERSION, \
274 .vendor_id = OUI_MOTU, \
275 .specifier_id = OUI_MOTU, \
277 .driver_data = (kernel_ulong_t)data, \
280 static const struct ieee1394_device_id motu_id_table[] = {
281 SND_MOTU_DEV_ENTRY(0x000003, &motu_828mk2),
282 SND_MOTU_DEV_ENTRY(0x000009, &snd_motu_spec_traveler),
283 SND_MOTU_DEV_ENTRY(0x000015, &motu_828mk3), /* FireWire only. */
284 SND_MOTU_DEV_ENTRY(0x000035, &motu_828mk3), /* Hybrid. */
285 SND_MOTU_DEV_ENTRY(0x000033, &motu_audio_express),
286 SND_MOTU_DEV_ENTRY(0x000045, &motu_4pre),
289 MODULE_DEVICE_TABLE(ieee1394, motu_id_table);
291 static struct fw_driver motu_driver = {
293 .owner = THIS_MODULE,
294 .name = KBUILD_MODNAME,
298 .update = motu_bus_update,
299 .remove = motu_remove,
300 .id_table = motu_id_table,
303 static int __init alsa_motu_init(void)
305 return driver_register(&motu_driver.driver);
308 static void __exit alsa_motu_exit(void)
310 driver_unregister(&motu_driver.driver);
313 module_init(alsa_motu_init);
314 module_exit(alsa_motu_exit);