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;
32 __be32 *pointers, value;
35 pointers = kmalloc_array(ARRAY_SIZE(min_values), sizeof(__be32),
41 * Check that GUID and unit directory are constructed according to DICE
42 * rules, i.e., that the specifier ID is the GUID's OUI, and that the
43 * GUID chip ID consists of the 8-bit category ID, the 10-bit product
44 * ID, and a 22-bit serial number.
46 fw_csr_iterator_init(&it, unit->directory);
47 while (fw_csr_iterator_next(&it, &key, &val)) {
49 case CSR_SPECIFIER_ID:
57 if (vendor == OUI_WEISS)
58 category = WEISS_CATEGORY_ID;
60 category = DICE_CATEGORY_ID;
61 if (device->config_rom[3] != ((vendor << 8) | category) ||
62 device->config_rom[4] >> 22 != model) {
68 * Check that the sub address spaces exist and are located inside the
69 * private address space. The minimum values are chosen so that all
70 * minimally required registers are included.
72 err = snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
73 DICE_PRIVATE_SPACE, pointers,
74 sizeof(__be32) * ARRAY_SIZE(min_values), 0);
79 for (i = 0; i < ARRAY_SIZE(min_values); ++i) {
80 value = be32_to_cpu(pointers[i]);
81 if (value < min_values[i] || value >= 0x40000) {
88 * Check that the implemented DICE driver specification major version
91 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
93 be32_to_cpu(pointers[0]) * 4 + GLOBAL_VERSION,
99 if ((version & cpu_to_be32(0xff000000)) != cpu_to_be32(0x01000000)) {
100 dev_err(&unit->device,
101 "unknown DICE version: 0x%08x\n", be32_to_cpu(version));
109 static int highest_supported_mode_rate(struct snd_dice *dice,
110 unsigned int mode, unsigned int *rate)
114 for (i = ARRAY_SIZE(snd_dice_rates); i > 0; i--) {
115 *rate = snd_dice_rates[i - 1];
116 if (snd_dice_stream_get_rate_mode(dice, *rate, &m) < 0)
127 static int dice_read_mode_params(struct snd_dice *dice, unsigned int mode)
133 if (highest_supported_mode_rate(dice, mode, &rate) < 0) {
134 dice->tx_channels[mode] = 0;
135 dice->tx_midi_ports[mode] = 0;
136 dice->rx_channels[mode] = 0;
137 dice->rx_midi_ports[mode] = 0;
141 err = snd_dice_transaction_set_rate(dice, rate);
145 err = snd_dice_transaction_read_tx(dice, TX_NUMBER_AUDIO,
146 values, sizeof(values));
150 dice->tx_channels[mode] = be32_to_cpu(values[0]);
151 dice->tx_midi_ports[mode] = be32_to_cpu(values[1]);
153 err = snd_dice_transaction_read_rx(dice, RX_NUMBER_AUDIO,
154 values, sizeof(values));
158 dice->rx_channels[mode] = be32_to_cpu(values[0]);
159 dice->rx_midi_ports[mode] = be32_to_cpu(values[1]);
164 static int dice_read_params(struct snd_dice *dice)
169 /* some very old firmwares don't tell about their clock support */
170 if (dice->clock_caps > 0) {
171 err = snd_dice_transaction_read_global(dice,
172 GLOBAL_CLOCK_CAPABILITIES,
176 dice->clock_caps = be32_to_cpu(value);
178 /* this should be supported by any device */
179 dice->clock_caps = CLOCK_CAP_RATE_44100 |
180 CLOCK_CAP_RATE_48000 |
181 CLOCK_CAP_SOURCE_ARX1 |
182 CLOCK_CAP_SOURCE_INTERNAL;
185 for (mode = 2; mode >= 0; --mode) {
186 err = dice_read_mode_params(dice, mode);
194 static void dice_card_strings(struct snd_dice *dice)
196 struct snd_card *card = dice->card;
197 struct fw_device *dev = fw_parent_device(dice->unit);
198 char vendor[32], model[32];
202 strcpy(card->driver, "DICE");
204 strcpy(card->shortname, "DICE");
205 BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
206 err = snd_dice_transaction_read_global(dice, GLOBAL_NICK_NAME,
208 sizeof(card->shortname));
210 /* DICE strings are returned in "always-wrong" endianness */
211 BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
212 for (i = 0; i < sizeof(card->shortname); i += 4)
213 swab32s((u32 *)&card->shortname[i]);
214 card->shortname[sizeof(card->shortname) - 1] = '\0';
218 fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
220 fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
221 snprintf(card->longname, sizeof(card->longname),
222 "%s %s (serial %u) at %s, S%d",
223 vendor, model, dev->config_rom[4] & 0x3fffff,
224 dev_name(&dice->unit->device), 100 << dev->max_speed);
226 strcpy(card->mixername, "DICE");
229 static void dice_card_free(struct snd_card *card)
231 struct snd_dice *dice = card->private_data;
233 snd_dice_transaction_destroy(dice);
234 mutex_destroy(&dice->mutex);
237 static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
239 struct snd_card *card;
240 struct snd_dice *dice;
243 err = dice_interface_check(unit);
247 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
248 sizeof(*dice), &card);
252 dice = card->private_data;
255 card->private_free = dice_card_free;
257 spin_lock_init(&dice->lock);
258 mutex_init(&dice->mutex);
259 init_completion(&dice->clock_accepted);
260 init_waitqueue_head(&dice->hwdep_wait);
262 err = snd_dice_transaction_init(dice);
266 err = dice_read_params(dice);
270 dice_card_strings(dice);
272 err = snd_dice_create_pcm(dice);
276 err = snd_dice_create_hwdep(dice);
280 snd_dice_create_proc(dice);
282 err = snd_dice_create_midi(dice);
286 err = snd_dice_stream_init_duplex(dice);
290 err = snd_card_register(card);
292 snd_dice_stream_destroy_duplex(dice);
296 dev_set_drvdata(&unit->device, dice);
304 static void dice_remove(struct fw_unit *unit)
306 struct snd_dice *dice = dev_get_drvdata(&unit->device);
308 snd_card_disconnect(dice->card);
310 snd_dice_stream_destroy_duplex(dice);
312 snd_card_free_when_closed(dice->card);
315 static void dice_bus_reset(struct fw_unit *unit)
317 struct snd_dice *dice = dev_get_drvdata(&unit->device);
319 /* The handler address register becomes initialized. */
320 snd_dice_transaction_reinit(dice);
322 mutex_lock(&dice->mutex);
323 snd_dice_stream_update_duplex(dice);
324 mutex_unlock(&dice->mutex);
327 #define DICE_INTERFACE 0x000001
329 static const struct ieee1394_device_id dice_id_table[] = {
331 .match_flags = IEEE1394_MATCH_VERSION,
332 .version = DICE_INTERFACE,
336 MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
338 static struct fw_driver dice_driver = {
340 .owner = THIS_MODULE,
341 .name = KBUILD_MODNAME,
345 .update = dice_bus_reset,
346 .remove = dice_remove,
347 .id_table = dice_id_table,
350 static int __init alsa_dice_init(void)
352 return driver_register(&dice_driver.driver);
355 static void __exit alsa_dice_exit(void)
357 driver_unregister(&dice_driver.driver);
360 module_init(alsa_dice_init);
361 module_exit(alsa_dice_exit);