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
25 #define DICE_CATEGORY_ID 0x04
26 #define WEISS_CATEGORY_ID 0x00
27 #define LOUD_CATEGORY_ID 0x10
28 #define HARMAN_CATEGORY_ID 0x20
30 #define MODEL_ALESIS_IO_BOTH 0x000001
32 static int check_dice_category(struct fw_unit *unit)
34 struct fw_device *device = fw_parent_device(unit);
35 struct fw_csr_iterator it;
36 int key, val, vendor = -1, model = -1;
37 unsigned int category;
40 * Check that GUID and unit directory are constructed according to DICE
41 * rules, i.e., that the specifier ID is the GUID's OUI, and that the
42 * GUID chip ID consists of the 8-bit category ID, the 10-bit product
43 * ID, and a 22-bit serial number.
45 fw_csr_iterator_init(&it, unit->directory);
46 while (fw_csr_iterator_next(&it, &key, &val)) {
48 case CSR_SPECIFIER_ID:
57 if (vendor == OUI_WEISS)
58 category = WEISS_CATEGORY_ID;
59 else if (vendor == OUI_LOUD)
60 category = LOUD_CATEGORY_ID;
61 else if (vendor == OUI_HARMAN)
62 category = HARMAN_CATEGORY_ID;
64 category = DICE_CATEGORY_ID;
65 if (device->config_rom[3] != ((vendor << 8) | category) ||
66 device->config_rom[4] >> 22 != model)
72 static int check_clock_caps(struct snd_dice *dice)
77 /* some very old firmwares don't tell about their clock support */
78 if (dice->clock_caps > 0) {
79 err = snd_dice_transaction_read_global(dice,
80 GLOBAL_CLOCK_CAPABILITIES,
84 dice->clock_caps = be32_to_cpu(value);
86 /* this should be supported by any device */
87 dice->clock_caps = CLOCK_CAP_RATE_44100 |
88 CLOCK_CAP_RATE_48000 |
89 CLOCK_CAP_SOURCE_ARX1 |
90 CLOCK_CAP_SOURCE_INTERNAL;
96 static void dice_card_strings(struct snd_dice *dice)
98 struct snd_card *card = dice->card;
99 struct fw_device *dev = fw_parent_device(dice->unit);
100 char vendor[32], model[32];
104 strcpy(card->driver, "DICE");
106 strcpy(card->shortname, "DICE");
107 BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
108 err = snd_dice_transaction_read_global(dice, GLOBAL_NICK_NAME,
110 sizeof(card->shortname));
112 /* DICE strings are returned in "always-wrong" endianness */
113 BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
114 for (i = 0; i < sizeof(card->shortname); i += 4)
115 swab32s((u32 *)&card->shortname[i]);
116 card->shortname[sizeof(card->shortname) - 1] = '\0';
120 fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
122 fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
123 snprintf(card->longname, sizeof(card->longname),
124 "%s %s (serial %u) at %s, S%d",
125 vendor, model, dev->config_rom[4] & 0x3fffff,
126 dev_name(&dice->unit->device), 100 << dev->max_speed);
128 strcpy(card->mixername, "DICE");
131 static void dice_card_free(struct snd_card *card)
133 struct snd_dice *dice = card->private_data;
135 snd_dice_stream_destroy_duplex(dice);
136 snd_dice_transaction_destroy(dice);
139 static void do_registration(struct work_struct *work)
141 struct snd_dice *dice = container_of(work, struct snd_dice, dwork.work);
144 if (dice->registered)
147 err = snd_card_new(&dice->unit->device, -1, NULL, THIS_MODULE, 0,
151 dice->card->private_free = dice_card_free;
152 dice->card->private_data = dice;
154 err = snd_dice_transaction_init(dice);
158 err = check_clock_caps(dice);
162 dice_card_strings(dice);
164 err = dice->detect_formats(dice);
168 err = snd_dice_stream_init_duplex(dice);
172 snd_dice_create_proc(dice);
174 err = snd_dice_create_pcm(dice);
178 err = snd_dice_create_midi(dice);
182 err = snd_dice_create_hwdep(dice);
186 err = snd_card_register(dice->card);
190 dice->registered = true;
194 snd_card_free(dice->card);
195 dev_info(&dice->unit->device,
196 "Sound card registration failed: %d\n", err);
199 static int dice_probe(struct fw_unit *unit,
200 const struct ieee1394_device_id *entry)
202 struct snd_dice *dice;
205 if (!entry->driver_data && entry->vendor_id != OUI_SSL) {
206 err = check_dice_category(unit);
211 /* Allocate this independent of sound card instance. */
212 dice = devm_kzalloc(&unit->device, sizeof(struct snd_dice), GFP_KERNEL);
215 dice->unit = fw_unit_get(unit);
216 dev_set_drvdata(&unit->device, dice);
218 if (!entry->driver_data) {
219 dice->detect_formats = snd_dice_stream_detect_current_formats;
221 dice->detect_formats =
222 (snd_dice_detect_formats_t)entry->driver_data;
225 spin_lock_init(&dice->lock);
226 mutex_init(&dice->mutex);
227 init_completion(&dice->clock_accepted);
228 init_waitqueue_head(&dice->hwdep_wait);
230 /* Allocate and register this sound card later. */
231 INIT_DEFERRABLE_WORK(&dice->dwork, do_registration);
232 snd_fw_schedule_registration(unit, &dice->dwork);
237 static void dice_remove(struct fw_unit *unit)
239 struct snd_dice *dice = dev_get_drvdata(&unit->device);
242 * Confirm to stop the work for registration before the sound card is
243 * going to be released. The work is not scheduled again because bus
244 * reset handler is not called anymore.
246 cancel_delayed_work_sync(&dice->dwork);
248 if (dice->registered) {
249 // Block till all of ALSA character devices are released.
250 snd_card_free(dice->card);
253 mutex_destroy(&dice->mutex);
254 fw_unit_put(dice->unit);
257 static void dice_bus_reset(struct fw_unit *unit)
259 struct snd_dice *dice = dev_get_drvdata(&unit->device);
261 /* Postpone a workqueue for deferred registration. */
262 if (!dice->registered)
263 snd_fw_schedule_registration(unit, &dice->dwork);
265 /* The handler address register becomes initialized. */
266 snd_dice_transaction_reinit(dice);
269 * After registration, userspace can start packet streaming, then this
270 * code block works fine.
272 if (dice->registered) {
273 mutex_lock(&dice->mutex);
274 snd_dice_stream_update_duplex(dice);
275 mutex_unlock(&dice->mutex);
279 #define DICE_INTERFACE 0x000001
281 static const struct ieee1394_device_id dice_id_table[] = {
282 /* M-Audio Profire 2626 has a different value in version field. */
284 .match_flags = IEEE1394_MATCH_VENDOR_ID |
285 IEEE1394_MATCH_MODEL_ID,
286 .vendor_id = OUI_MAUDIO,
287 .model_id = 0x000010,
288 .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
290 /* M-Audio Profire 610 has a different value in version field. */
292 .match_flags = IEEE1394_MATCH_VENDOR_ID |
293 IEEE1394_MATCH_MODEL_ID,
294 .vendor_id = OUI_MAUDIO,
295 .model_id = 0x000011,
296 .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
298 /* TC Electronic Konnekt 24D. */
300 .match_flags = IEEE1394_MATCH_VENDOR_ID |
301 IEEE1394_MATCH_MODEL_ID,
302 .vendor_id = OUI_TCELECTRONIC,
303 .model_id = 0x000020,
304 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
306 /* TC Electronic Konnekt 8. */
308 .match_flags = IEEE1394_MATCH_VENDOR_ID |
309 IEEE1394_MATCH_MODEL_ID,
310 .vendor_id = OUI_TCELECTRONIC,
311 .model_id = 0x000021,
312 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
314 /* TC Electronic Studio Konnekt 48. */
316 .match_flags = IEEE1394_MATCH_VENDOR_ID |
317 IEEE1394_MATCH_MODEL_ID,
318 .vendor_id = OUI_TCELECTRONIC,
319 .model_id = 0x000022,
320 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
322 /* TC Electronic Konnekt Live. */
324 .match_flags = IEEE1394_MATCH_VENDOR_ID |
325 IEEE1394_MATCH_MODEL_ID,
326 .vendor_id = OUI_TCELECTRONIC,
327 .model_id = 0x000023,
328 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
330 /* TC Electronic Desktop Konnekt 6. */
332 .match_flags = IEEE1394_MATCH_VENDOR_ID |
333 IEEE1394_MATCH_MODEL_ID,
334 .vendor_id = OUI_TCELECTRONIC,
335 .model_id = 0x000024,
336 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
338 /* TC Electronic Impact Twin. */
340 .match_flags = IEEE1394_MATCH_VENDOR_ID |
341 IEEE1394_MATCH_MODEL_ID,
342 .vendor_id = OUI_TCELECTRONIC,
343 .model_id = 0x000027,
344 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
346 /* TC Electronic Digital Konnekt x32. */
348 .match_flags = IEEE1394_MATCH_VENDOR_ID |
349 IEEE1394_MATCH_MODEL_ID,
350 .vendor_id = OUI_TCELECTRONIC,
351 .model_id = 0x000030,
352 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
354 /* Alesis iO14/iO26. */
356 .match_flags = IEEE1394_MATCH_VENDOR_ID |
357 IEEE1394_MATCH_MODEL_ID,
358 .vendor_id = OUI_ALESIS,
359 .model_id = MODEL_ALESIS_IO_BOTH,
360 .driver_data = (kernel_ulong_t)snd_dice_detect_alesis_formats,
362 // Alesis MasterControl.
364 .match_flags = IEEE1394_MATCH_VENDOR_ID |
365 IEEE1394_MATCH_MODEL_ID,
366 .vendor_id = OUI_ALESIS,
367 .model_id = 0x000002,
368 .driver_data = (kernel_ulong_t)snd_dice_detect_alesis_mastercontrol_formats,
370 /* Mytek Stereo 192 DSD-DAC. */
372 .match_flags = IEEE1394_MATCH_VENDOR_ID |
373 IEEE1394_MATCH_MODEL_ID,
374 .vendor_id = OUI_MYTEK,
375 .model_id = 0x000002,
376 .driver_data = (kernel_ulong_t)snd_dice_detect_mytek_formats,
378 // Solid State Logic, Duende Classic and Mini.
379 // NOTE: each field of GUID in config ROM is not compliant to standard
382 .match_flags = IEEE1394_MATCH_VENDOR_ID |
383 IEEE1394_MATCH_MODEL_ID,
384 .vendor_id = OUI_SSL,
385 .model_id = 0x000070,
387 // Presonus FireStudio.
389 .match_flags = IEEE1394_MATCH_VENDOR_ID |
390 IEEE1394_MATCH_MODEL_ID,
391 .vendor_id = OUI_PRESONUS,
392 .model_id = 0x000008,
393 .driver_data = (kernel_ulong_t)snd_dice_detect_presonus_formats,
395 // Lexicon I-ONYX FW810S.
397 .match_flags = IEEE1394_MATCH_VENDOR_ID |
398 IEEE1394_MATCH_MODEL_ID,
399 .vendor_id = OUI_HARMAN,
400 .model_id = 0x000001,
401 .driver_data = (kernel_ulong_t)snd_dice_detect_harman_formats,
404 .match_flags = IEEE1394_MATCH_VERSION,
405 .version = DICE_INTERFACE,
409 MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
411 static struct fw_driver dice_driver = {
413 .owner = THIS_MODULE,
414 .name = KBUILD_MODNAME,
418 .update = dice_bus_reset,
419 .remove = dice_remove,
420 .id_table = dice_id_table,
423 static int __init alsa_dice_init(void)
425 return driver_register(&dice_driver.driver);
428 static void __exit alsa_dice_exit(void)
430 driver_unregister(&dice_driver.driver);
433 module_init(alsa_dice_init);
434 module_exit(alsa_dice_exit);