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