1 // SPDX-License-Identifier: GPL-2.0-only
3 * TC Applied Technologies Digital Interface Communications Engine driver
5 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
10 MODULE_DESCRIPTION("DICE driver");
11 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
12 MODULE_LICENSE("GPL v2");
14 #define OUI_WEISS 0x001c6a
15 #define OUI_LOUD 0x000ff2
16 #define OUI_FOCUSRITE 0x00130e
17 #define OUI_TCELECTRONIC 0x000166
18 #define OUI_ALESIS 0x000595
19 #define OUI_MAUDIO 0x000d6c
20 #define OUI_MYTEK 0x001ee8
21 #define OUI_SSL 0x0050c2 // Actually ID reserved by IEEE.
22 #define OUI_PRESONUS 0x000a92
23 #define OUI_HARMAN 0x000fd7
24 #define OUI_AVID 0x00a07e
26 #define DICE_CATEGORY_ID 0x04
27 #define WEISS_CATEGORY_ID 0x00
28 #define LOUD_CATEGORY_ID 0x10
29 #define HARMAN_CATEGORY_ID 0x20
31 #define MODEL_ALESIS_IO_BOTH 0x000001
33 static int check_dice_category(struct fw_unit *unit)
35 struct fw_device *device = fw_parent_device(unit);
36 struct fw_csr_iterator it;
37 int key, val, vendor = -1, model = -1;
38 unsigned int category;
41 * Check that GUID and unit directory are constructed according to DICE
42 * rules, i.e., that the specifier ID is the GUID's OUI, and that the
43 * GUID chip ID consists of the 8-bit category ID, the 10-bit product
44 * ID, and a 22-bit serial number.
46 fw_csr_iterator_init(&it, unit->directory);
47 while (fw_csr_iterator_next(&it, &key, &val)) {
49 case CSR_SPECIFIER_ID:
58 if (vendor == OUI_WEISS)
59 category = WEISS_CATEGORY_ID;
60 else if (vendor == OUI_LOUD)
61 category = LOUD_CATEGORY_ID;
62 else if (vendor == OUI_HARMAN)
63 category = HARMAN_CATEGORY_ID;
65 category = DICE_CATEGORY_ID;
66 if (device->config_rom[3] != ((vendor << 8) | category) ||
67 device->config_rom[4] >> 22 != model)
73 static int check_clock_caps(struct snd_dice *dice)
78 /* some very old firmwares don't tell about their clock support */
79 if (dice->clock_caps > 0) {
80 err = snd_dice_transaction_read_global(dice,
81 GLOBAL_CLOCK_CAPABILITIES,
85 dice->clock_caps = be32_to_cpu(value);
87 /* this should be supported by any device */
88 dice->clock_caps = CLOCK_CAP_RATE_44100 |
89 CLOCK_CAP_RATE_48000 |
90 CLOCK_CAP_SOURCE_ARX1 |
91 CLOCK_CAP_SOURCE_INTERNAL;
97 static void dice_card_strings(struct snd_dice *dice)
99 struct snd_card *card = dice->card;
100 struct fw_device *dev = fw_parent_device(dice->unit);
101 char vendor[32], model[32];
105 strcpy(card->driver, "DICE");
107 strcpy(card->shortname, "DICE");
108 BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
109 err = snd_dice_transaction_read_global(dice, GLOBAL_NICK_NAME,
111 sizeof(card->shortname));
113 /* DICE strings are returned in "always-wrong" endianness */
114 BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
115 for (i = 0; i < sizeof(card->shortname); i += 4)
116 swab32s((u32 *)&card->shortname[i]);
117 card->shortname[sizeof(card->shortname) - 1] = '\0';
121 fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
123 fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
124 snprintf(card->longname, sizeof(card->longname),
125 "%s %s (serial %u) at %s, S%d",
126 vendor, model, dev->config_rom[4] & 0x3fffff,
127 dev_name(&dice->unit->device), 100 << dev->max_speed);
129 strcpy(card->mixername, "DICE");
132 static void dice_card_free(struct snd_card *card)
134 struct snd_dice *dice = card->private_data;
136 snd_dice_stream_destroy_duplex(dice);
137 snd_dice_transaction_destroy(dice);
140 static void do_registration(struct work_struct *work)
142 struct snd_dice *dice = container_of(work, struct snd_dice, dwork.work);
145 if (dice->registered)
148 err = snd_card_new(&dice->unit->device, -1, NULL, THIS_MODULE, 0,
152 dice->card->private_free = dice_card_free;
153 dice->card->private_data = dice;
155 err = snd_dice_transaction_init(dice);
159 err = check_clock_caps(dice);
163 dice_card_strings(dice);
165 err = dice->detect_formats(dice);
169 err = snd_dice_stream_init_duplex(dice);
173 snd_dice_create_proc(dice);
175 err = snd_dice_create_pcm(dice);
179 err = snd_dice_create_midi(dice);
183 err = snd_dice_create_hwdep(dice);
187 err = snd_card_register(dice->card);
191 dice->registered = true;
195 snd_card_free(dice->card);
196 dev_info(&dice->unit->device,
197 "Sound card registration failed: %d\n", err);
200 static int dice_probe(struct fw_unit *unit,
201 const struct ieee1394_device_id *entry)
203 struct snd_dice *dice;
206 if (!entry->driver_data && entry->vendor_id != OUI_SSL) {
207 err = check_dice_category(unit);
212 /* Allocate this independent of sound card instance. */
213 dice = devm_kzalloc(&unit->device, sizeof(struct snd_dice), GFP_KERNEL);
216 dice->unit = fw_unit_get(unit);
217 dev_set_drvdata(&unit->device, dice);
219 if (!entry->driver_data) {
220 dice->detect_formats = snd_dice_stream_detect_current_formats;
222 dice->detect_formats =
223 (snd_dice_detect_formats_t)entry->driver_data;
226 // Below models are compliant to IEC 61883-1/6 and have no quirk at high sampling transfer
228 // * Avid M-Box 3 Pro
229 // * M-Audio Profire 610
230 // * M-Audio Profire 2626
231 if (entry->vendor_id == OUI_MAUDIO || entry->vendor_id == OUI_AVID)
232 dice->disable_double_pcm_frames = true;
234 spin_lock_init(&dice->lock);
235 mutex_init(&dice->mutex);
236 init_completion(&dice->clock_accepted);
237 init_waitqueue_head(&dice->hwdep_wait);
239 /* Allocate and register this sound card later. */
240 INIT_DEFERRABLE_WORK(&dice->dwork, do_registration);
241 snd_fw_schedule_registration(unit, &dice->dwork);
246 static void dice_remove(struct fw_unit *unit)
248 struct snd_dice *dice = dev_get_drvdata(&unit->device);
251 * Confirm to stop the work for registration before the sound card is
252 * going to be released. The work is not scheduled again because bus
253 * reset handler is not called anymore.
255 cancel_delayed_work_sync(&dice->dwork);
257 if (dice->registered) {
258 // Block till all of ALSA character devices are released.
259 snd_card_free(dice->card);
262 mutex_destroy(&dice->mutex);
263 fw_unit_put(dice->unit);
266 static void dice_bus_reset(struct fw_unit *unit)
268 struct snd_dice *dice = dev_get_drvdata(&unit->device);
270 /* Postpone a workqueue for deferred registration. */
271 if (!dice->registered)
272 snd_fw_schedule_registration(unit, &dice->dwork);
274 /* The handler address register becomes initialized. */
275 snd_dice_transaction_reinit(dice);
278 * After registration, userspace can start packet streaming, then this
279 * code block works fine.
281 if (dice->registered) {
282 mutex_lock(&dice->mutex);
283 snd_dice_stream_update_duplex(dice);
284 mutex_unlock(&dice->mutex);
288 #define DICE_INTERFACE 0x000001
290 #define DICE_DEV_ENTRY_TYPICAL(vendor, model, data) \
292 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
293 IEEE1394_MATCH_MODEL_ID | \
294 IEEE1394_MATCH_SPECIFIER_ID | \
295 IEEE1394_MATCH_VERSION, \
296 .vendor_id = (vendor), \
297 .model_id = (model), \
298 .specifier_id = (vendor), \
299 .version = DICE_INTERFACE, \
300 .driver_data = (kernel_ulong_t)(data), \
303 static const struct ieee1394_device_id dice_id_table[] = {
304 // Avid M-Box 3 Pro. To match in probe function.
305 DICE_DEV_ENTRY_TYPICAL(OUI_AVID, 0x000004, snd_dice_detect_extension_formats),
306 /* M-Audio Profire 2626 has a different value in version field. */
308 .match_flags = IEEE1394_MATCH_VENDOR_ID |
309 IEEE1394_MATCH_MODEL_ID,
310 .vendor_id = OUI_MAUDIO,
311 .model_id = 0x000010,
312 .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
314 /* M-Audio Profire 610 has a different value in version field. */
316 .match_flags = IEEE1394_MATCH_VENDOR_ID |
317 IEEE1394_MATCH_MODEL_ID,
318 .vendor_id = OUI_MAUDIO,
319 .model_id = 0x000011,
320 .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
322 /* TC Electronic Konnekt 24D. */
324 .match_flags = IEEE1394_MATCH_VENDOR_ID |
325 IEEE1394_MATCH_MODEL_ID,
326 .vendor_id = OUI_TCELECTRONIC,
327 .model_id = 0x000020,
328 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
330 /* TC Electronic Konnekt 8. */
332 .match_flags = IEEE1394_MATCH_VENDOR_ID |
333 IEEE1394_MATCH_MODEL_ID,
334 .vendor_id = OUI_TCELECTRONIC,
335 .model_id = 0x000021,
336 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
338 /* TC Electronic Studio Konnekt 48. */
340 .match_flags = IEEE1394_MATCH_VENDOR_ID |
341 IEEE1394_MATCH_MODEL_ID,
342 .vendor_id = OUI_TCELECTRONIC,
343 .model_id = 0x000022,
344 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
346 /* TC Electronic Konnekt Live. */
348 .match_flags = IEEE1394_MATCH_VENDOR_ID |
349 IEEE1394_MATCH_MODEL_ID,
350 .vendor_id = OUI_TCELECTRONIC,
351 .model_id = 0x000023,
352 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
354 /* TC Electronic Desktop Konnekt 6. */
356 .match_flags = IEEE1394_MATCH_VENDOR_ID |
357 IEEE1394_MATCH_MODEL_ID,
358 .vendor_id = OUI_TCELECTRONIC,
359 .model_id = 0x000024,
360 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
362 /* TC Electronic Impact Twin. */
364 .match_flags = IEEE1394_MATCH_VENDOR_ID |
365 IEEE1394_MATCH_MODEL_ID,
366 .vendor_id = OUI_TCELECTRONIC,
367 .model_id = 0x000027,
368 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
370 /* TC Electronic Digital Konnekt x32. */
372 .match_flags = IEEE1394_MATCH_VENDOR_ID |
373 IEEE1394_MATCH_MODEL_ID,
374 .vendor_id = OUI_TCELECTRONIC,
375 .model_id = 0x000030,
376 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
378 /* Alesis iO14/iO26. */
380 .match_flags = IEEE1394_MATCH_VENDOR_ID |
381 IEEE1394_MATCH_MODEL_ID,
382 .vendor_id = OUI_ALESIS,
383 .model_id = MODEL_ALESIS_IO_BOTH,
384 .driver_data = (kernel_ulong_t)snd_dice_detect_alesis_formats,
386 // Alesis MasterControl.
388 .match_flags = IEEE1394_MATCH_VENDOR_ID |
389 IEEE1394_MATCH_MODEL_ID,
390 .vendor_id = OUI_ALESIS,
391 .model_id = 0x000002,
392 .driver_data = (kernel_ulong_t)snd_dice_detect_alesis_mastercontrol_formats,
394 /* Mytek Stereo 192 DSD-DAC. */
396 .match_flags = IEEE1394_MATCH_VENDOR_ID |
397 IEEE1394_MATCH_MODEL_ID,
398 .vendor_id = OUI_MYTEK,
399 .model_id = 0x000002,
400 .driver_data = (kernel_ulong_t)snd_dice_detect_mytek_formats,
402 // Solid State Logic, Duende Classic and Mini.
403 // NOTE: each field of GUID in config ROM is not compliant to standard
406 .match_flags = IEEE1394_MATCH_VENDOR_ID |
407 IEEE1394_MATCH_MODEL_ID,
408 .vendor_id = OUI_SSL,
409 .model_id = 0x000070,
411 // Presonus FireStudio.
413 .match_flags = IEEE1394_MATCH_VENDOR_ID |
414 IEEE1394_MATCH_MODEL_ID,
415 .vendor_id = OUI_PRESONUS,
416 .model_id = 0x000008,
417 .driver_data = (kernel_ulong_t)snd_dice_detect_presonus_formats,
419 // Lexicon I-ONYX FW810S.
421 .match_flags = IEEE1394_MATCH_VENDOR_ID |
422 IEEE1394_MATCH_MODEL_ID,
423 .vendor_id = OUI_HARMAN,
424 .model_id = 0x000001,
425 .driver_data = (kernel_ulong_t)snd_dice_detect_harman_formats,
428 .match_flags = IEEE1394_MATCH_VERSION,
429 .version = DICE_INTERFACE,
433 MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
435 static struct fw_driver dice_driver = {
437 .owner = THIS_MODULE,
438 .name = KBUILD_MODNAME,
442 .update = dice_bus_reset,
443 .remove = dice_remove,
444 .id_table = dice_id_table,
447 static int __init alsa_dice_init(void)
449 return driver_register(&dice_driver.driver);
452 static void __exit alsa_dice_exit(void)
454 driver_unregister(&dice_driver.driver);
457 module_init(alsa_dice_init);
458 module_exit(alsa_dice_exit);