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_free(struct snd_tscm *tscm)
90 snd_tscm_transaction_unregister(tscm);
91 snd_tscm_stream_destroy_duplex(tscm);
93 fw_unit_put(tscm->unit);
95 mutex_destroy(&tscm->mutex);
99 static void tscm_card_free(struct snd_card *card)
101 tscm_free(card->private_data);
104 static void do_registration(struct work_struct *work)
106 struct snd_tscm *tscm = container_of(work, struct snd_tscm, dwork.work);
109 err = snd_card_new(&tscm->unit->device, -1, NULL, THIS_MODULE, 0,
114 err = identify_model(tscm);
118 err = snd_tscm_transaction_register(tscm);
122 err = snd_tscm_stream_init_duplex(tscm);
126 snd_tscm_proc_init(tscm);
128 err = snd_tscm_create_pcm_devices(tscm);
132 err = snd_tscm_create_midi_devices(tscm);
136 err = snd_tscm_create_hwdep_device(tscm);
140 err = snd_card_register(tscm->card);
145 * After registered, tscm instance can be released corresponding to
146 * releasing the sound card instance.
148 tscm->card->private_free = tscm_card_free;
149 tscm->card->private_data = tscm;
150 tscm->registered = true;
154 snd_tscm_transaction_unregister(tscm);
155 snd_tscm_stream_destroy_duplex(tscm);
156 snd_card_free(tscm->card);
157 dev_info(&tscm->unit->device,
158 "Sound card registration failed: %d\n", err);
161 static int snd_tscm_probe(struct fw_unit *unit,
162 const struct ieee1394_device_id *entry)
164 struct snd_tscm *tscm;
166 /* Allocate this independent of sound card instance. */
167 tscm = kzalloc(sizeof(struct snd_tscm), GFP_KERNEL);
171 /* initialize myself */
172 tscm->unit = fw_unit_get(unit);
173 dev_set_drvdata(&unit->device, tscm);
175 mutex_init(&tscm->mutex);
176 spin_lock_init(&tscm->lock);
177 init_waitqueue_head(&tscm->hwdep_wait);
179 /* Allocate and register this sound card later. */
180 INIT_DEFERRABLE_WORK(&tscm->dwork, do_registration);
181 snd_fw_schedule_registration(unit, &tscm->dwork);
186 static void snd_tscm_update(struct fw_unit *unit)
188 struct snd_tscm *tscm = dev_get_drvdata(&unit->device);
190 /* Postpone a workqueue for deferred registration. */
191 if (!tscm->registered)
192 snd_fw_schedule_registration(unit, &tscm->dwork);
194 snd_tscm_transaction_reregister(tscm);
197 * After registration, userspace can start packet streaming, then this
198 * code block works fine.
200 if (tscm->registered) {
201 mutex_lock(&tscm->mutex);
202 snd_tscm_stream_update_duplex(tscm);
203 mutex_unlock(&tscm->mutex);
207 static void snd_tscm_remove(struct fw_unit *unit)
209 struct snd_tscm *tscm = dev_get_drvdata(&unit->device);
212 * Confirm to stop the work for registration before the sound card is
213 * going to be released. The work is not scheduled again because bus
214 * reset handler is not called anymore.
216 cancel_delayed_work_sync(&tscm->dwork);
218 if (tscm->registered) {
219 /* No need to wait for releasing card object in this context. */
220 snd_card_free_when_closed(tscm->card);
222 /* Don't forget this case. */
227 static const struct ieee1394_device_id snd_tscm_id_table[] = {
230 .match_flags = IEEE1394_MATCH_VENDOR_ID |
231 IEEE1394_MATCH_SPECIFIER_ID |
232 IEEE1394_MATCH_VERSION,
233 .vendor_id = 0x00022e,
234 .specifier_id = 0x00022e,
237 // Tascam, FE-8 (.version = 0x800001)
238 // This kernel module doesn't support FE-8 because the most of features
239 // can be implemented in userspace without any specific support of this
242 // .version = 0x800002 is unknown.
246 .match_flags = IEEE1394_MATCH_VENDOR_ID |
247 IEEE1394_MATCH_SPECIFIER_ID |
248 IEEE1394_MATCH_VERSION,
249 .vendor_id = 0x00022e,
250 .specifier_id = 0x00022e,
255 .match_flags = IEEE1394_MATCH_VENDOR_ID |
256 IEEE1394_MATCH_SPECIFIER_ID |
257 IEEE1394_MATCH_VERSION,
258 .vendor_id = 0x00022e,
259 .specifier_id = 0x00022e,
262 /* FE-08 requires reverse-engineering because it just has faders. */
265 MODULE_DEVICE_TABLE(ieee1394, snd_tscm_id_table);
267 static struct fw_driver tscm_driver = {
269 .owner = THIS_MODULE,
270 .name = "snd-firewire-tascam",
273 .probe = snd_tscm_probe,
274 .update = snd_tscm_update,
275 .remove = snd_tscm_remove,
276 .id_table = snd_tscm_id_table,
279 static int __init snd_tscm_init(void)
281 return driver_register(&tscm_driver.driver);
284 static void __exit snd_tscm_exit(void)
286 driver_unregister(&tscm_driver.driver);
289 module_init(snd_tscm_init);
290 module_exit(snd_tscm_exit);