2 * tascam.c - a part of driver for TASCAM FireWire series
4 * Copyright (c) 2015 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
11 MODULE_DESCRIPTION("TASCAM FireWire series Driver");
12 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
13 MODULE_LICENSE("GPL v2");
15 static const struct snd_tscm_spec model_specs[] = {
20 .pcm_capture_analog_channels = 8,
21 .pcm_playback_analog_channels = 8,
22 .midi_capture_ports = 4,
23 .midi_playback_ports = 4,
29 .pcm_capture_analog_channels = 8,
30 .pcm_playback_analog_channels = 2,
31 .midi_capture_ports = 2,
32 .midi_playback_ports = 2,
38 .pcm_capture_analog_channels = 8,
39 .pcm_playback_analog_channels = 2,
40 .midi_capture_ports = 2,
41 .midi_playback_ports = 4,
45 static int identify_model(struct snd_tscm *tscm)
47 struct fw_device *fw_dev = fw_parent_device(tscm->unit);
48 const u32 *config_rom = fw_dev->config_rom;
53 if (fw_dev->config_rom_length < 30) {
54 dev_err(&tscm->unit->device,
55 "Configuration ROM is too short.\n");
59 /* Pick up model name from certain addresses. */
60 for (i = 0; i < 8; i++) {
61 c = config_rom[28 + i / 4] >> (24 - 8 * (i % 4));
68 for (i = 0; i < ARRAY_SIZE(model_specs); i++) {
69 if (strcmp(model, model_specs[i].name) == 0) {
70 tscm->spec = &model_specs[i];
74 if (tscm->spec == NULL)
77 strcpy(tscm->card->driver, "FW-TASCAM");
78 strcpy(tscm->card->shortname, model);
79 strcpy(tscm->card->mixername, model);
80 snprintf(tscm->card->longname, sizeof(tscm->card->longname),
81 "TASCAM %s, GUID %08x%08x at %s, S%d", model,
82 fw_dev->config_rom[3], fw_dev->config_rom[4],
83 dev_name(&tscm->unit->device), 100 << fw_dev->max_speed);
88 static void tscm_card_free(struct snd_card *card)
90 struct snd_tscm *tscm = card->private_data;
92 snd_tscm_transaction_unregister(tscm);
93 snd_tscm_stream_destroy_duplex(tscm);
96 static void do_registration(struct work_struct *work)
98 struct snd_tscm *tscm = container_of(work, struct snd_tscm, dwork.work);
101 err = snd_card_new(&tscm->unit->device, -1, NULL, THIS_MODULE, 0,
105 tscm->card->private_free = tscm_card_free;
106 tscm->card->private_data = tscm;
108 err = identify_model(tscm);
112 err = snd_tscm_transaction_register(tscm);
116 err = snd_tscm_stream_init_duplex(tscm);
120 snd_tscm_proc_init(tscm);
122 err = snd_tscm_create_pcm_devices(tscm);
126 err = snd_tscm_create_midi_devices(tscm);
130 err = snd_tscm_create_hwdep_device(tscm);
134 err = snd_card_register(tscm->card);
138 tscm->registered = true;
142 snd_card_free(tscm->card);
143 dev_info(&tscm->unit->device,
144 "Sound card registration failed: %d\n", err);
147 static int snd_tscm_probe(struct fw_unit *unit,
148 const struct ieee1394_device_id *entry)
150 struct snd_tscm *tscm;
152 /* Allocate this independent of sound card instance. */
153 tscm = devm_kzalloc(&unit->device, sizeof(struct snd_tscm), GFP_KERNEL);
156 tscm->unit = fw_unit_get(unit);
157 dev_set_drvdata(&unit->device, tscm);
159 mutex_init(&tscm->mutex);
160 spin_lock_init(&tscm->lock);
161 init_waitqueue_head(&tscm->hwdep_wait);
163 /* Allocate and register this sound card later. */
164 INIT_DEFERRABLE_WORK(&tscm->dwork, do_registration);
165 snd_fw_schedule_registration(unit, &tscm->dwork);
170 static void snd_tscm_update(struct fw_unit *unit)
172 struct snd_tscm *tscm = dev_get_drvdata(&unit->device);
174 /* Postpone a workqueue for deferred registration. */
175 if (!tscm->registered)
176 snd_fw_schedule_registration(unit, &tscm->dwork);
178 snd_tscm_transaction_reregister(tscm);
181 * After registration, userspace can start packet streaming, then this
182 * code block works fine.
184 if (tscm->registered) {
185 mutex_lock(&tscm->mutex);
186 snd_tscm_stream_update_duplex(tscm);
187 mutex_unlock(&tscm->mutex);
191 static void snd_tscm_remove(struct fw_unit *unit)
193 struct snd_tscm *tscm = dev_get_drvdata(&unit->device);
196 * Confirm to stop the work for registration before the sound card is
197 * going to be released. The work is not scheduled again because bus
198 * reset handler is not called anymore.
200 cancel_delayed_work_sync(&tscm->dwork);
202 if (tscm->registered) {
203 // Block till all of ALSA character devices are released.
204 snd_card_free(tscm->card);
207 mutex_destroy(&tscm->mutex);
208 fw_unit_put(tscm->unit);
211 static const struct ieee1394_device_id snd_tscm_id_table[] = {
213 .match_flags = IEEE1394_MATCH_VENDOR_ID |
214 IEEE1394_MATCH_SPECIFIER_ID,
215 .vendor_id = 0x00022e,
216 .specifier_id = 0x00022e,
218 /* FE-08 requires reverse-engineering because it just has faders. */
221 MODULE_DEVICE_TABLE(ieee1394, snd_tscm_id_table);
223 static struct fw_driver tscm_driver = {
225 .owner = THIS_MODULE,
226 .name = "snd-firewire-tascam",
229 .probe = snd_tscm_probe,
230 .update = snd_tscm_update,
231 .remove = snd_tscm_remove,
232 .id_table = snd_tscm_id_table,
235 static int __init snd_tscm_init(void)
237 return driver_register(&tscm_driver.driver);
240 static void __exit snd_tscm_exit(void)
242 driver_unregister(&tscm_driver.driver);
245 module_init(snd_tscm_init);
246 module_exit(snd_tscm_exit);