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