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
22 #define DICE_CATEGORY_ID 0x04
23 #define WEISS_CATEGORY_ID 0x00
24 #define LOUD_CATEGORY_ID 0x10
26 #define MODEL_ALESIS_IO_BOTH 0x000001
28 static int check_dice_category(struct fw_unit
*unit
)
30 struct fw_device
*device
= fw_parent_device(unit
);
31 struct fw_csr_iterator it
;
32 int key
, val
, vendor
= -1, model
= -1;
33 unsigned int category
;
36 * Check that GUID and unit directory are constructed according to DICE
37 * rules, i.e., that the specifier ID is the GUID's OUI, and that the
38 * GUID chip ID consists of the 8-bit category ID, the 10-bit product
39 * ID, and a 22-bit serial number.
41 fw_csr_iterator_init(&it
, unit
->directory
);
42 while (fw_csr_iterator_next(&it
, &key
, &val
)) {
44 case CSR_SPECIFIER_ID
:
53 if (vendor
== OUI_WEISS
)
54 category
= WEISS_CATEGORY_ID
;
55 else if (vendor
== OUI_LOUD
)
56 category
= LOUD_CATEGORY_ID
;
58 category
= DICE_CATEGORY_ID
;
59 if (device
->config_rom
[3] != ((vendor
<< 8) | category
) ||
60 device
->config_rom
[4] >> 22 != model
)
66 static int check_clock_caps(struct snd_dice
*dice
)
71 /* some very old firmwares don't tell about their clock support */
72 if (dice
->clock_caps
> 0) {
73 err
= snd_dice_transaction_read_global(dice
,
74 GLOBAL_CLOCK_CAPABILITIES
,
78 dice
->clock_caps
= be32_to_cpu(value
);
80 /* this should be supported by any device */
81 dice
->clock_caps
= CLOCK_CAP_RATE_44100
|
82 CLOCK_CAP_RATE_48000
|
83 CLOCK_CAP_SOURCE_ARX1
|
84 CLOCK_CAP_SOURCE_INTERNAL
;
90 static void dice_card_strings(struct snd_dice
*dice
)
92 struct snd_card
*card
= dice
->card
;
93 struct fw_device
*dev
= fw_parent_device(dice
->unit
);
94 char vendor
[32], model
[32];
98 strcpy(card
->driver
, "DICE");
100 strcpy(card
->shortname
, "DICE");
101 BUILD_BUG_ON(NICK_NAME_SIZE
< sizeof(card
->shortname
));
102 err
= snd_dice_transaction_read_global(dice
, GLOBAL_NICK_NAME
,
104 sizeof(card
->shortname
));
106 /* DICE strings are returned in "always-wrong" endianness */
107 BUILD_BUG_ON(sizeof(card
->shortname
) % 4 != 0);
108 for (i
= 0; i
< sizeof(card
->shortname
); i
+= 4)
109 swab32s((u32
*)&card
->shortname
[i
]);
110 card
->shortname
[sizeof(card
->shortname
) - 1] = '\0';
114 fw_csr_string(dev
->config_rom
+ 5, CSR_VENDOR
, vendor
, sizeof(vendor
));
116 fw_csr_string(dice
->unit
->directory
, CSR_MODEL
, model
, sizeof(model
));
117 snprintf(card
->longname
, sizeof(card
->longname
),
118 "%s %s (serial %u) at %s, S%d",
119 vendor
, model
, dev
->config_rom
[4] & 0x3fffff,
120 dev_name(&dice
->unit
->device
), 100 << dev
->max_speed
);
122 strcpy(card
->mixername
, "DICE");
125 static void dice_free(struct snd_dice
*dice
)
127 snd_dice_stream_destroy_duplex(dice
);
128 snd_dice_transaction_destroy(dice
);
129 fw_unit_put(dice
->unit
);
131 mutex_destroy(&dice
->mutex
);
136 * This module releases the FireWire unit data after all ALSA character devices
137 * are released by applications. This is for releasing stream data or finishing
138 * transactions safely. Thus at returning from .remove(), this module still keep
139 * references for the unit.
141 static void dice_card_free(struct snd_card
*card
)
143 dice_free(card
->private_data
);
146 static void do_registration(struct work_struct
*work
)
148 struct snd_dice
*dice
= container_of(work
, struct snd_dice
, dwork
.work
);
151 if (dice
->registered
)
154 err
= snd_card_new(&dice
->unit
->device
, -1, NULL
, THIS_MODULE
, 0,
159 err
= snd_dice_transaction_init(dice
);
163 err
= check_clock_caps(dice
);
167 dice_card_strings(dice
);
169 err
= dice
->detect_formats(dice
);
173 err
= snd_dice_stream_init_duplex(dice
);
177 snd_dice_create_proc(dice
);
179 err
= snd_dice_create_pcm(dice
);
183 err
= snd_dice_create_midi(dice
);
187 err
= snd_dice_create_hwdep(dice
);
191 err
= snd_card_register(dice
->card
);
196 * After registered, dice instance can be released corresponding to
197 * releasing the sound card instance.
199 dice
->card
->private_free
= dice_card_free
;
200 dice
->card
->private_data
= dice
;
201 dice
->registered
= true;
205 snd_dice_stream_destroy_duplex(dice
);
206 snd_dice_transaction_destroy(dice
);
207 snd_dice_stream_destroy_duplex(dice
);
208 snd_card_free(dice
->card
);
209 dev_info(&dice
->unit
->device
,
210 "Sound card registration failed: %d\n", err
);
213 static int dice_probe(struct fw_unit
*unit
,
214 const struct ieee1394_device_id
*entry
)
216 struct snd_dice
*dice
;
219 if (!entry
->driver_data
) {
220 err
= check_dice_category(unit
);
225 /* Allocate this independent of sound card instance. */
226 dice
= kzalloc(sizeof(struct snd_dice
), GFP_KERNEL
);
230 dice
->unit
= fw_unit_get(unit
);
231 dev_set_drvdata(&unit
->device
, dice
);
233 if (!entry
->driver_data
) {
234 dice
->detect_formats
= snd_dice_stream_detect_current_formats
;
236 dice
->detect_formats
=
237 (snd_dice_detect_formats_t
)entry
->driver_data
;
240 spin_lock_init(&dice
->lock
);
241 mutex_init(&dice
->mutex
);
242 init_completion(&dice
->clock_accepted
);
243 init_waitqueue_head(&dice
->hwdep_wait
);
245 /* Allocate and register this sound card later. */
246 INIT_DEFERRABLE_WORK(&dice
->dwork
, do_registration
);
247 snd_fw_schedule_registration(unit
, &dice
->dwork
);
252 static void dice_remove(struct fw_unit
*unit
)
254 struct snd_dice
*dice
= dev_get_drvdata(&unit
->device
);
257 * Confirm to stop the work for registration before the sound card is
258 * going to be released. The work is not scheduled again because bus
259 * reset handler is not called anymore.
261 cancel_delayed_work_sync(&dice
->dwork
);
263 if (dice
->registered
) {
264 /* No need to wait for releasing card object in this context. */
265 snd_card_free_when_closed(dice
->card
);
267 /* Don't forget this case. */
272 static void dice_bus_reset(struct fw_unit
*unit
)
274 struct snd_dice
*dice
= dev_get_drvdata(&unit
->device
);
276 /* Postpone a workqueue for deferred registration. */
277 if (!dice
->registered
)
278 snd_fw_schedule_registration(unit
, &dice
->dwork
);
280 /* The handler address register becomes initialized. */
281 snd_dice_transaction_reinit(dice
);
284 * After registration, userspace can start packet streaming, then this
285 * code block works fine.
287 if (dice
->registered
) {
288 mutex_lock(&dice
->mutex
);
289 snd_dice_stream_update_duplex(dice
);
290 mutex_unlock(&dice
->mutex
);
294 #define DICE_INTERFACE 0x000001
296 static const struct ieee1394_device_id dice_id_table
[] = {
297 /* M-Audio Profire 2626 has a different value in version field. */
299 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
300 IEEE1394_MATCH_MODEL_ID
,
301 .vendor_id
= OUI_MAUDIO
,
302 .model_id
= 0x000010,
303 .driver_data
= (kernel_ulong_t
)snd_dice_detect_extension_formats
,
305 /* M-Audio Profire 610 has a different value in version field. */
307 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
308 IEEE1394_MATCH_MODEL_ID
,
309 .vendor_id
= OUI_MAUDIO
,
310 .model_id
= 0x000011,
311 .driver_data
= (kernel_ulong_t
)snd_dice_detect_extension_formats
,
313 /* TC Electronic Konnekt 24D. */
315 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
316 IEEE1394_MATCH_MODEL_ID
,
317 .vendor_id
= OUI_TCELECTRONIC
,
318 .model_id
= 0x000020,
319 .driver_data
= (kernel_ulong_t
)snd_dice_detect_tcelectronic_formats
,
321 /* TC Electronic Konnekt 8. */
323 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
324 IEEE1394_MATCH_MODEL_ID
,
325 .vendor_id
= OUI_TCELECTRONIC
,
326 .model_id
= 0x000021,
327 .driver_data
= (kernel_ulong_t
)snd_dice_detect_tcelectronic_formats
,
329 /* TC Electronic Studio Konnekt 48. */
331 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
332 IEEE1394_MATCH_MODEL_ID
,
333 .vendor_id
= OUI_TCELECTRONIC
,
334 .model_id
= 0x000022,
335 .driver_data
= (kernel_ulong_t
)snd_dice_detect_tcelectronic_formats
,
337 /* TC Electronic Konnekt Live. */
339 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
340 IEEE1394_MATCH_MODEL_ID
,
341 .vendor_id
= OUI_TCELECTRONIC
,
342 .model_id
= 0x000023,
343 .driver_data
= (kernel_ulong_t
)snd_dice_detect_tcelectronic_formats
,
345 /* TC Electronic Desktop Konnekt 6. */
347 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
348 IEEE1394_MATCH_MODEL_ID
,
349 .vendor_id
= OUI_TCELECTRONIC
,
350 .model_id
= 0x000024,
351 .driver_data
= (kernel_ulong_t
)snd_dice_detect_tcelectronic_formats
,
353 /* TC Electronic Impact Twin. */
355 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
356 IEEE1394_MATCH_MODEL_ID
,
357 .vendor_id
= OUI_TCELECTRONIC
,
358 .model_id
= 0x000027,
359 .driver_data
= (kernel_ulong_t
)snd_dice_detect_tcelectronic_formats
,
361 /* TC Electronic Digital Konnekt x32. */
363 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
364 IEEE1394_MATCH_MODEL_ID
,
365 .vendor_id
= OUI_TCELECTRONIC
,
366 .model_id
= 0x000030,
367 .driver_data
= (kernel_ulong_t
)snd_dice_detect_tcelectronic_formats
,
369 /* Alesis iO14/iO26. */
371 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
372 IEEE1394_MATCH_MODEL_ID
,
373 .vendor_id
= OUI_ALESIS
,
374 .model_id
= MODEL_ALESIS_IO_BOTH
,
375 .driver_data
= (kernel_ulong_t
)snd_dice_detect_alesis_formats
,
377 /* Mytek Stereo 192 DSD-DAC. */
379 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
380 IEEE1394_MATCH_MODEL_ID
,
381 .vendor_id
= OUI_MYTEK
,
382 .model_id
= 0x000002,
383 .driver_data
= (kernel_ulong_t
)snd_dice_detect_mytek_formats
,
386 .match_flags
= IEEE1394_MATCH_VERSION
,
387 .version
= DICE_INTERFACE
,
391 MODULE_DEVICE_TABLE(ieee1394
, dice_id_table
);
393 static struct fw_driver dice_driver
= {
395 .owner
= THIS_MODULE
,
396 .name
= KBUILD_MODNAME
,
400 .update
= dice_bus_reset
,
401 .remove
= dice_remove
,
402 .id_table
= dice_id_table
,
405 static int __init
alsa_dice_init(void)
407 return driver_register(&dice_driver
.driver
);
410 static void __exit
alsa_dice_exit(void)
412 driver_unregister(&dice_driver
.driver
);
415 module_init(alsa_dice_init
);
416 module_exit(alsa_dice_exit
);