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
24 #define DICE_CATEGORY_ID 0x04
25 #define WEISS_CATEGORY_ID 0x00
26 #define LOUD_CATEGORY_ID 0x10
28 #define MODEL_ALESIS_IO_BOTH 0x000001
30 static int check_dice_category(struct fw_unit *unit)
32 struct fw_device *device = fw_parent_device(unit);
33 struct fw_csr_iterator it;
34 int key, val, vendor = -1, model = -1;
35 unsigned int category;
38 * Check that GUID and unit directory are constructed according to DICE
39 * rules, i.e., that the specifier ID is the GUID's OUI, and that the
40 * GUID chip ID consists of the 8-bit category ID, the 10-bit product
41 * ID, and a 22-bit serial number.
43 fw_csr_iterator_init(&it, unit->directory);
44 while (fw_csr_iterator_next(&it, &key, &val)) {
46 case CSR_SPECIFIER_ID:
55 if (vendor == OUI_WEISS)
56 category = WEISS_CATEGORY_ID;
57 else if (vendor == OUI_LOUD)
58 category = LOUD_CATEGORY_ID;
60 category = DICE_CATEGORY_ID;
61 if (device->config_rom[3] != ((vendor << 8) | category) ||
62 device->config_rom[4] >> 22 != model)
68 static int check_clock_caps(struct snd_dice *dice)
73 /* some very old firmwares don't tell about their clock support */
74 if (dice->clock_caps > 0) {
75 err = snd_dice_transaction_read_global(dice,
76 GLOBAL_CLOCK_CAPABILITIES,
80 dice->clock_caps = be32_to_cpu(value);
82 /* this should be supported by any device */
83 dice->clock_caps = CLOCK_CAP_RATE_44100 |
84 CLOCK_CAP_RATE_48000 |
85 CLOCK_CAP_SOURCE_ARX1 |
86 CLOCK_CAP_SOURCE_INTERNAL;
92 static void dice_card_strings(struct snd_dice *dice)
94 struct snd_card *card = dice->card;
95 struct fw_device *dev = fw_parent_device(dice->unit);
96 char vendor[32], model[32];
100 strcpy(card->driver, "DICE");
102 strcpy(card->shortname, "DICE");
103 BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
104 err = snd_dice_transaction_read_global(dice, GLOBAL_NICK_NAME,
106 sizeof(card->shortname));
108 /* DICE strings are returned in "always-wrong" endianness */
109 BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
110 for (i = 0; i < sizeof(card->shortname); i += 4)
111 swab32s((u32 *)&card->shortname[i]);
112 card->shortname[sizeof(card->shortname) - 1] = '\0';
116 fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
118 fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
119 snprintf(card->longname, sizeof(card->longname),
120 "%s %s (serial %u) at %s, S%d",
121 vendor, model, dev->config_rom[4] & 0x3fffff,
122 dev_name(&dice->unit->device), 100 << dev->max_speed);
124 strcpy(card->mixername, "DICE");
127 static void dice_card_free(struct snd_card *card)
129 struct snd_dice *dice = card->private_data;
131 snd_dice_stream_destroy_duplex(dice);
132 snd_dice_transaction_destroy(dice);
135 static void do_registration(struct work_struct *work)
137 struct snd_dice *dice = container_of(work, struct snd_dice, dwork.work);
140 if (dice->registered)
143 err = snd_card_new(&dice->unit->device, -1, NULL, THIS_MODULE, 0,
147 dice->card->private_free = dice_card_free;
148 dice->card->private_data = dice;
150 err = snd_dice_transaction_init(dice);
154 err = check_clock_caps(dice);
158 dice_card_strings(dice);
160 err = dice->detect_formats(dice);
164 err = snd_dice_stream_init_duplex(dice);
168 snd_dice_create_proc(dice);
170 err = snd_dice_create_pcm(dice);
174 err = snd_dice_create_midi(dice);
178 err = snd_dice_create_hwdep(dice);
182 err = snd_card_register(dice->card);
186 dice->registered = true;
190 snd_card_free(dice->card);
191 dev_info(&dice->unit->device,
192 "Sound card registration failed: %d\n", err);
195 static int dice_probe(struct fw_unit *unit,
196 const struct ieee1394_device_id *entry)
198 struct snd_dice *dice;
201 if (!entry->driver_data && entry->vendor_id != OUI_SSL) {
202 err = check_dice_category(unit);
207 /* Allocate this independent of sound card instance. */
208 dice = devm_kzalloc(&unit->device, sizeof(struct snd_dice), GFP_KERNEL);
211 dice->unit = fw_unit_get(unit);
212 dev_set_drvdata(&unit->device, dice);
214 if (!entry->driver_data) {
215 dice->detect_formats = snd_dice_stream_detect_current_formats;
217 dice->detect_formats =
218 (snd_dice_detect_formats_t)entry->driver_data;
221 spin_lock_init(&dice->lock);
222 mutex_init(&dice->mutex);
223 init_completion(&dice->clock_accepted);
224 init_waitqueue_head(&dice->hwdep_wait);
226 /* Allocate and register this sound card later. */
227 INIT_DEFERRABLE_WORK(&dice->dwork, do_registration);
228 snd_fw_schedule_registration(unit, &dice->dwork);
233 static void dice_remove(struct fw_unit *unit)
235 struct snd_dice *dice = dev_get_drvdata(&unit->device);
238 * Confirm to stop the work for registration before the sound card is
239 * going to be released. The work is not scheduled again because bus
240 * reset handler is not called anymore.
242 cancel_delayed_work_sync(&dice->dwork);
244 if (dice->registered) {
245 // Block till all of ALSA character devices are released.
246 snd_card_free(dice->card);
249 mutex_destroy(&dice->mutex);
250 fw_unit_put(dice->unit);
253 static void dice_bus_reset(struct fw_unit *unit)
255 struct snd_dice *dice = dev_get_drvdata(&unit->device);
257 /* Postpone a workqueue for deferred registration. */
258 if (!dice->registered)
259 snd_fw_schedule_registration(unit, &dice->dwork);
261 /* The handler address register becomes initialized. */
262 snd_dice_transaction_reinit(dice);
265 * After registration, userspace can start packet streaming, then this
266 * code block works fine.
268 if (dice->registered) {
269 mutex_lock(&dice->mutex);
270 snd_dice_stream_update_duplex(dice);
271 mutex_unlock(&dice->mutex);
275 #define DICE_INTERFACE 0x000001
277 static const struct ieee1394_device_id dice_id_table[] = {
278 /* M-Audio Profire 2626 has a different value in version field. */
280 .match_flags = IEEE1394_MATCH_VENDOR_ID |
281 IEEE1394_MATCH_MODEL_ID,
282 .vendor_id = OUI_MAUDIO,
283 .model_id = 0x000010,
284 .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
286 /* M-Audio Profire 610 has a different value in version field. */
288 .match_flags = IEEE1394_MATCH_VENDOR_ID |
289 IEEE1394_MATCH_MODEL_ID,
290 .vendor_id = OUI_MAUDIO,
291 .model_id = 0x000011,
292 .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
294 /* TC Electronic Konnekt 24D. */
296 .match_flags = IEEE1394_MATCH_VENDOR_ID |
297 IEEE1394_MATCH_MODEL_ID,
298 .vendor_id = OUI_TCELECTRONIC,
299 .model_id = 0x000020,
300 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
302 /* TC Electronic Konnekt 8. */
304 .match_flags = IEEE1394_MATCH_VENDOR_ID |
305 IEEE1394_MATCH_MODEL_ID,
306 .vendor_id = OUI_TCELECTRONIC,
307 .model_id = 0x000021,
308 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
310 /* TC Electronic Studio Konnekt 48. */
312 .match_flags = IEEE1394_MATCH_VENDOR_ID |
313 IEEE1394_MATCH_MODEL_ID,
314 .vendor_id = OUI_TCELECTRONIC,
315 .model_id = 0x000022,
316 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
318 /* TC Electronic Konnekt Live. */
320 .match_flags = IEEE1394_MATCH_VENDOR_ID |
321 IEEE1394_MATCH_MODEL_ID,
322 .vendor_id = OUI_TCELECTRONIC,
323 .model_id = 0x000023,
324 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
326 /* TC Electronic Desktop Konnekt 6. */
328 .match_flags = IEEE1394_MATCH_VENDOR_ID |
329 IEEE1394_MATCH_MODEL_ID,
330 .vendor_id = OUI_TCELECTRONIC,
331 .model_id = 0x000024,
332 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
334 /* TC Electronic Impact Twin. */
336 .match_flags = IEEE1394_MATCH_VENDOR_ID |
337 IEEE1394_MATCH_MODEL_ID,
338 .vendor_id = OUI_TCELECTRONIC,
339 .model_id = 0x000027,
340 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
342 /* TC Electronic Digital Konnekt x32. */
344 .match_flags = IEEE1394_MATCH_VENDOR_ID |
345 IEEE1394_MATCH_MODEL_ID,
346 .vendor_id = OUI_TCELECTRONIC,
347 .model_id = 0x000030,
348 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
350 /* Alesis iO14/iO26. */
352 .match_flags = IEEE1394_MATCH_VENDOR_ID |
353 IEEE1394_MATCH_MODEL_ID,
354 .vendor_id = OUI_ALESIS,
355 .model_id = MODEL_ALESIS_IO_BOTH,
356 .driver_data = (kernel_ulong_t)snd_dice_detect_alesis_formats,
358 // Alesis MasterControl.
360 .match_flags = IEEE1394_MATCH_VENDOR_ID |
361 IEEE1394_MATCH_MODEL_ID,
362 .vendor_id = OUI_ALESIS,
363 .model_id = 0x000002,
364 .driver_data = (kernel_ulong_t)snd_dice_detect_alesis_mastercontrol_formats,
366 /* Mytek Stereo 192 DSD-DAC. */
368 .match_flags = IEEE1394_MATCH_VENDOR_ID |
369 IEEE1394_MATCH_MODEL_ID,
370 .vendor_id = OUI_MYTEK,
371 .model_id = 0x000002,
372 .driver_data = (kernel_ulong_t)snd_dice_detect_mytek_formats,
374 // Solid State Logic, Duende Classic and Mini.
375 // NOTE: each field of GUID in config ROM is not compliant to standard
378 .match_flags = IEEE1394_MATCH_VENDOR_ID |
379 IEEE1394_MATCH_MODEL_ID,
380 .vendor_id = OUI_SSL,
381 .model_id = 0x000070,
383 // Presonus FireStudio.
385 .match_flags = IEEE1394_MATCH_VENDOR_ID |
386 IEEE1394_MATCH_MODEL_ID,
387 .vendor_id = OUI_PRESONUS,
388 .model_id = 0x000008,
389 .driver_data = (kernel_ulong_t)snd_dice_detect_presonus_formats,
392 .match_flags = IEEE1394_MATCH_VERSION,
393 .version = DICE_INTERFACE,
397 MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
399 static struct fw_driver dice_driver = {
401 .owner = THIS_MODULE,
402 .name = KBUILD_MODNAME,
406 .update = dice_bus_reset,
407 .remove = dice_remove,
408 .id_table = dice_id_table,
411 static int __init alsa_dice_init(void)
413 return driver_register(&dice_driver.driver);
416 static void __exit alsa_dice_exit(void)
418 driver_unregister(&dice_driver.driver);
421 module_init(alsa_dice_init);
422 module_exit(alsa_dice_exit);