Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * TC Applied Technologies Digital Interface Communications Engine driver |
| 3 | * |
| 4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> |
| 5 | * Licensed under the terms of the GNU General Public License, version 2. |
| 6 | */ |
| 7 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 8 | #include "dice.h" |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 9 | |
| 10 | MODULE_DESCRIPTION("DICE driver"); |
| 11 | MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); |
| 12 | MODULE_LICENSE("GPL v2"); |
| 13 | |
Clemens Ladisch | a471fcd | 2012-02-13 21:55:13 +0100 | [diff] [blame] | 14 | #define OUI_WEISS 0x001c6a |
| 15 | |
| 16 | #define DICE_CATEGORY_ID 0x04 |
| 17 | #define WEISS_CATEGORY_ID 0x00 |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 18 | |
| 19 | static int dice_interface_check(struct fw_unit *unit) |
| 20 | { |
| 21 | static const int min_values[10] = { |
| 22 | 10, 0x64 / 4, |
| 23 | 10, 0x18 / 4, |
| 24 | 10, 0x18 / 4, |
| 25 | 0, 0, |
| 26 | 0, 0, |
| 27 | }; |
| 28 | struct fw_device *device = fw_parent_device(unit); |
| 29 | struct fw_csr_iterator it; |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 30 | int key, val, vendor = -1, model = -1, err; |
Clemens Ladisch | a471fcd | 2012-02-13 21:55:13 +0100 | [diff] [blame] | 31 | unsigned int category, i; |
Takashi Sakamoto | cbc6f28 | 2015-10-18 22:39:50 +0900 | [diff] [blame] | 32 | __be32 *pointers; |
| 33 | u32 value; |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 34 | __be32 version; |
| 35 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 36 | pointers = kmalloc_array(ARRAY_SIZE(min_values), sizeof(__be32), |
| 37 | GFP_KERNEL); |
| 38 | if (pointers == NULL) |
| 39 | return -ENOMEM; |
| 40 | |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 41 | /* |
| 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 |
Clemens Ladisch | a471fcd | 2012-02-13 21:55:13 +0100 | [diff] [blame] | 44 | * GUID chip ID consists of the 8-bit category ID, the 10-bit product |
| 45 | * ID, and a 22-bit serial number. |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 46 | */ |
| 47 | fw_csr_iterator_init(&it, unit->directory); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 48 | while (fw_csr_iterator_next(&it, &key, &val)) { |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 49 | switch (key) { |
| 50 | case CSR_SPECIFIER_ID: |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 51 | vendor = val; |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 52 | break; |
| 53 | case CSR_MODEL: |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 54 | model = val; |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 55 | break; |
| 56 | } |
| 57 | } |
Clemens Ladisch | a471fcd | 2012-02-13 21:55:13 +0100 | [diff] [blame] | 58 | if (vendor == OUI_WEISS) |
| 59 | category = WEISS_CATEGORY_ID; |
| 60 | else |
| 61 | category = DICE_CATEGORY_ID; |
| 62 | if (device->config_rom[3] != ((vendor << 8) | category) || |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 63 | device->config_rom[4] >> 22 != model) { |
| 64 | err = -ENODEV; |
| 65 | goto end; |
| 66 | } |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 67 | |
| 68 | /* |
| 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. |
| 72 | */ |
| 73 | err = snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST, |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 74 | DICE_PRIVATE_SPACE, pointers, |
| 75 | sizeof(__be32) * ARRAY_SIZE(min_values), 0); |
| 76 | if (err < 0) { |
| 77 | err = -ENODEV; |
| 78 | goto end; |
| 79 | } |
| 80 | for (i = 0; i < ARRAY_SIZE(min_values); ++i) { |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 81 | value = be32_to_cpu(pointers[i]); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 82 | if (value < min_values[i] || value >= 0x40000) { |
| 83 | err = -ENODEV; |
| 84 | goto end; |
| 85 | } |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Check that the implemented DICE driver specification major version |
| 90 | * number matches. |
| 91 | */ |
| 92 | err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST, |
| 93 | DICE_PRIVATE_SPACE + |
| 94 | be32_to_cpu(pointers[0]) * 4 + GLOBAL_VERSION, |
Clemens Ladisch | 1b70485 | 2011-09-04 22:17:38 +0200 | [diff] [blame] | 95 | &version, 4, 0); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 96 | if (err < 0) { |
| 97 | err = -ENODEV; |
| 98 | goto end; |
| 99 | } |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 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)); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 103 | err = -ENODEV; |
| 104 | goto end; |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 105 | } |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 106 | end: |
| 107 | return err; |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame] | 110 | static int highest_supported_mode_rate(struct snd_dice *dice, |
| 111 | unsigned int mode, unsigned int *rate) |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 112 | { |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame] | 113 | unsigned int i, m; |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 114 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame] | 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) |
| 118 | continue; |
| 119 | if (mode == m) |
| 120 | break; |
| 121 | } |
| 122 | if (i == 0) |
| 123 | return -EINVAL; |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 124 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame] | 125 | return 0; |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 126 | } |
| 127 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 128 | static int dice_read_mode_params(struct snd_dice *dice, unsigned int mode) |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 129 | { |
| 130 | __be32 values[2]; |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame] | 131 | unsigned int rate; |
| 132 | int err; |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 133 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame] | 134 | if (highest_supported_mode_rate(dice, mode, &rate) < 0) { |
Takashi Sakamoto | 9a02843 | 2014-12-09 00:10:36 +0900 | [diff] [blame] | 135 | dice->tx_channels[mode] = 0; |
| 136 | dice->tx_midi_ports[mode] = 0; |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 137 | dice->rx_channels[mode] = 0; |
| 138 | dice->rx_midi_ports[mode] = 0; |
| 139 | return 0; |
| 140 | } |
| 141 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame] | 142 | err = snd_dice_transaction_set_rate(dice, rate); |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 143 | if (err < 0) |
| 144 | return err; |
| 145 | |
Takashi Sakamoto | 9a02843 | 2014-12-09 00:10:36 +0900 | [diff] [blame] | 146 | err = snd_dice_transaction_read_tx(dice, TX_NUMBER_AUDIO, |
| 147 | values, sizeof(values)); |
| 148 | if (err < 0) |
| 149 | return err; |
| 150 | |
| 151 | dice->tx_channels[mode] = be32_to_cpu(values[0]); |
| 152 | dice->tx_midi_ports[mode] = be32_to_cpu(values[1]); |
| 153 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 154 | err = snd_dice_transaction_read_rx(dice, RX_NUMBER_AUDIO, |
| 155 | values, sizeof(values)); |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 156 | if (err < 0) |
| 157 | return err; |
| 158 | |
| 159 | dice->rx_channels[mode] = be32_to_cpu(values[0]); |
| 160 | dice->rx_midi_ports[mode] = be32_to_cpu(values[1]); |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 165 | static int dice_read_params(struct snd_dice *dice) |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 166 | { |
Clemens Ladisch | a030199 | 2011-12-04 21:47:00 +0100 | [diff] [blame] | 167 | __be32 value; |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 168 | int mode, err; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 169 | |
Clemens Ladisch | a030199 | 2011-12-04 21:47:00 +0100 | [diff] [blame] | 170 | /* some very old firmwares don't tell about their clock support */ |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 171 | if (dice->clock_caps > 0) { |
| 172 | err = snd_dice_transaction_read_global(dice, |
| 173 | GLOBAL_CLOCK_CAPABILITIES, |
| 174 | &value, 4); |
Clemens Ladisch | a030199 | 2011-12-04 21:47:00 +0100 | [diff] [blame] | 175 | if (err < 0) |
| 176 | return err; |
| 177 | dice->clock_caps = be32_to_cpu(value); |
| 178 | } else { |
| 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; |
| 184 | } |
| 185 | |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 186 | for (mode = 2; mode >= 0; --mode) { |
| 187 | err = dice_read_mode_params(dice, mode); |
| 188 | if (err < 0) |
| 189 | return err; |
| 190 | } |
| 191 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 192 | return 0; |
| 193 | } |
| 194 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 195 | static void dice_card_strings(struct snd_dice *dice) |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 196 | { |
| 197 | struct snd_card *card = dice->card; |
| 198 | struct fw_device *dev = fw_parent_device(dice->unit); |
| 199 | char vendor[32], model[32]; |
| 200 | unsigned int i; |
| 201 | int err; |
| 202 | |
| 203 | strcpy(card->driver, "DICE"); |
| 204 | |
| 205 | strcpy(card->shortname, "DICE"); |
| 206 | BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname)); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 207 | err = snd_dice_transaction_read_global(dice, GLOBAL_NICK_NAME, |
| 208 | card->shortname, |
| 209 | sizeof(card->shortname)); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 210 | if (err >= 0) { |
| 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'; |
| 216 | } |
| 217 | |
| 218 | strcpy(vendor, "?"); |
| 219 | fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor)); |
| 220 | strcpy(model, "?"); |
| 221 | fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model)); |
| 222 | snprintf(card->longname, sizeof(card->longname), |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 223 | "%s %s (serial %u) at %s, S%d", |
| 224 | vendor, model, dev->config_rom[4] & 0x3fffff, |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 225 | dev_name(&dice->unit->device), 100 << dev->max_speed); |
| 226 | |
| 227 | strcpy(card->mixername, "DICE"); |
| 228 | } |
| 229 | |
Takashi Sakamoto | 12ed719 | 2015-02-21 23:54:57 +0900 | [diff] [blame] | 230 | /* |
| 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. |
| 235 | */ |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 236 | static void dice_card_free(struct snd_card *card) |
| 237 | { |
| 238 | struct snd_dice *dice = card->private_data; |
| 239 | |
Takashi Sakamoto | dec8431 | 2015-02-21 23:55:00 +0900 | [diff] [blame] | 240 | snd_dice_stream_destroy_duplex(dice); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 241 | snd_dice_transaction_destroy(dice); |
Takashi Sakamoto | 12ed719 | 2015-02-21 23:54:57 +0900 | [diff] [blame] | 242 | fw_unit_put(dice->unit); |
| 243 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 244 | mutex_destroy(&dice->mutex); |
| 245 | } |
| 246 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 247 | static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id) |
| 248 | { |
| 249 | struct snd_card *card; |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 250 | struct snd_dice *dice; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 251 | int err; |
| 252 | |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 253 | err = dice_interface_check(unit); |
| 254 | if (err < 0) |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 255 | goto end; |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 256 | |
Takashi Iwai | 06b45f0 | 2014-01-29 14:23:55 +0100 | [diff] [blame] | 257 | err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, |
| 258 | sizeof(*dice), &card); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 259 | if (err < 0) |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 260 | goto end; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 261 | |
| 262 | dice = card->private_data; |
| 263 | dice->card = card; |
Takashi Sakamoto | 12ed719 | 2015-02-21 23:54:57 +0900 | [diff] [blame] | 264 | dice->unit = fw_unit_get(unit); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 265 | card->private_free = dice_card_free; |
| 266 | |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 267 | spin_lock_init(&dice->lock); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 268 | mutex_init(&dice->mutex); |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 269 | init_completion(&dice->clock_accepted); |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 270 | init_waitqueue_head(&dice->hwdep_wait); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 271 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 272 | err = snd_dice_transaction_init(dice); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 273 | if (err < 0) |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 274 | goto error; |
Clemens Ladisch | 5ea4018 | 2011-12-05 22:09:42 +0100 | [diff] [blame] | 275 | |
| 276 | err = dice_read_params(dice); |
| 277 | if (err < 0) |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 278 | goto error; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 279 | |
| 280 | dice_card_strings(dice); |
| 281 | |
Takashi Sakamoto | c50fb91 | 2014-11-29 00:59:15 +0900 | [diff] [blame] | 282 | err = snd_dice_create_pcm(dice); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 283 | if (err < 0) |
| 284 | goto error; |
| 285 | |
Takashi Sakamoto | 19af57b | 2014-11-29 00:59:16 +0900 | [diff] [blame] | 286 | err = snd_dice_create_hwdep(dice); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 287 | if (err < 0) |
| 288 | goto error; |
| 289 | |
Takashi Sakamoto | 04d426a | 2014-11-29 00:59:17 +0900 | [diff] [blame] | 290 | snd_dice_create_proc(dice); |
Clemens Ladisch | c614475 | 2012-01-05 22:36:08 +0100 | [diff] [blame] | 291 | |
Takashi Sakamoto | a113ff8 | 2014-12-09 00:10:39 +0900 | [diff] [blame] | 292 | err = snd_dice_create_midi(dice); |
| 293 | if (err < 0) |
| 294 | goto error; |
| 295 | |
Takashi Sakamoto | 9a02843 | 2014-12-09 00:10:36 +0900 | [diff] [blame] | 296 | err = snd_dice_stream_init_duplex(dice); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 297 | if (err < 0) |
| 298 | goto error; |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 299 | |
| 300 | err = snd_card_register(card); |
| 301 | if (err < 0) { |
Takashi Sakamoto | 9a02843 | 2014-12-09 00:10:36 +0900 | [diff] [blame] | 302 | snd_dice_stream_destroy_duplex(dice); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 303 | goto error; |
| 304 | } |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 305 | |
| 306 | dev_set_drvdata(&unit->device, dice); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 307 | end: |
| 308 | return err; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 309 | error: |
| 310 | snd_card_free(card); |
| 311 | return err; |
| 312 | } |
| 313 | |
| 314 | static void dice_remove(struct fw_unit *unit) |
| 315 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 316 | struct snd_dice *dice = dev_get_drvdata(&unit->device); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 317 | |
Takashi Sakamoto | 12ed719 | 2015-02-21 23:54:57 +0900 | [diff] [blame] | 318 | /* No need to wait for releasing card object in this context. */ |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 319 | snd_card_free_when_closed(dice->card); |
| 320 | } |
| 321 | |
| 322 | static void dice_bus_reset(struct fw_unit *unit) |
| 323 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 324 | struct snd_dice *dice = dev_get_drvdata(&unit->device); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 325 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 326 | /* The handler address register becomes initialized. */ |
| 327 | snd_dice_transaction_reinit(dice); |
| 328 | |
Stefan Richter | a8c558f | 2011-08-27 20:05:15 +0200 | [diff] [blame] | 329 | mutex_lock(&dice->mutex); |
Takashi Sakamoto | 9a02843 | 2014-12-09 00:10:36 +0900 | [diff] [blame] | 330 | snd_dice_stream_update_duplex(dice); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 331 | mutex_unlock(&dice->mutex); |
| 332 | } |
| 333 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 334 | #define DICE_INTERFACE 0x000001 |
| 335 | |
| 336 | static const struct ieee1394_device_id dice_id_table[] = { |
| 337 | { |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 338 | .match_flags = IEEE1394_MATCH_VERSION, |
| 339 | .version = DICE_INTERFACE, |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 340 | }, |
| 341 | { } |
| 342 | }; |
| 343 | MODULE_DEVICE_TABLE(ieee1394, dice_id_table); |
| 344 | |
| 345 | static struct fw_driver dice_driver = { |
| 346 | .driver = { |
| 347 | .owner = THIS_MODULE, |
| 348 | .name = KBUILD_MODNAME, |
| 349 | .bus = &fw_bus_type, |
| 350 | }, |
| 351 | .probe = dice_probe, |
| 352 | .update = dice_bus_reset, |
| 353 | .remove = dice_remove, |
| 354 | .id_table = dice_id_table, |
| 355 | }; |
| 356 | |
| 357 | static int __init alsa_dice_init(void) |
| 358 | { |
| 359 | return driver_register(&dice_driver.driver); |
| 360 | } |
| 361 | |
| 362 | static void __exit alsa_dice_exit(void) |
| 363 | { |
| 364 | driver_unregister(&dice_driver.driver); |
| 365 | } |
| 366 | |
| 367 | module_init(alsa_dice_init); |
| 368 | module_exit(alsa_dice_exit); |