2 * TC Applied Technologies Digital Interface Communications Engine driver
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
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.
23 #define DICE_CATEGORY_ID 0x04
24 #define WEISS_CATEGORY_ID 0x00
25 #define LOUD_CATEGORY_ID 0x10
27 #define MODEL_ALESIS_IO_BOTH 0x000001
29 static int check_dice_category(struct fw_unit *unit)
31 struct fw_device *device = fw_parent_device(unit);
32 struct fw_csr_iterator it;
33 int key, val, vendor = -1, model = -1;
34 unsigned int category;
37 * Check that GUID and unit directory are constructed according to DICE
38 * rules, i.e., that the specifier ID is the GUID's OUI, and that the
39 * GUID chip ID consists of the 8-bit category ID, the 10-bit product
40 * ID, and a 22-bit serial number.
42 fw_csr_iterator_init(&it, unit->directory);
43 while (fw_csr_iterator_next(&it, &key, &val)) {
45 case CSR_SPECIFIER_ID:
54 if (vendor == OUI_WEISS)
55 category = WEISS_CATEGORY_ID;
56 else if (vendor == OUI_LOUD)
57 category = LOUD_CATEGORY_ID;
59 category = DICE_CATEGORY_ID;
60 if (device->config_rom[3] != ((vendor << 8) | category) ||
61 device->config_rom[4] >> 22 != model)
67 static int check_clock_caps(struct snd_dice *dice)
72 /* some very old firmwares don't tell about their clock support */
73 if (dice->clock_caps > 0) {
74 err = snd_dice_transaction_read_global(dice,
75 GLOBAL_CLOCK_CAPABILITIES,
79 dice->clock_caps = be32_to_cpu(value);
81 /* this should be supported by any device */
82 dice->clock_caps = CLOCK_CAP_RATE_44100 |
83 CLOCK_CAP_RATE_48000 |
84 CLOCK_CAP_SOURCE_ARX1 |
85 CLOCK_CAP_SOURCE_INTERNAL;
91 static void dice_card_strings(struct snd_dice *dice)
93 struct snd_card *card = dice->card;
94 struct fw_device *dev = fw_parent_device(dice->unit);
95 char vendor[32], model[32];
99 strcpy(card->driver, "DICE");
101 strcpy(card->shortname, "DICE");
102 BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
103 err = snd_dice_transaction_read_global(dice, GLOBAL_NICK_NAME,
105 sizeof(card->shortname));
107 /* DICE strings are returned in "always-wrong" endianness */
108 BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
109 for (i = 0; i < sizeof(card->shortname); i += 4)
110 swab32s((u32 *)&card->shortname[i]);
111 card->shortname[sizeof(card->shortname) - 1] = '\0';
115 fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
117 fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
118 snprintf(card->longname, sizeof(card->longname),
119 "%s %s (serial %u) at %s, S%d",
120 vendor, model, dev->config_rom[4] & 0x3fffff,
121 dev_name(&dice->unit->device), 100 << dev->max_speed);
123 strcpy(card->mixername, "DICE");
126 static void dice_free(struct snd_dice *dice)
128 snd_dice_stream_destroy_duplex(dice);
129 snd_dice_transaction_destroy(dice);
130 fw_unit_put(dice->unit);
132 mutex_destroy(&dice->mutex);
137 * This module releases the FireWire unit data after all ALSA character devices
138 * are released by applications. This is for releasing stream data or finishing
139 * transactions safely. Thus at returning from .remove(), this module still keep
140 * references for the unit.
142 static void dice_card_free(struct snd_card *card)
144 dice_free(card->private_data);
147 static void do_registration(struct work_struct *work)
149 struct snd_dice *dice = container_of(work, struct snd_dice, dwork.work);
152 if (dice->registered)
155 err = snd_card_new(&dice->unit->device, -1, NULL, THIS_MODULE, 0,
160 err = snd_dice_transaction_init(dice);
164 err = check_clock_caps(dice);
168 dice_card_strings(dice);
170 err = dice->detect_formats(dice);
174 err = snd_dice_stream_init_duplex(dice);
178 snd_dice_create_proc(dice);
180 err = snd_dice_create_pcm(dice);
184 err = snd_dice_create_midi(dice);
188 err = snd_dice_create_hwdep(dice);
192 err = snd_card_register(dice->card);
197 * After registered, dice instance can be released corresponding to
198 * releasing the sound card instance.
200 dice->card->private_free = dice_card_free;
201 dice->card->private_data = dice;
202 dice->registered = true;
206 snd_dice_stream_destroy_duplex(dice);
207 snd_dice_transaction_destroy(dice);
208 snd_dice_stream_destroy_duplex(dice);
209 snd_card_free(dice->card);
210 dev_info(&dice->unit->device,
211 "Sound card registration failed: %d\n", err);
214 static int dice_probe(struct fw_unit *unit,
215 const struct ieee1394_device_id *entry)
217 struct snd_dice *dice;
220 if (!entry->driver_data && entry->vendor_id != OUI_SSL) {
221 err = check_dice_category(unit);
226 /* Allocate this independent of sound card instance. */
227 dice = kzalloc(sizeof(struct snd_dice), GFP_KERNEL);
231 dice->unit = fw_unit_get(unit);
232 dev_set_drvdata(&unit->device, dice);
234 if (!entry->driver_data) {
235 dice->detect_formats = snd_dice_stream_detect_current_formats;
237 dice->detect_formats =
238 (snd_dice_detect_formats_t)entry->driver_data;
241 spin_lock_init(&dice->lock);
242 mutex_init(&dice->mutex);
243 init_completion(&dice->clock_accepted);
244 init_waitqueue_head(&dice->hwdep_wait);
246 /* Allocate and register this sound card later. */
247 INIT_DEFERRABLE_WORK(&dice->dwork, do_registration);
248 snd_fw_schedule_registration(unit, &dice->dwork);
253 static void dice_remove(struct fw_unit *unit)
255 struct snd_dice *dice = dev_get_drvdata(&unit->device);
258 * Confirm to stop the work for registration before the sound card is
259 * going to be released. The work is not scheduled again because bus
260 * reset handler is not called anymore.
262 cancel_delayed_work_sync(&dice->dwork);
264 if (dice->registered) {
265 /* No need to wait for releasing card object in this context. */
266 snd_card_free_when_closed(dice->card);
268 /* Don't forget this case. */
273 static void dice_bus_reset(struct fw_unit *unit)
275 struct snd_dice *dice = dev_get_drvdata(&unit->device);
277 /* Postpone a workqueue for deferred registration. */
278 if (!dice->registered)
279 snd_fw_schedule_registration(unit, &dice->dwork);
281 /* The handler address register becomes initialized. */
282 snd_dice_transaction_reinit(dice);
285 * After registration, userspace can start packet streaming, then this
286 * code block works fine.
288 if (dice->registered) {
289 mutex_lock(&dice->mutex);
290 snd_dice_stream_update_duplex(dice);
291 mutex_unlock(&dice->mutex);
295 #define DICE_INTERFACE 0x000001
297 static const struct ieee1394_device_id dice_id_table[] = {
298 /* M-Audio Profire 2626 has a different value in version field. */
300 .match_flags = IEEE1394_MATCH_VENDOR_ID |
301 IEEE1394_MATCH_MODEL_ID,
302 .vendor_id = OUI_MAUDIO,
303 .model_id = 0x000010,
304 .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
306 /* M-Audio Profire 610 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 = 0x000011,
312 .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
314 /* TC Electronic Konnekt 24D. */
316 .match_flags = IEEE1394_MATCH_VENDOR_ID |
317 IEEE1394_MATCH_MODEL_ID,
318 .vendor_id = OUI_TCELECTRONIC,
319 .model_id = 0x000020,
320 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
322 /* TC Electronic Konnekt 8. */
324 .match_flags = IEEE1394_MATCH_VENDOR_ID |
325 IEEE1394_MATCH_MODEL_ID,
326 .vendor_id = OUI_TCELECTRONIC,
327 .model_id = 0x000021,
328 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
330 /* TC Electronic Studio Konnekt 48. */
332 .match_flags = IEEE1394_MATCH_VENDOR_ID |
333 IEEE1394_MATCH_MODEL_ID,
334 .vendor_id = OUI_TCELECTRONIC,
335 .model_id = 0x000022,
336 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
338 /* TC Electronic Konnekt Live. */
340 .match_flags = IEEE1394_MATCH_VENDOR_ID |
341 IEEE1394_MATCH_MODEL_ID,
342 .vendor_id = OUI_TCELECTRONIC,
343 .model_id = 0x000023,
344 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
346 /* TC Electronic Desktop Konnekt 6. */
348 .match_flags = IEEE1394_MATCH_VENDOR_ID |
349 IEEE1394_MATCH_MODEL_ID,
350 .vendor_id = OUI_TCELECTRONIC,
351 .model_id = 0x000024,
352 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
354 /* TC Electronic Impact Twin. */
356 .match_flags = IEEE1394_MATCH_VENDOR_ID |
357 IEEE1394_MATCH_MODEL_ID,
358 .vendor_id = OUI_TCELECTRONIC,
359 .model_id = 0x000027,
360 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
362 /* TC Electronic Digital Konnekt x32. */
364 .match_flags = IEEE1394_MATCH_VENDOR_ID |
365 IEEE1394_MATCH_MODEL_ID,
366 .vendor_id = OUI_TCELECTRONIC,
367 .model_id = 0x000030,
368 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
370 /* Alesis iO14/iO26. */
372 .match_flags = IEEE1394_MATCH_VENDOR_ID |
373 IEEE1394_MATCH_MODEL_ID,
374 .vendor_id = OUI_ALESIS,
375 .model_id = MODEL_ALESIS_IO_BOTH,
376 .driver_data = (kernel_ulong_t)snd_dice_detect_alesis_formats,
378 /* Mytek Stereo 192 DSD-DAC. */
380 .match_flags = IEEE1394_MATCH_VENDOR_ID |
381 IEEE1394_MATCH_MODEL_ID,
382 .vendor_id = OUI_MYTEK,
383 .model_id = 0x000002,
384 .driver_data = (kernel_ulong_t)snd_dice_detect_mytek_formats,
386 // Solid State Logic, Duende Classic and Mini.
387 // NOTE: each field of GUID in config ROM is not compliant to standard
390 .match_flags = IEEE1394_MATCH_VENDOR_ID |
391 IEEE1394_MATCH_MODEL_ID,
392 .vendor_id = OUI_SSL,
393 .model_id = 0x000070,
396 .match_flags = IEEE1394_MATCH_VERSION,
397 .version = DICE_INTERFACE,
401 MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
403 static struct fw_driver dice_driver = {
405 .owner = THIS_MODULE,
406 .name = KBUILD_MODNAME,
410 .update = dice_bus_reset,
411 .remove = dice_remove,
412 .id_table = dice_id_table,
415 static int __init alsa_dice_init(void)
417 return driver_register(&dice_driver.driver);
420 static void __exit alsa_dice_exit(void)
422 driver_unregister(&dice_driver.driver);
425 module_init(alsa_dice_init);
426 module_exit(alsa_dice_exit);