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
16 #define DICE_CATEGORY_ID 0x04
17 #define WEISS_CATEGORY_ID 0x00
19 static int dice_interface_check(struct fw_unit *unit)
21 static const int min_values[10] = {
28 struct fw_device *device = fw_parent_device(unit);
29 struct fw_csr_iterator it;
30 int key, val, vendor = -1, model = -1, err;
31 unsigned int category, i;
36 pointers = kmalloc_array(ARRAY_SIZE(min_values), sizeof(__be32),
42 * Check that GUID and unit directory are constructed according to DICE
43 * rules, i.e., that the specifier ID is the GUID's OUI, and that the
44 * GUID chip ID consists of the 8-bit category ID, the 10-bit product
45 * ID, and a 22-bit serial number.
47 fw_csr_iterator_init(&it, unit->directory);
48 while (fw_csr_iterator_next(&it, &key, &val)) {
50 case CSR_SPECIFIER_ID:
58 if (vendor == OUI_WEISS)
59 category = WEISS_CATEGORY_ID;
61 category = DICE_CATEGORY_ID;
62 if (device->config_rom[3] != ((vendor << 8) | category) ||
63 device->config_rom[4] >> 22 != model) {
69 * Check that the sub address spaces exist and are located inside the
70 * private address space. The minimum values are chosen so that all
71 * minimally required registers are included.
73 err = snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
74 DICE_PRIVATE_SPACE, pointers,
75 sizeof(__be32) * ARRAY_SIZE(min_values), 0);
80 for (i = 0; i < ARRAY_SIZE(min_values); ++i) {
81 value = be32_to_cpu(pointers[i]);
82 if (value < min_values[i] || value >= 0x40000) {
89 * Check that the implemented DICE driver specification major version
92 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
94 be32_to_cpu(pointers[0]) * 4 + GLOBAL_VERSION,
100 if ((version & cpu_to_be32(0xff000000)) != cpu_to_be32(0x01000000)) {
101 dev_err(&unit->device,
102 "unknown DICE version: 0x%08x\n", be32_to_cpu(version));
110 static int highest_supported_mode_rate(struct snd_dice *dice,
111 unsigned int mode, unsigned int *rate)
115 for (i = ARRAY_SIZE(snd_dice_rates); i > 0; i--) {
116 *rate = snd_dice_rates[i - 1];
117 if (snd_dice_stream_get_rate_mode(dice, *rate, &m) < 0)
128 static int dice_read_mode_params(struct snd_dice *dice, unsigned int mode)
134 if (highest_supported_mode_rate(dice, mode, &rate) < 0) {
135 dice->tx_channels[mode] = 0;
136 dice->tx_midi_ports[mode] = 0;
137 dice->rx_channels[mode] = 0;
138 dice->rx_midi_ports[mode] = 0;
142 err = snd_dice_transaction_set_rate(dice, rate);
146 err = snd_dice_transaction_read_tx(dice, TX_NUMBER_AUDIO,
147 values, sizeof(values));
151 dice->tx_channels[mode] = be32_to_cpu(values[0]);
152 dice->tx_midi_ports[mode] = be32_to_cpu(values[1]);
154 err = snd_dice_transaction_read_rx(dice, RX_NUMBER_AUDIO,
155 values, sizeof(values));
159 dice->rx_channels[mode] = be32_to_cpu(values[0]);
160 dice->rx_midi_ports[mode] = be32_to_cpu(values[1]);
165 static int dice_read_params(struct snd_dice *dice)
170 /* some very old firmwares don't tell about their clock support */
171 if (dice->clock_caps > 0) {
172 err = snd_dice_transaction_read_global(dice,
173 GLOBAL_CLOCK_CAPABILITIES,
177 dice->clock_caps = be32_to_cpu(value);
179 /* this should be supported by any device */
180 dice->clock_caps = CLOCK_CAP_RATE_44100 |
181 CLOCK_CAP_RATE_48000 |
182 CLOCK_CAP_SOURCE_ARX1 |
183 CLOCK_CAP_SOURCE_INTERNAL;
186 for (mode = 2; mode >= 0; --mode) {
187 err = dice_read_mode_params(dice, mode);
195 static void dice_card_strings(struct snd_dice *dice)
197 struct snd_card *card = dice->card;
198 struct fw_device *dev = fw_parent_device(dice->unit);
199 char vendor[32], model[32];
203 strcpy(card->driver, "DICE");
205 strcpy(card->shortname, "DICE");
206 BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
207 err = snd_dice_transaction_read_global(dice, GLOBAL_NICK_NAME,
209 sizeof(card->shortname));
211 /* DICE strings are returned in "always-wrong" endianness */
212 BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
213 for (i = 0; i < sizeof(card->shortname); i += 4)
214 swab32s((u32 *)&card->shortname[i]);
215 card->shortname[sizeof(card->shortname) - 1] = '\0';
219 fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
221 fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
222 snprintf(card->longname, sizeof(card->longname),
223 "%s %s (serial %u) at %s, S%d",
224 vendor, model, dev->config_rom[4] & 0x3fffff,
225 dev_name(&dice->unit->device), 100 << dev->max_speed);
227 strcpy(card->mixername, "DICE");
231 * This module releases the FireWire unit data after all ALSA character devices
232 * are released by applications. This is for releasing stream data or finishing
233 * transactions safely. Thus at returning from .remove(), this module still keep
234 * references for the unit.
236 static void dice_card_free(struct snd_card *card)
238 struct snd_dice *dice = card->private_data;
240 snd_dice_stream_destroy_duplex(dice);
241 snd_dice_transaction_destroy(dice);
242 fw_unit_put(dice->unit);
244 mutex_destroy(&dice->mutex);
247 static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
249 struct snd_card *card;
250 struct snd_dice *dice;
253 err = dice_interface_check(unit);
257 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
258 sizeof(*dice), &card);
262 dice = card->private_data;
264 dice->unit = fw_unit_get(unit);
265 card->private_free = dice_card_free;
267 spin_lock_init(&dice->lock);
268 mutex_init(&dice->mutex);
269 init_completion(&dice->clock_accepted);
270 init_waitqueue_head(&dice->hwdep_wait);
272 err = snd_dice_transaction_init(dice);
276 err = dice_read_params(dice);
280 dice_card_strings(dice);
282 err = snd_dice_create_pcm(dice);
286 err = snd_dice_create_hwdep(dice);
290 snd_dice_create_proc(dice);
292 err = snd_dice_create_midi(dice);
296 err = snd_dice_stream_init_duplex(dice);
300 err = snd_card_register(card);
302 snd_dice_stream_destroy_duplex(dice);
306 dev_set_drvdata(&unit->device, dice);
314 static void dice_remove(struct fw_unit *unit)
316 struct snd_dice *dice = dev_get_drvdata(&unit->device);
318 /* No need to wait for releasing card object in this context. */
319 snd_card_free_when_closed(dice->card);
322 static void dice_bus_reset(struct fw_unit *unit)
324 struct snd_dice *dice = dev_get_drvdata(&unit->device);
326 /* The handler address register becomes initialized. */
327 snd_dice_transaction_reinit(dice);
329 mutex_lock(&dice->mutex);
330 snd_dice_stream_update_duplex(dice);
331 mutex_unlock(&dice->mutex);
334 #define DICE_INTERFACE 0x000001
336 static const struct ieee1394_device_id dice_id_table[] = {
338 .match_flags = IEEE1394_MATCH_VERSION,
339 .version = DICE_INTERFACE,
343 MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
345 static struct fw_driver dice_driver = {
347 .owner = THIS_MODULE,
348 .name = KBUILD_MODNAME,
352 .update = dice_bus_reset,
353 .remove = dice_remove,
354 .id_table = dice_id_table,
357 static int __init alsa_dice_init(void)
359 return driver_register(&dice_driver.driver);
362 static void __exit alsa_dice_exit(void)
364 driver_unregister(&dice_driver.driver);
367 module_init(alsa_dice_init);
368 module_exit(alsa_dice_exit);