1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * tascam.c - a part of driver for TASCAM FireWire series 4 * 5 * Copyright (c) 2015 Takashi Sakamoto 6 */ 7 8 #include "tascam.h" 9 10 MODULE_DESCRIPTION("TASCAM FireWire series Driver"); 11 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>"); 12 MODULE_LICENSE("GPL"); 13 14 static const struct snd_tscm_spec model_specs[] = { 15 { 16 .name = "FW-1884", 17 .has_adat = true, 18 .has_spdif = true, 19 .pcm_capture_analog_channels = 8, 20 .pcm_playback_analog_channels = 8, 21 .midi_capture_ports = 4, 22 .midi_playback_ports = 4, 23 }, 24 { 25 .name = "FW-1082", 26 .has_adat = false, 27 .has_spdif = true, 28 .pcm_capture_analog_channels = 8, 29 .pcm_playback_analog_channels = 2, 30 .midi_capture_ports = 2, 31 .midi_playback_ports = 2, 32 }, 33 { 34 .name = "FW-1804", 35 .has_adat = true, 36 .has_spdif = true, 37 .pcm_capture_analog_channels = 8, 38 .pcm_playback_analog_channels = 2, 39 .midi_capture_ports = 2, 40 .midi_playback_ports = 4, 41 }, 42 }; 43 44 static int identify_model(struct snd_tscm *tscm) 45 { 46 struct fw_device *fw_dev = fw_parent_device(tscm->unit); 47 const u32 *config_rom = fw_dev->config_rom; 48 char model[9]; 49 unsigned int i; 50 u8 c; 51 52 if (fw_dev->config_rom_length < 30) { 53 dev_err(&tscm->unit->device, 54 "Configuration ROM is too short.\n"); 55 return -ENODEV; 56 } 57 58 /* Pick up model name from certain addresses. */ 59 for (i = 0; i < 8; i++) { 60 c = config_rom[28 + i / 4] >> (24 - 8 * (i % 4)); 61 if (c == '\0') 62 break; 63 model[i] = c; 64 } 65 model[i] = '\0'; 66 67 for (i = 0; i < ARRAY_SIZE(model_specs); i++) { 68 if (strcmp(model, model_specs[i].name) == 0) { 69 tscm->spec = &model_specs[i]; 70 break; 71 } 72 } 73 if (tscm->spec == NULL) 74 return -ENODEV; 75 76 strscpy(tscm->card->driver, "FW-TASCAM"); 77 strscpy(tscm->card->shortname, model); 78 strscpy(tscm->card->mixername, model); 79 snprintf(tscm->card->longname, sizeof(tscm->card->longname), 80 "TASCAM %s, GUID %08x%08x at %s, S%d", model, 81 fw_dev->config_rom[3], fw_dev->config_rom[4], 82 dev_name(&tscm->unit->device), 100 << fw_dev->max_speed); 83 84 return 0; 85 } 86 87 static void tscm_card_free(struct snd_card *card) 88 { 89 struct snd_tscm *tscm = card->private_data; 90 91 snd_tscm_transaction_unregister(tscm); 92 snd_tscm_stream_destroy_duplex(tscm); 93 94 mutex_destroy(&tscm->mutex); 95 fw_unit_put(tscm->unit); 96 } 97 98 static int snd_tscm_probe(struct fw_unit *unit, 99 const struct ieee1394_device_id *entry) 100 { 101 struct snd_card *card; 102 struct snd_tscm *tscm; 103 int err; 104 105 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, sizeof(*tscm), &card); 106 if (err < 0) 107 return err; 108 card->private_free = tscm_card_free; 109 110 tscm = card->private_data; 111 tscm->unit = fw_unit_get(unit); 112 dev_set_drvdata(&unit->device, tscm); 113 tscm->card = card; 114 115 mutex_init(&tscm->mutex); 116 spin_lock_init(&tscm->lock); 117 init_waitqueue_head(&tscm->hwdep_wait); 118 119 err = identify_model(tscm); 120 if (err < 0) 121 goto error; 122 123 err = snd_tscm_transaction_register(tscm); 124 if (err < 0) 125 goto error; 126 127 err = snd_tscm_stream_init_duplex(tscm); 128 if (err < 0) 129 goto error; 130 131 snd_tscm_proc_init(tscm); 132 133 err = snd_tscm_create_pcm_devices(tscm); 134 if (err < 0) 135 goto error; 136 137 err = snd_tscm_create_midi_devices(tscm); 138 if (err < 0) 139 goto error; 140 141 err = snd_tscm_create_hwdep_device(tscm); 142 if (err < 0) 143 goto error; 144 145 err = snd_card_register(card); 146 if (err < 0) 147 goto error; 148 149 return 0; 150 error: 151 snd_card_free(card); 152 return err; 153 } 154 155 static void snd_tscm_update(struct fw_unit *unit) 156 { 157 struct snd_tscm *tscm = dev_get_drvdata(&unit->device); 158 159 snd_tscm_transaction_reregister(tscm); 160 161 guard(mutex)(&tscm->mutex); 162 snd_tscm_stream_update_duplex(tscm); 163 } 164 165 static void snd_tscm_remove(struct fw_unit *unit) 166 { 167 struct snd_tscm *tscm = dev_get_drvdata(&unit->device); 168 169 // Block till all of ALSA character devices are released. 170 snd_card_free(tscm->card); 171 } 172 173 static const struct ieee1394_device_id snd_tscm_id_table[] = { 174 // Tascam, FW-1884. 175 { 176 .match_flags = IEEE1394_MATCH_VENDOR_ID | 177 IEEE1394_MATCH_SPECIFIER_ID | 178 IEEE1394_MATCH_VERSION, 179 .vendor_id = 0x00022e, 180 .specifier_id = 0x00022e, 181 .version = 0x800000, 182 }, 183 // Tascam, FE-8 (.version = 0x800001) 184 // This kernel module doesn't support FE-8 because the most of features 185 // can be implemented in userspace without any specific support of this 186 // module. 187 // 188 // .version = 0x800002 is unknown. 189 // 190 // Tascam, FW-1082. 191 { 192 .match_flags = IEEE1394_MATCH_VENDOR_ID | 193 IEEE1394_MATCH_SPECIFIER_ID | 194 IEEE1394_MATCH_VERSION, 195 .vendor_id = 0x00022e, 196 .specifier_id = 0x00022e, 197 .version = 0x800003, 198 }, 199 // Tascam, FW-1804. 200 { 201 .match_flags = IEEE1394_MATCH_VENDOR_ID | 202 IEEE1394_MATCH_SPECIFIER_ID | 203 IEEE1394_MATCH_VERSION, 204 .vendor_id = 0x00022e, 205 .specifier_id = 0x00022e, 206 .version = 0x800004, 207 }, 208 {} 209 }; 210 MODULE_DEVICE_TABLE(ieee1394, snd_tscm_id_table); 211 212 static struct fw_driver tscm_driver = { 213 .driver = { 214 .owner = THIS_MODULE, 215 .name = KBUILD_MODNAME, 216 .bus = &fw_bus_type, 217 }, 218 .probe = snd_tscm_probe, 219 .update = snd_tscm_update, 220 .remove = snd_tscm_remove, 221 .id_table = snd_tscm_id_table, 222 }; 223 224 static int __init snd_tscm_init(void) 225 { 226 return driver_register(&tscm_driver.driver); 227 } 228 229 static void __exit snd_tscm_exit(void) 230 { 231 driver_unregister(&tscm_driver.driver); 232 } 233 234 module_init(snd_tscm_init); 235 module_exit(snd_tscm_exit); 236