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
17 #define DICE_CATEGORY_ID 0x04
18 #define WEISS_CATEGORY_ID 0x00
19 #define LOUD_CATEGORY_ID 0x10
21 static int dice_interface_check(struct fw_unit *unit)
23 static const int min_values[10] = {
30 struct fw_device *device = fw_parent_device(unit);
31 struct fw_csr_iterator it;
32 int key, val, vendor = -1, model = -1, err;
33 unsigned int category, i;
38 pointers = kmalloc_array(ARRAY_SIZE(min_values), sizeof(__be32),
44 * Check that GUID and unit directory are constructed according to DICE
45 * rules, i.e., that the specifier ID is the GUID's OUI, and that the
46 * GUID chip ID consists of the 8-bit category ID, the 10-bit product
47 * ID, and a 22-bit serial number.
49 fw_csr_iterator_init(&it, unit->directory);
50 while (fw_csr_iterator_next(&it, &key, &val)) {
52 case CSR_SPECIFIER_ID:
60 if (vendor == OUI_WEISS)
61 category = WEISS_CATEGORY_ID;
62 else if (vendor == OUI_LOUD)
63 category = LOUD_CATEGORY_ID;
65 category = DICE_CATEGORY_ID;
66 if (device->config_rom[3] != ((vendor << 8) | category) ||
67 device->config_rom[4] >> 22 != model) {
73 * Check that the sub address spaces exist and are located inside the
74 * private address space. The minimum values are chosen so that all
75 * minimally required registers are included.
77 err = snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
78 DICE_PRIVATE_SPACE, pointers,
79 sizeof(__be32) * ARRAY_SIZE(min_values), 0);
84 for (i = 0; i < ARRAY_SIZE(min_values); ++i) {
85 value = be32_to_cpu(pointers[i]);
86 if (value < min_values[i] || value >= 0x40000) {
93 * Check that the implemented DICE driver specification major version
96 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
98 be32_to_cpu(pointers[0]) * 4 + GLOBAL_VERSION,
104 if ((version & cpu_to_be32(0xff000000)) != cpu_to_be32(0x01000000)) {
105 dev_err(&unit->device,
106 "unknown DICE version: 0x%08x\n", be32_to_cpu(version));
114 static int highest_supported_mode_rate(struct snd_dice *dice,
115 unsigned int mode, unsigned int *rate)
119 for (i = ARRAY_SIZE(snd_dice_rates); i > 0; i--) {
120 *rate = snd_dice_rates[i - 1];
121 if (snd_dice_stream_get_rate_mode(dice, *rate, &m) < 0)
132 static int dice_read_mode_params(struct snd_dice *dice, unsigned int mode)
138 if (highest_supported_mode_rate(dice, mode, &rate) < 0) {
139 dice->tx_channels[mode] = 0;
140 dice->tx_midi_ports[mode] = 0;
141 dice->rx_channels[mode] = 0;
142 dice->rx_midi_ports[mode] = 0;
146 err = snd_dice_transaction_set_rate(dice, rate);
150 err = snd_dice_transaction_read_tx(dice, TX_NUMBER_AUDIO,
151 values, sizeof(values));
155 dice->tx_channels[mode] = be32_to_cpu(values[0]);
156 dice->tx_midi_ports[mode] = be32_to_cpu(values[1]);
158 err = snd_dice_transaction_read_rx(dice, RX_NUMBER_AUDIO,
159 values, sizeof(values));
163 dice->rx_channels[mode] = be32_to_cpu(values[0]);
164 dice->rx_midi_ports[mode] = be32_to_cpu(values[1]);
169 static int dice_read_params(struct snd_dice *dice)
174 /* some very old firmwares don't tell about their clock support */
175 if (dice->clock_caps > 0) {
176 err = snd_dice_transaction_read_global(dice,
177 GLOBAL_CLOCK_CAPABILITIES,
181 dice->clock_caps = be32_to_cpu(value);
183 /* this should be supported by any device */
184 dice->clock_caps = CLOCK_CAP_RATE_44100 |
185 CLOCK_CAP_RATE_48000 |
186 CLOCK_CAP_SOURCE_ARX1 |
187 CLOCK_CAP_SOURCE_INTERNAL;
190 for (mode = 2; mode >= 0; --mode) {
191 err = dice_read_mode_params(dice, mode);
199 static void dice_card_strings(struct snd_dice *dice)
201 struct snd_card *card = dice->card;
202 struct fw_device *dev = fw_parent_device(dice->unit);
203 char vendor[32], model[32];
207 strcpy(card->driver, "DICE");
209 strcpy(card->shortname, "DICE");
210 BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
211 err = snd_dice_transaction_read_global(dice, GLOBAL_NICK_NAME,
213 sizeof(card->shortname));
215 /* DICE strings are returned in "always-wrong" endianness */
216 BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
217 for (i = 0; i < sizeof(card->shortname); i += 4)
218 swab32s((u32 *)&card->shortname[i]);
219 card->shortname[sizeof(card->shortname) - 1] = '\0';
223 fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
225 fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
226 snprintf(card->longname, sizeof(card->longname),
227 "%s %s (serial %u) at %s, S%d",
228 vendor, model, dev->config_rom[4] & 0x3fffff,
229 dev_name(&dice->unit->device), 100 << dev->max_speed);
231 strcpy(card->mixername, "DICE");
235 * This module releases the FireWire unit data after all ALSA character devices
236 * are released by applications. This is for releasing stream data or finishing
237 * transactions safely. Thus at returning from .remove(), this module still keep
238 * references for the unit.
240 static void dice_card_free(struct snd_card *card)
242 struct snd_dice *dice = card->private_data;
244 snd_dice_stream_destroy_duplex(dice);
245 snd_dice_transaction_destroy(dice);
246 fw_unit_put(dice->unit);
248 mutex_destroy(&dice->mutex);
251 static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
253 struct snd_card *card;
254 struct snd_dice *dice;
257 err = dice_interface_check(unit);
261 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
262 sizeof(*dice), &card);
266 dice = card->private_data;
268 dice->unit = fw_unit_get(unit);
269 card->private_free = dice_card_free;
271 spin_lock_init(&dice->lock);
272 mutex_init(&dice->mutex);
273 init_completion(&dice->clock_accepted);
274 init_waitqueue_head(&dice->hwdep_wait);
276 err = snd_dice_transaction_init(dice);
280 err = dice_read_params(dice);
284 dice_card_strings(dice);
286 err = snd_dice_create_pcm(dice);
290 err = snd_dice_create_hwdep(dice);
294 snd_dice_create_proc(dice);
296 err = snd_dice_create_midi(dice);
300 err = snd_dice_stream_init_duplex(dice);
304 err = snd_card_register(card);
306 snd_dice_stream_destroy_duplex(dice);
310 dev_set_drvdata(&unit->device, dice);
318 static void dice_remove(struct fw_unit *unit)
320 struct snd_dice *dice = dev_get_drvdata(&unit->device);
322 /* No need to wait for releasing card object in this context. */
323 snd_card_free_when_closed(dice->card);
326 static void dice_bus_reset(struct fw_unit *unit)
328 struct snd_dice *dice = dev_get_drvdata(&unit->device);
330 /* The handler address register becomes initialized. */
331 snd_dice_transaction_reinit(dice);
333 mutex_lock(&dice->mutex);
334 snd_dice_stream_update_duplex(dice);
335 mutex_unlock(&dice->mutex);
338 #define DICE_INTERFACE 0x000001
340 static const struct ieee1394_device_id dice_id_table[] = {
342 .match_flags = IEEE1394_MATCH_VERSION,
343 .version = DICE_INTERFACE,
347 MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
349 static struct fw_driver dice_driver = {
351 .owner = THIS_MODULE,
352 .name = KBUILD_MODNAME,
356 .update = dice_bus_reset,
357 .remove = dice_remove,
358 .id_table = dice_id_table,
361 static int __init alsa_dice_init(void)
363 return driver_register(&dice_driver.driver);
366 static void __exit alsa_dice_exit(void)
368 driver_unregister(&dice_driver.driver);
371 module_init(alsa_dice_init);
372 module_exit(alsa_dice_exit);