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 check_dice_category(struct fw_unit *unit)
23 struct fw_device *device = fw_parent_device(unit);
24 struct fw_csr_iterator it;
25 int key, val, vendor = -1, model = -1;
26 unsigned int category;
29 * Check that GUID and unit directory are constructed according to DICE
30 * rules, i.e., that the specifier ID is the GUID's OUI, and that the
31 * GUID chip ID consists of the 8-bit category ID, the 10-bit product
32 * ID, and a 22-bit serial number.
34 fw_csr_iterator_init(&it, unit->directory);
35 while (fw_csr_iterator_next(&it, &key, &val)) {
37 case CSR_SPECIFIER_ID:
45 if (vendor == OUI_WEISS)
46 category = WEISS_CATEGORY_ID;
47 else if (vendor == OUI_LOUD)
48 category = LOUD_CATEGORY_ID;
50 category = DICE_CATEGORY_ID;
51 if (device->config_rom[3] != ((vendor << 8) | category) ||
52 device->config_rom[4] >> 22 != model)
58 static int highest_supported_mode_rate(struct snd_dice *dice,
59 unsigned int mode, unsigned int *rate)
63 for (i = ARRAY_SIZE(snd_dice_rates); i > 0; i--) {
64 *rate = snd_dice_rates[i - 1];
65 if (snd_dice_stream_get_rate_mode(dice, *rate, &m) < 0)
76 static int dice_read_mode_params(struct snd_dice *dice, unsigned int mode)
82 if (highest_supported_mode_rate(dice, mode, &rate) < 0) {
83 dice->tx_channels[mode] = 0;
84 dice->tx_midi_ports[mode] = 0;
85 dice->rx_channels[mode] = 0;
86 dice->rx_midi_ports[mode] = 0;
90 err = snd_dice_transaction_set_rate(dice, rate);
94 err = snd_dice_transaction_read_tx(dice, TX_NUMBER_AUDIO,
95 values, sizeof(values));
99 dice->tx_channels[mode] = be32_to_cpu(values[0]);
100 dice->tx_midi_ports[mode] = be32_to_cpu(values[1]);
102 err = snd_dice_transaction_read_rx(dice, RX_NUMBER_AUDIO,
103 values, sizeof(values));
107 dice->rx_channels[mode] = be32_to_cpu(values[0]);
108 dice->rx_midi_ports[mode] = be32_to_cpu(values[1]);
113 static int dice_read_params(struct snd_dice *dice)
118 /* some very old firmwares don't tell about their clock support */
119 if (dice->clock_caps > 0) {
120 err = snd_dice_transaction_read_global(dice,
121 GLOBAL_CLOCK_CAPABILITIES,
125 dice->clock_caps = be32_to_cpu(value);
127 /* this should be supported by any device */
128 dice->clock_caps = CLOCK_CAP_RATE_44100 |
129 CLOCK_CAP_RATE_48000 |
130 CLOCK_CAP_SOURCE_ARX1 |
131 CLOCK_CAP_SOURCE_INTERNAL;
134 for (mode = 2; mode >= 0; --mode) {
135 err = dice_read_mode_params(dice, mode);
143 static void dice_card_strings(struct snd_dice *dice)
145 struct snd_card *card = dice->card;
146 struct fw_device *dev = fw_parent_device(dice->unit);
147 char vendor[32], model[32];
151 strcpy(card->driver, "DICE");
153 strcpy(card->shortname, "DICE");
154 BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
155 err = snd_dice_transaction_read_global(dice, GLOBAL_NICK_NAME,
157 sizeof(card->shortname));
159 /* DICE strings are returned in "always-wrong" endianness */
160 BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
161 for (i = 0; i < sizeof(card->shortname); i += 4)
162 swab32s((u32 *)&card->shortname[i]);
163 card->shortname[sizeof(card->shortname) - 1] = '\0';
167 fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
169 fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
170 snprintf(card->longname, sizeof(card->longname),
171 "%s %s (serial %u) at %s, S%d",
172 vendor, model, dev->config_rom[4] & 0x3fffff,
173 dev_name(&dice->unit->device), 100 << dev->max_speed);
175 strcpy(card->mixername, "DICE");
179 * This module releases the FireWire unit data after all ALSA character devices
180 * are released by applications. This is for releasing stream data or finishing
181 * transactions safely. Thus at returning from .remove(), this module still keep
182 * references for the unit.
184 static void dice_card_free(struct snd_card *card)
186 struct snd_dice *dice = card->private_data;
188 snd_dice_stream_destroy_duplex(dice);
189 snd_dice_transaction_destroy(dice);
190 fw_unit_put(dice->unit);
192 mutex_destroy(&dice->mutex);
195 static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
197 struct snd_card *card;
198 struct snd_dice *dice;
201 err = check_dice_category(unit);
205 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
206 sizeof(*dice), &card);
210 dice = card->private_data;
212 dice->unit = fw_unit_get(unit);
213 card->private_free = dice_card_free;
215 spin_lock_init(&dice->lock);
216 mutex_init(&dice->mutex);
217 init_completion(&dice->clock_accepted);
218 init_waitqueue_head(&dice->hwdep_wait);
220 err = snd_dice_transaction_init(dice);
224 err = dice_read_params(dice);
228 dice_card_strings(dice);
230 err = snd_dice_create_pcm(dice);
234 err = snd_dice_create_hwdep(dice);
238 snd_dice_create_proc(dice);
240 err = snd_dice_create_midi(dice);
244 err = snd_dice_stream_init_duplex(dice);
248 err = snd_card_register(card);
250 snd_dice_stream_destroy_duplex(dice);
254 dev_set_drvdata(&unit->device, dice);
262 static void dice_remove(struct fw_unit *unit)
264 struct snd_dice *dice = dev_get_drvdata(&unit->device);
266 /* No need to wait for releasing card object in this context. */
267 snd_card_free_when_closed(dice->card);
270 static void dice_bus_reset(struct fw_unit *unit)
272 struct snd_dice *dice = dev_get_drvdata(&unit->device);
274 /* The handler address register becomes initialized. */
275 snd_dice_transaction_reinit(dice);
277 mutex_lock(&dice->mutex);
278 snd_dice_stream_update_duplex(dice);
279 mutex_unlock(&dice->mutex);
282 #define DICE_INTERFACE 0x000001
284 static const struct ieee1394_device_id dice_id_table[] = {
286 .match_flags = IEEE1394_MATCH_VERSION,
287 .version = DICE_INTERFACE,
291 MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
293 static struct fw_driver dice_driver = {
295 .owner = THIS_MODULE,
296 .name = KBUILD_MODNAME,
300 .update = dice_bus_reset,
301 .remove = dice_remove,
302 .id_table = dice_id_table,
305 static int __init alsa_dice_init(void)
307 return driver_register(&dice_driver.driver);
310 static void __exit alsa_dice_exit(void)
312 driver_unregister(&dice_driver.driver);
315 module_init(alsa_dice_init);
316 module_exit(alsa_dice_exit);