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_card_free(struct snd_card *card)
57 struct snd_motu *motu = card->private_data;
59 snd_motu_transaction_unregister(motu);
60 snd_motu_stream_destroy_duplex(motu);
63 static void do_registration(struct work_struct *work)
65 struct snd_motu *motu = container_of(work, struct snd_motu, dwork.work);
71 err = snd_card_new(&motu->unit->device, -1, NULL, THIS_MODULE, 0,
75 motu->card->private_free = motu_card_free;
76 motu->card->private_data = motu;
80 err = snd_motu_transaction_register(motu);
84 err = snd_motu_stream_init_duplex(motu);
88 snd_motu_proc_init(motu);
90 err = snd_motu_create_pcm_devices(motu);
94 if ((motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_2ND_Q) ||
95 (motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_3RD_Q) ||
96 (motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_2ND_Q) ||
97 (motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_3RD_Q)) {
98 err = snd_motu_create_midi_devices(motu);
103 err = snd_motu_create_hwdep_device(motu);
107 err = snd_card_register(motu->card);
111 motu->registered = true;
115 snd_card_free(motu->card);
116 dev_info(&motu->unit->device,
117 "Sound card registration failed: %d\n", err);
120 static int motu_probe(struct fw_unit *unit,
121 const struct ieee1394_device_id *entry)
123 struct snd_motu *motu;
125 /* Allocate this independently of sound card instance. */
126 motu = devm_kzalloc(&unit->device, sizeof(struct snd_motu), GFP_KERNEL);
129 motu->unit = fw_unit_get(unit);
130 dev_set_drvdata(&unit->device, motu);
132 motu->spec = (const struct snd_motu_spec *)entry->driver_data;
133 mutex_init(&motu->mutex);
134 spin_lock_init(&motu->lock);
135 init_waitqueue_head(&motu->hwdep_wait);
137 /* Allocate and register this sound card later. */
138 INIT_DEFERRABLE_WORK(&motu->dwork, do_registration);
139 snd_fw_schedule_registration(unit, &motu->dwork);
144 static void motu_remove(struct fw_unit *unit)
146 struct snd_motu *motu = dev_get_drvdata(&unit->device);
149 * Confirm to stop the work for registration before the sound card is
150 * going to be released. The work is not scheduled again because bus
151 * reset handler is not called anymore.
153 cancel_delayed_work_sync(&motu->dwork);
155 if (motu->registered) {
156 // Block till all of ALSA character devices are released.
157 snd_card_free(motu->card);
160 mutex_destroy(&motu->mutex);
161 fw_unit_put(motu->unit);
164 static void motu_bus_update(struct fw_unit *unit)
166 struct snd_motu *motu = dev_get_drvdata(&unit->device);
168 /* Postpone a workqueue for deferred registration. */
169 if (!motu->registered)
170 snd_fw_schedule_registration(unit, &motu->dwork);
172 /* The handler address register becomes initialized. */
173 snd_motu_transaction_reregister(motu);
176 static const struct snd_motu_spec motu_828mk2 = {
178 .protocol = &snd_motu_protocol_v2,
179 .flags = SND_MOTU_SPEC_SUPPORT_CLOCK_X2 |
180 SND_MOTU_SPEC_TX_MICINST_CHUNK |
181 SND_MOTU_SPEC_TX_RETURN_CHUNK |
182 SND_MOTU_SPEC_RX_SEPARETED_MAIN |
183 SND_MOTU_SPEC_HAS_OPT_IFACE_A |
184 SND_MOTU_SPEC_RX_MIDI_2ND_Q |
185 SND_MOTU_SPEC_TX_MIDI_2ND_Q,
187 .analog_in_ports = 8,
188 .analog_out_ports = 8,
191 const struct snd_motu_spec snd_motu_spec_traveler = {
193 .protocol = &snd_motu_protocol_v2,
194 .flags = SND_MOTU_SPEC_SUPPORT_CLOCK_X2 |
195 SND_MOTU_SPEC_SUPPORT_CLOCK_X4 |
196 SND_MOTU_SPEC_TX_RETURN_CHUNK |
197 SND_MOTU_SPEC_HAS_AESEBU_IFACE |
198 SND_MOTU_SPEC_HAS_OPT_IFACE_A |
199 SND_MOTU_SPEC_RX_MIDI_2ND_Q |
200 SND_MOTU_SPEC_TX_MIDI_2ND_Q,
202 .analog_in_ports = 8,
203 .analog_out_ports = 8,
206 static const struct snd_motu_spec motu_828mk3 = {
208 .protocol = &snd_motu_protocol_v3,
209 .flags = SND_MOTU_SPEC_SUPPORT_CLOCK_X2 |
210 SND_MOTU_SPEC_SUPPORT_CLOCK_X4 |
211 SND_MOTU_SPEC_TX_MICINST_CHUNK |
212 SND_MOTU_SPEC_TX_RETURN_CHUNK |
213 SND_MOTU_SPEC_TX_REVERB_CHUNK |
214 SND_MOTU_SPEC_RX_SEPARETED_MAIN |
215 SND_MOTU_SPEC_HAS_OPT_IFACE_A |
216 SND_MOTU_SPEC_HAS_OPT_IFACE_B |
217 SND_MOTU_SPEC_RX_MIDI_3RD_Q |
218 SND_MOTU_SPEC_TX_MIDI_3RD_Q,
220 .analog_in_ports = 8,
221 .analog_out_ports = 8,
224 static const struct snd_motu_spec motu_audio_express = {
225 .name = "AudioExpress",
226 .protocol = &snd_motu_protocol_v3,
227 .flags = SND_MOTU_SPEC_SUPPORT_CLOCK_X2 |
228 SND_MOTU_SPEC_TX_MICINST_CHUNK |
229 SND_MOTU_SPEC_TX_RETURN_CHUNK |
230 SND_MOTU_SPEC_RX_SEPARETED_MAIN |
231 SND_MOTU_SPEC_RX_MIDI_2ND_Q |
232 SND_MOTU_SPEC_TX_MIDI_3RD_Q,
233 .analog_in_ports = 2,
234 .analog_out_ports = 4,
237 #define SND_MOTU_DEV_ENTRY(model, data) \
239 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
240 IEEE1394_MATCH_SPECIFIER_ID | \
241 IEEE1394_MATCH_VERSION, \
242 .vendor_id = OUI_MOTU, \
243 .specifier_id = OUI_MOTU, \
245 .driver_data = (kernel_ulong_t)data, \
248 static const struct ieee1394_device_id motu_id_table[] = {
249 SND_MOTU_DEV_ENTRY(0x000003, &motu_828mk2),
250 SND_MOTU_DEV_ENTRY(0x000009, &snd_motu_spec_traveler),
251 SND_MOTU_DEV_ENTRY(0x000015, &motu_828mk3), /* FireWire only. */
252 SND_MOTU_DEV_ENTRY(0x000035, &motu_828mk3), /* Hybrid. */
253 SND_MOTU_DEV_ENTRY(0x000033, &motu_audio_express),
256 MODULE_DEVICE_TABLE(ieee1394, motu_id_table);
258 static struct fw_driver motu_driver = {
260 .owner = THIS_MODULE,
261 .name = KBUILD_MODNAME,
265 .update = motu_bus_update,
266 .remove = motu_remove,
267 .id_table = motu_id_table,
270 static int __init alsa_motu_init(void)
272 return driver_register(&motu_driver.driver);
275 static void __exit alsa_motu_exit(void)
277 driver_unregister(&motu_driver.driver);
280 module_init(alsa_motu_init);
281 module_exit(alsa_motu_exit);