1 /* 2 * tascam.c - a part of driver for TASCAM FireWire series 3 * 4 * Copyright (c) 2015 Takashi Sakamoto 5 * 6 * Licensed under the terms of the GNU General Public License, version 2. 7 */ 8 9 #include "tascam.h" 10 11 MODULE_DESCRIPTION("TASCAM FireWire series Driver"); 12 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>"); 13 MODULE_LICENSE("GPL v2"); 14 15 static struct snd_tscm_spec model_specs[] = { 16 { 17 .name = "FW-1884", 18 .has_adat = true, 19 .has_spdif = true, 20 .pcm_capture_analog_channels = 8, 21 .pcm_playback_analog_channels = 8, 22 .midi_capture_ports = 4, 23 .midi_playback_ports = 4, 24 .is_controller = true, 25 }, 26 { 27 .name = "FW-1082", 28 .has_adat = false, 29 .has_spdif = true, 30 .pcm_capture_analog_channels = 8, 31 .pcm_playback_analog_channels = 2, 32 .midi_capture_ports = 2, 33 .midi_playback_ports = 2, 34 .is_controller = true, 35 }, 36 /* FW-1804 may be supported. */ 37 }; 38 39 static int identify_model(struct snd_tscm *tscm) 40 { 41 struct fw_device *fw_dev = fw_parent_device(tscm->unit); 42 const u32 *config_rom = fw_dev->config_rom; 43 char model[9]; 44 unsigned int i; 45 u8 c; 46 47 if (fw_dev->config_rom_length < 30) { 48 dev_err(&tscm->unit->device, 49 "Configuration ROM is too short.\n"); 50 return -ENODEV; 51 } 52 53 /* Pick up model name from certain addresses. */ 54 for (i = 0; i < 8; i++) { 55 c = config_rom[28 + i / 4] >> (24 - 8 * (i % 4)); 56 if (c == '\0') 57 break; 58 model[i] = c; 59 } 60 model[i] = '\0'; 61 62 for (i = 0; i < ARRAY_SIZE(model_specs); i++) { 63 if (strcmp(model, model_specs[i].name) == 0) { 64 tscm->spec = &model_specs[i]; 65 break; 66 } 67 } 68 if (tscm->spec == NULL) 69 return -ENODEV; 70 71 strcpy(tscm->card->driver, "FW-TASCAM"); 72 strcpy(tscm->card->shortname, model); 73 strcpy(tscm->card->mixername, model); 74 snprintf(tscm->card->longname, sizeof(tscm->card->longname), 75 "TASCAM %s, GUID %08x%08x at %s, S%d", model, 76 fw_dev->config_rom[3], fw_dev->config_rom[4], 77 dev_name(&tscm->unit->device), 100 << fw_dev->max_speed); 78 79 return 0; 80 } 81 82 static void tscm_card_free(struct snd_card *card) 83 { 84 struct snd_tscm *tscm = card->private_data; 85 86 snd_tscm_transaction_unregister(tscm); 87 snd_tscm_stream_destroy_duplex(tscm); 88 89 fw_unit_put(tscm->unit); 90 91 mutex_destroy(&tscm->mutex); 92 } 93 94 static int snd_tscm_probe(struct fw_unit *unit, 95 const struct ieee1394_device_id *entry) 96 { 97 struct snd_card *card; 98 struct snd_tscm *tscm; 99 int err; 100 101 /* create card */ 102 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, 103 sizeof(struct snd_tscm), &card); 104 if (err < 0) 105 return err; 106 card->private_free = tscm_card_free; 107 108 /* initialize myself */ 109 tscm = card->private_data; 110 tscm->card = card; 111 tscm->unit = fw_unit_get(unit); 112 113 mutex_init(&tscm->mutex); 114 spin_lock_init(&tscm->lock); 115 init_waitqueue_head(&tscm->hwdep_wait); 116 117 err = identify_model(tscm); 118 if (err < 0) 119 goto error; 120 121 snd_tscm_proc_init(tscm); 122 123 err = snd_tscm_stream_init_duplex(tscm); 124 if (err < 0) 125 goto error; 126 127 err = snd_tscm_create_pcm_devices(tscm); 128 if (err < 0) 129 goto error; 130 131 err = snd_tscm_transaction_register(tscm); 132 if (err < 0) 133 goto error; 134 135 err = snd_tscm_create_midi_devices(tscm); 136 if (err < 0) 137 goto error; 138 139 err = snd_tscm_create_hwdep_device(tscm); 140 if (err < 0) 141 goto error; 142 143 err = snd_card_register(card); 144 if (err < 0) 145 goto error; 146 147 dev_set_drvdata(&unit->device, tscm); 148 149 return err; 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 mutex_lock(&tscm->mutex); 162 snd_tscm_stream_update_duplex(tscm); 163 mutex_unlock(&tscm->mutex); 164 } 165 166 static void snd_tscm_remove(struct fw_unit *unit) 167 { 168 struct snd_tscm *tscm = dev_get_drvdata(&unit->device); 169 170 /* No need to wait for releasing card object in this context. */ 171 snd_card_free_when_closed(tscm->card); 172 } 173 174 static const struct ieee1394_device_id snd_tscm_id_table[] = { 175 { 176 .match_flags = IEEE1394_MATCH_VENDOR_ID | 177 IEEE1394_MATCH_SPECIFIER_ID, 178 .vendor_id = 0x00022e, 179 .specifier_id = 0x00022e, 180 }, 181 /* FE-08 requires reverse-engineering because it just has faders. */ 182 {} 183 }; 184 MODULE_DEVICE_TABLE(ieee1394, snd_tscm_id_table); 185 186 static struct fw_driver tscm_driver = { 187 .driver = { 188 .owner = THIS_MODULE, 189 .name = "snd-firewire-tascam", 190 .bus = &fw_bus_type, 191 }, 192 .probe = snd_tscm_probe, 193 .update = snd_tscm_update, 194 .remove = snd_tscm_remove, 195 .id_table = snd_tscm_id_table, 196 }; 197 198 static int __init snd_tscm_init(void) 199 { 200 return driver_register(&tscm_driver.driver); 201 } 202 203 static void __exit snd_tscm_exit(void) 204 { 205 driver_unregister(&tscm_driver.driver); 206 } 207 208 module_init(snd_tscm_init); 209 module_exit(snd_tscm_exit); 210