^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * TC Applied Technologies Digital Interface Communications Engine driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "dice.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) MODULE_DESCRIPTION("DICE driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define OUI_WEISS 0x001c6a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define OUI_LOUD 0x000ff2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define OUI_FOCUSRITE 0x00130e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define OUI_TCELECTRONIC 0x000166
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define OUI_ALESIS 0x000595
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define OUI_MAUDIO 0x000d6c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define OUI_MYTEK 0x001ee8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define OUI_SSL 0x0050c2 // Actually ID reserved by IEEE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define OUI_PRESONUS 0x000a92
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define DICE_CATEGORY_ID 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define WEISS_CATEGORY_ID 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define LOUD_CATEGORY_ID 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define MODEL_ALESIS_IO_BOTH 0x000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static int check_dice_category(struct fw_unit *unit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct fw_device *device = fw_parent_device(unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct fw_csr_iterator it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int key, val, vendor = -1, model = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned int category;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * Check that GUID and unit directory are constructed according to DICE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * rules, i.e., that the specifier ID is the GUID's OUI, and that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * GUID chip ID consists of the 8-bit category ID, the 10-bit product
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * ID, and a 22-bit serial number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) fw_csr_iterator_init(&it, unit->directory);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) while (fw_csr_iterator_next(&it, &key, &val)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) switch (key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) case CSR_SPECIFIER_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) vendor = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) case CSR_MODEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) model = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (vendor == OUI_WEISS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) category = WEISS_CATEGORY_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) else if (vendor == OUI_LOUD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) category = LOUD_CATEGORY_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) category = DICE_CATEGORY_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (device->config_rom[3] != ((vendor << 8) | category) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) device->config_rom[4] >> 22 != model)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int check_clock_caps(struct snd_dice *dice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) __be32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* some very old firmwares don't tell about their clock support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (dice->clock_caps > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) err = snd_dice_transaction_read_global(dice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) GLOBAL_CLOCK_CAPABILITIES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) &value, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) dice->clock_caps = be32_to_cpu(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* this should be supported by any device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) dice->clock_caps = CLOCK_CAP_RATE_44100 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) CLOCK_CAP_RATE_48000 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) CLOCK_CAP_SOURCE_ARX1 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) CLOCK_CAP_SOURCE_INTERNAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static void dice_card_strings(struct snd_dice *dice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct snd_card *card = dice->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct fw_device *dev = fw_parent_device(dice->unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) char vendor[32], model[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) strcpy(card->driver, "DICE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) strcpy(card->shortname, "DICE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) err = snd_dice_transaction_read_global(dice, GLOBAL_NICK_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) card->shortname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) sizeof(card->shortname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (err >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* DICE strings are returned in "always-wrong" endianness */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) for (i = 0; i < sizeof(card->shortname); i += 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) swab32s((u32 *)&card->shortname[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) card->shortname[sizeof(card->shortname) - 1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) strcpy(vendor, "?");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) strcpy(model, "?");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) snprintf(card->longname, sizeof(card->longname),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) "%s %s (serial %u) at %s, S%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) vendor, model, dev->config_rom[4] & 0x3fffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) dev_name(&dice->unit->device), 100 << dev->max_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) strcpy(card->mixername, "DICE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static void dice_card_free(struct snd_card *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct snd_dice *dice = card->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) snd_dice_stream_destroy_duplex(dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) snd_dice_transaction_destroy(dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static void do_registration(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct snd_dice *dice = container_of(work, struct snd_dice, dwork.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (dice->registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) err = snd_card_new(&dice->unit->device, -1, NULL, THIS_MODULE, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) &dice->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) dice->card->private_free = dice_card_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) dice->card->private_data = dice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) err = snd_dice_transaction_init(dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) err = check_clock_caps(dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) dice_card_strings(dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) err = dice->detect_formats(dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) err = snd_dice_stream_init_duplex(dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) snd_dice_create_proc(dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) err = snd_dice_create_pcm(dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) err = snd_dice_create_midi(dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) err = snd_dice_create_hwdep(dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) err = snd_card_register(dice->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) dice->registered = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) snd_card_free(dice->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) dev_info(&dice->unit->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) "Sound card registration failed: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static int dice_probe(struct fw_unit *unit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) const struct ieee1394_device_id *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct snd_dice *dice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (!entry->driver_data && entry->vendor_id != OUI_SSL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) err = check_dice_category(unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* Allocate this independent of sound card instance. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) dice = devm_kzalloc(&unit->device, sizeof(struct snd_dice), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (!dice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) dice->unit = fw_unit_get(unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) dev_set_drvdata(&unit->device, dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (!entry->driver_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) dice->detect_formats = snd_dice_stream_detect_current_formats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) dice->detect_formats =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) (snd_dice_detect_formats_t)entry->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) spin_lock_init(&dice->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) mutex_init(&dice->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) init_completion(&dice->clock_accepted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) init_waitqueue_head(&dice->hwdep_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* Allocate and register this sound card later. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) INIT_DEFERRABLE_WORK(&dice->dwork, do_registration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) snd_fw_schedule_registration(unit, &dice->dwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static void dice_remove(struct fw_unit *unit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct snd_dice *dice = dev_get_drvdata(&unit->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * Confirm to stop the work for registration before the sound card is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * going to be released. The work is not scheduled again because bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * reset handler is not called anymore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) cancel_delayed_work_sync(&dice->dwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (dice->registered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) // Block till all of ALSA character devices are released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) snd_card_free(dice->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) mutex_destroy(&dice->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) fw_unit_put(dice->unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static void dice_bus_reset(struct fw_unit *unit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct snd_dice *dice = dev_get_drvdata(&unit->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) /* Postpone a workqueue for deferred registration. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (!dice->registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) snd_fw_schedule_registration(unit, &dice->dwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /* The handler address register becomes initialized. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) snd_dice_transaction_reinit(dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * After registration, userspace can start packet streaming, then this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * code block works fine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (dice->registered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) mutex_lock(&dice->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) snd_dice_stream_update_duplex(dice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) mutex_unlock(&dice->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #define DICE_INTERFACE 0x000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static const struct ieee1394_device_id dice_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* M-Audio Profire 2626 has a different value in version field. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) .vendor_id = OUI_MAUDIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) .model_id = 0x000010,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /* M-Audio Profire 610 has a different value in version field. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) .vendor_id = OUI_MAUDIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) .model_id = 0x000011,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /* TC Electronic Konnekt 24D. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) .vendor_id = OUI_TCELECTRONIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) .model_id = 0x000020,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /* TC Electronic Konnekt 8. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) .vendor_id = OUI_TCELECTRONIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) .model_id = 0x000021,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /* TC Electronic Studio Konnekt 48. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) .vendor_id = OUI_TCELECTRONIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) .model_id = 0x000022,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* TC Electronic Konnekt Live. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) .vendor_id = OUI_TCELECTRONIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .model_id = 0x000023,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /* TC Electronic Desktop Konnekt 6. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .vendor_id = OUI_TCELECTRONIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) .model_id = 0x000024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /* TC Electronic Impact Twin. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) .vendor_id = OUI_TCELECTRONIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .model_id = 0x000027,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /* TC Electronic Digital Konnekt x32. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) .vendor_id = OUI_TCELECTRONIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) .model_id = 0x000030,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) /* Alesis iO14/iO26. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) .vendor_id = OUI_ALESIS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) .model_id = MODEL_ALESIS_IO_BOTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) .driver_data = (kernel_ulong_t)snd_dice_detect_alesis_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) // Alesis MasterControl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) .vendor_id = OUI_ALESIS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) .model_id = 0x000002,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) .driver_data = (kernel_ulong_t)snd_dice_detect_alesis_mastercontrol_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /* Mytek Stereo 192 DSD-DAC. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) .vendor_id = OUI_MYTEK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) .model_id = 0x000002,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) .driver_data = (kernel_ulong_t)snd_dice_detect_mytek_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) // Solid State Logic, Duende Classic and Mini.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) // NOTE: each field of GUID in config ROM is not compliant to standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) // DICE scheme.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) .vendor_id = OUI_SSL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) .model_id = 0x000070,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) // Presonus FireStudio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) .vendor_id = OUI_PRESONUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) .model_id = 0x000008,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) .driver_data = (kernel_ulong_t)snd_dice_detect_presonus_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) .match_flags = IEEE1394_MATCH_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) .version = DICE_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) static struct fw_driver dice_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) .name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) .bus = &fw_bus_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) .probe = dice_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) .update = dice_bus_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) .remove = dice_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) .id_table = dice_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static int __init alsa_dice_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return driver_register(&dice_driver.driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static void __exit alsa_dice_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) driver_unregister(&dice_driver.driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) module_init(alsa_dice_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) module_exit(alsa_dice_exit);