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 0x001486
19 #define DICE_CATEGORY_ID 0x04
20 #define WEISS_CATEGORY_ID 0x00
21 #define LOUD_CATEGORY_ID 0x10
24 * Some models support several isochronous channels, while these streams are not
25 * always available. In this case, add the model name to this list.
27 static bool force_two_pcm_support(struct fw_unit
*unit
)
29 const char *const models
[] = {
30 /* TC Electronic models. */
32 /* Focusrite models. */
41 err
= fw_csr_string(unit
->directory
, CSR_MODEL
, model
, sizeof(model
));
45 for (i
= 0; i
< ARRAY_SIZE(models
); i
++) {
46 if (strcmp(models
[i
], model
) == 0)
50 return i
< ARRAY_SIZE(models
);
53 static int check_dice_category(struct fw_unit
*unit
)
55 struct fw_device
*device
= fw_parent_device(unit
);
56 struct fw_csr_iterator it
;
57 int key
, val
, vendor
= -1, model
= -1;
58 unsigned int category
;
61 * Check that GUID and unit directory are constructed according to DICE
62 * rules, i.e., that the specifier ID is the GUID's OUI, and that the
63 * GUID chip ID consists of the 8-bit category ID, the 10-bit product
64 * ID, and a 22-bit serial number.
66 fw_csr_iterator_init(&it
, unit
->directory
);
67 while (fw_csr_iterator_next(&it
, &key
, &val
)) {
69 case CSR_SPECIFIER_ID
:
78 if (vendor
== OUI_FOCUSRITE
|| vendor
== OUI_TCELECTRONIC
) {
79 if (force_two_pcm_support(unit
))
83 if (vendor
== OUI_WEISS
)
84 category
= WEISS_CATEGORY_ID
;
85 else if (vendor
== OUI_LOUD
)
86 category
= LOUD_CATEGORY_ID
;
88 category
= DICE_CATEGORY_ID
;
89 if (device
->config_rom
[3] != ((vendor
<< 8) | category
) ||
90 device
->config_rom
[4] >> 22 != model
)
96 static int check_clock_caps(struct snd_dice
*dice
)
101 /* some very old firmwares don't tell about their clock support */
102 if (dice
->clock_caps
> 0) {
103 err
= snd_dice_transaction_read_global(dice
,
104 GLOBAL_CLOCK_CAPABILITIES
,
108 dice
->clock_caps
= be32_to_cpu(value
);
110 /* this should be supported by any device */
111 dice
->clock_caps
= CLOCK_CAP_RATE_44100
|
112 CLOCK_CAP_RATE_48000
|
113 CLOCK_CAP_SOURCE_ARX1
|
114 CLOCK_CAP_SOURCE_INTERNAL
;
120 static void dice_card_strings(struct snd_dice
*dice
)
122 struct snd_card
*card
= dice
->card
;
123 struct fw_device
*dev
= fw_parent_device(dice
->unit
);
124 char vendor
[32], model
[32];
128 strcpy(card
->driver
, "DICE");
130 strcpy(card
->shortname
, "DICE");
131 BUILD_BUG_ON(NICK_NAME_SIZE
< sizeof(card
->shortname
));
132 err
= snd_dice_transaction_read_global(dice
, GLOBAL_NICK_NAME
,
134 sizeof(card
->shortname
));
136 /* DICE strings are returned in "always-wrong" endianness */
137 BUILD_BUG_ON(sizeof(card
->shortname
) % 4 != 0);
138 for (i
= 0; i
< sizeof(card
->shortname
); i
+= 4)
139 swab32s((u32
*)&card
->shortname
[i
]);
140 card
->shortname
[sizeof(card
->shortname
) - 1] = '\0';
144 fw_csr_string(dev
->config_rom
+ 5, CSR_VENDOR
, vendor
, sizeof(vendor
));
146 fw_csr_string(dice
->unit
->directory
, CSR_MODEL
, model
, sizeof(model
));
147 snprintf(card
->longname
, sizeof(card
->longname
),
148 "%s %s (serial %u) at %s, S%d",
149 vendor
, model
, dev
->config_rom
[4] & 0x3fffff,
150 dev_name(&dice
->unit
->device
), 100 << dev
->max_speed
);
152 strcpy(card
->mixername
, "DICE");
155 static void dice_free(struct snd_dice
*dice
)
157 snd_dice_stream_destroy_duplex(dice
);
158 snd_dice_transaction_destroy(dice
);
159 fw_unit_put(dice
->unit
);
161 mutex_destroy(&dice
->mutex
);
166 * This module releases the FireWire unit data after all ALSA character devices
167 * are released by applications. This is for releasing stream data or finishing
168 * transactions safely. Thus at returning from .remove(), this module still keep
169 * references for the unit.
171 static void dice_card_free(struct snd_card
*card
)
173 dice_free(card
->private_data
);
176 static void do_registration(struct work_struct
*work
)
178 struct snd_dice
*dice
= container_of(work
, struct snd_dice
, dwork
.work
);
181 if (dice
->registered
)
184 err
= snd_card_new(&dice
->unit
->device
, -1, NULL
, THIS_MODULE
, 0,
189 if (force_two_pcm_support(dice
->unit
))
190 dice
->force_two_pcms
= true;
192 err
= snd_dice_transaction_init(dice
);
196 err
= check_clock_caps(dice
);
200 dice_card_strings(dice
);
202 err
= snd_dice_stream_init_duplex(dice
);
206 snd_dice_create_proc(dice
);
208 err
= snd_dice_create_pcm(dice
);
212 err
= snd_dice_create_midi(dice
);
216 err
= snd_dice_create_hwdep(dice
);
220 err
= snd_card_register(dice
->card
);
225 * After registered, dice instance can be released corresponding to
226 * releasing the sound card instance.
228 dice
->card
->private_free
= dice_card_free
;
229 dice
->card
->private_data
= dice
;
230 dice
->registered
= true;
234 snd_dice_stream_destroy_duplex(dice
);
235 snd_dice_transaction_destroy(dice
);
236 snd_dice_stream_destroy_duplex(dice
);
237 snd_card_free(dice
->card
);
238 dev_info(&dice
->unit
->device
,
239 "Sound card registration failed: %d\n", err
);
242 static int dice_probe(struct fw_unit
*unit
, const struct ieee1394_device_id
*id
)
244 struct snd_dice
*dice
;
247 err
= check_dice_category(unit
);
251 /* Allocate this independent of sound card instance. */
252 dice
= kzalloc(sizeof(struct snd_dice
), GFP_KERNEL
);
256 dice
->unit
= fw_unit_get(unit
);
257 dev_set_drvdata(&unit
->device
, dice
);
259 spin_lock_init(&dice
->lock
);
260 mutex_init(&dice
->mutex
);
261 init_completion(&dice
->clock_accepted
);
262 init_waitqueue_head(&dice
->hwdep_wait
);
264 /* Allocate and register this sound card later. */
265 INIT_DEFERRABLE_WORK(&dice
->dwork
, do_registration
);
266 snd_fw_schedule_registration(unit
, &dice
->dwork
);
271 static void dice_remove(struct fw_unit
*unit
)
273 struct snd_dice
*dice
= dev_get_drvdata(&unit
->device
);
276 * Confirm to stop the work for registration before the sound card is
277 * going to be released. The work is not scheduled again because bus
278 * reset handler is not called anymore.
280 cancel_delayed_work_sync(&dice
->dwork
);
282 if (dice
->registered
) {
283 /* No need to wait for releasing card object in this context. */
284 snd_card_free_when_closed(dice
->card
);
286 /* Don't forget this case. */
291 static void dice_bus_reset(struct fw_unit
*unit
)
293 struct snd_dice
*dice
= dev_get_drvdata(&unit
->device
);
295 /* Postpone a workqueue for deferred registration. */
296 if (!dice
->registered
)
297 snd_fw_schedule_registration(unit
, &dice
->dwork
);
299 /* The handler address register becomes initialized. */
300 snd_dice_transaction_reinit(dice
);
303 * After registration, userspace can start packet streaming, then this
304 * code block works fine.
306 if (dice
->registered
) {
307 mutex_lock(&dice
->mutex
);
308 snd_dice_stream_update_duplex(dice
);
309 mutex_unlock(&dice
->mutex
);
313 #define DICE_INTERFACE 0x000001
315 static const struct ieee1394_device_id dice_id_table
[] = {
317 .match_flags
= IEEE1394_MATCH_VERSION
,
318 .version
= DICE_INTERFACE
,
320 /* M-Audio Profire 610/2626 has a different value in version field. */
322 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
323 IEEE1394_MATCH_SPECIFIER_ID
,
324 .vendor_id
= 0x000d6c,
325 .specifier_id
= 0x000d6c,
329 MODULE_DEVICE_TABLE(ieee1394
, dice_id_table
);
331 static struct fw_driver dice_driver
= {
333 .owner
= THIS_MODULE
,
334 .name
= KBUILD_MODNAME
,
338 .update
= dice_bus_reset
,
339 .remove
= dice_remove
,
340 .id_table
= dice_id_table
,
343 static int __init
alsa_dice_init(void)
345 return driver_register(&dice_driver
.driver
);
348 static void __exit
alsa_dice_exit(void)
350 driver_unregister(&dice_driver
.driver
);
353 module_init(alsa_dice_init
);
354 module_exit(alsa_dice_exit
);