1 // SPDX-License-Identifier: GPL-2.0-only
3 * TC Applied Technologies Digital Interface Communications Engine driver
10 MODULE_DESCRIPTION("DICE driver");
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_card_free(struct snd_card *card)
128 struct snd_dice *dice = card->private_data;
130 snd_dice_stream_destroy_duplex(dice);
131 snd_dice_transaction_destroy(dice);
134 static void do_registration(struct work_struct *work)
136 struct snd_dice *dice = container_of(work, struct snd_dice, dwork.work);
139 if (dice->registered)
142 err = snd_card_new(&dice->unit->device, -1, NULL, THIS_MODULE, 0,
146 dice->card->private_free = dice_card_free;
147 dice->card->private_data = dice;
149 err = snd_dice_transaction_init(dice);
153 err = check_clock_caps(dice);
157 dice_card_strings(dice);
159 err = dice->detect_formats(dice);
163 err = snd_dice_stream_init_duplex(dice);
167 snd_dice_create_proc(dice);
169 err = snd_dice_create_pcm(dice);
173 err = snd_dice_create_midi(dice);
177 err = snd_dice_create_hwdep(dice);
181 err = snd_card_register(dice->card);
185 dice->registered = true;
189 snd_card_free(dice->card);
190 dev_info(&dice->unit->device,
191 "Sound card registration failed: %d\n", err);
194 static int dice_probe(struct fw_unit *unit,
195 const struct ieee1394_device_id *entry)
197 struct snd_dice *dice;
200 if (!entry->driver_data && entry->vendor_id != OUI_SSL) {
201 err = check_dice_category(unit);
206 /* Allocate this independent of sound card instance. */
207 dice = devm_kzalloc(&unit->device, sizeof(struct snd_dice), GFP_KERNEL);
210 dice->unit = fw_unit_get(unit);
211 dev_set_drvdata(&unit->device, dice);
213 if (!entry->driver_data) {
214 dice->detect_formats = snd_dice_stream_detect_current_formats;
216 dice->detect_formats =
217 (snd_dice_detect_formats_t)entry->driver_data;
220 spin_lock_init(&dice->lock);
221 mutex_init(&dice->mutex);
222 init_completion(&dice->clock_accepted);
223 init_waitqueue_head(&dice->hwdep_wait);
225 /* Allocate and register this sound card later. */
226 INIT_DEFERRABLE_WORK(&dice->dwork, do_registration);
227 snd_fw_schedule_registration(unit, &dice->dwork);
232 static void dice_remove(struct fw_unit *unit)
234 struct snd_dice *dice = dev_get_drvdata(&unit->device);
237 * Confirm to stop the work for registration before the sound card is
238 * going to be released. The work is not scheduled again because bus
239 * reset handler is not called anymore.
241 cancel_delayed_work_sync(&dice->dwork);
243 if (dice->registered) {
244 // Block till all of ALSA character devices are released.
245 snd_card_free(dice->card);
248 mutex_destroy(&dice->mutex);
249 fw_unit_put(dice->unit);
252 static void dice_bus_reset(struct fw_unit *unit)
254 struct snd_dice *dice = dev_get_drvdata(&unit->device);
256 /* Postpone a workqueue for deferred registration. */
257 if (!dice->registered)
258 snd_fw_schedule_registration(unit, &dice->dwork);
260 /* The handler address register becomes initialized. */
261 snd_dice_transaction_reinit(dice);
264 * After registration, userspace can start packet streaming, then this
265 * code block works fine.
267 if (dice->registered) {
268 mutex_lock(&dice->mutex);
269 snd_dice_stream_update_duplex(dice);
270 mutex_unlock(&dice->mutex);
274 #define DICE_INTERFACE 0x000001
276 static const struct ieee1394_device_id dice_id_table[] = {
277 /* M-Audio Profire 2626 has a different value in version field. */
279 .match_flags = IEEE1394_MATCH_VENDOR_ID |
280 IEEE1394_MATCH_MODEL_ID,
281 .vendor_id = OUI_MAUDIO,
282 .model_id = 0x000010,
283 .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
285 /* M-Audio Profire 610 has a different value in version field. */
287 .match_flags = IEEE1394_MATCH_VENDOR_ID |
288 IEEE1394_MATCH_MODEL_ID,
289 .vendor_id = OUI_MAUDIO,
290 .model_id = 0x000011,
291 .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
293 /* TC Electronic Konnekt 24D. */
295 .match_flags = IEEE1394_MATCH_VENDOR_ID |
296 IEEE1394_MATCH_MODEL_ID,
297 .vendor_id = OUI_TCELECTRONIC,
298 .model_id = 0x000020,
299 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
301 /* TC Electronic Konnekt 8. */
303 .match_flags = IEEE1394_MATCH_VENDOR_ID |
304 IEEE1394_MATCH_MODEL_ID,
305 .vendor_id = OUI_TCELECTRONIC,
306 .model_id = 0x000021,
307 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
309 /* TC Electronic Studio Konnekt 48. */
311 .match_flags = IEEE1394_MATCH_VENDOR_ID |
312 IEEE1394_MATCH_MODEL_ID,
313 .vendor_id = OUI_TCELECTRONIC,
314 .model_id = 0x000022,
315 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
317 /* TC Electronic Konnekt Live. */
319 .match_flags = IEEE1394_MATCH_VENDOR_ID |
320 IEEE1394_MATCH_MODEL_ID,
321 .vendor_id = OUI_TCELECTRONIC,
322 .model_id = 0x000023,
323 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
325 /* TC Electronic Desktop Konnekt 6. */
327 .match_flags = IEEE1394_MATCH_VENDOR_ID |
328 IEEE1394_MATCH_MODEL_ID,
329 .vendor_id = OUI_TCELECTRONIC,
330 .model_id = 0x000024,
331 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
333 /* TC Electronic Impact Twin. */
335 .match_flags = IEEE1394_MATCH_VENDOR_ID |
336 IEEE1394_MATCH_MODEL_ID,
337 .vendor_id = OUI_TCELECTRONIC,
338 .model_id = 0x000027,
339 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
341 /* TC Electronic Digital Konnekt x32. */
343 .match_flags = IEEE1394_MATCH_VENDOR_ID |
344 IEEE1394_MATCH_MODEL_ID,
345 .vendor_id = OUI_TCELECTRONIC,
346 .model_id = 0x000030,
347 .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
349 /* Alesis iO14/iO26. */
351 .match_flags = IEEE1394_MATCH_VENDOR_ID |
352 IEEE1394_MATCH_MODEL_ID,
353 .vendor_id = OUI_ALESIS,
354 .model_id = MODEL_ALESIS_IO_BOTH,
355 .driver_data = (kernel_ulong_t)snd_dice_detect_alesis_formats,
357 /* Mytek Stereo 192 DSD-DAC. */
359 .match_flags = IEEE1394_MATCH_VENDOR_ID |
360 IEEE1394_MATCH_MODEL_ID,
361 .vendor_id = OUI_MYTEK,
362 .model_id = 0x000002,
363 .driver_data = (kernel_ulong_t)snd_dice_detect_mytek_formats,
365 // Solid State Logic, Duende Classic and Mini.
366 // NOTE: each field of GUID in config ROM is not compliant to standard
369 .match_flags = IEEE1394_MATCH_VENDOR_ID |
370 IEEE1394_MATCH_MODEL_ID,
371 .vendor_id = OUI_SSL,
372 .model_id = 0x000070,
375 .match_flags = IEEE1394_MATCH_VERSION,
376 .version = DICE_INTERFACE,
380 MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
382 static struct fw_driver dice_driver = {
384 .owner = THIS_MODULE,
385 .name = KBUILD_MODNAME,
389 .update = dice_bus_reset,
390 .remove = dice_remove,
391 .id_table = dice_id_table,
394 static int __init alsa_dice_init(void)
396 return driver_register(&dice_driver.driver);
399 static void __exit alsa_dice_exit(void)
401 driver_unregister(&dice_driver.driver);
404 module_init(alsa_dice_init);
405 module_exit(alsa_dice_exit);