2 * digi00x.c - a part of driver for Digidesign Digi 002/003 family
4 * Copyright (c) 2014-2015 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
11 MODULE_DESCRIPTION("Digidesign Digi 002/003 family Driver");
12 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
13 MODULE_LICENSE("GPL v2");
15 #define VENDOR_DIGIDESIGN 0x00a07e
16 #define MODEL_CONSOLE 0x000001
17 #define MODEL_RACK 0x000002
18 #define SPEC_VERSION 0x000001
20 static int name_card(struct snd_dg00x *dg00x)
22 struct fw_device *fw_dev = fw_parent_device(dg00x->unit);
27 err = fw_csr_string(dg00x->unit->directory, CSR_MODEL, name,
32 model = skip_spaces(name);
34 strcpy(dg00x->card->driver, "Digi00x");
35 strcpy(dg00x->card->shortname, model);
36 strcpy(dg00x->card->mixername, model);
37 snprintf(dg00x->card->longname, sizeof(dg00x->card->longname),
38 "Digidesign %s, GUID %08x%08x at %s, S%d", model,
39 fw_dev->config_rom[3], fw_dev->config_rom[4],
40 dev_name(&dg00x->unit->device), 100 << fw_dev->max_speed);
45 static void dg00x_free(struct snd_dg00x *dg00x)
47 snd_dg00x_stream_destroy_duplex(dg00x);
48 snd_dg00x_transaction_unregister(dg00x);
50 fw_unit_put(dg00x->unit);
52 mutex_destroy(&dg00x->mutex);
56 static void dg00x_card_free(struct snd_card *card)
58 dg00x_free(card->private_data);
61 static void do_registration(struct work_struct *work)
63 struct snd_dg00x *dg00x =
64 container_of(work, struct snd_dg00x, dwork.work);
67 if (dg00x->registered)
70 err = snd_card_new(&dg00x->unit->device, -1, NULL, THIS_MODULE, 0,
75 err = name_card(dg00x);
79 err = snd_dg00x_stream_init_duplex(dg00x);
83 snd_dg00x_proc_init(dg00x);
85 err = snd_dg00x_create_pcm_devices(dg00x);
89 err = snd_dg00x_create_midi_devices(dg00x);
93 err = snd_dg00x_create_hwdep_device(dg00x);
97 err = snd_dg00x_transaction_register(dg00x);
101 err = snd_card_register(dg00x->card);
105 dg00x->card->private_free = dg00x_card_free;
106 dg00x->card->private_data = dg00x;
107 dg00x->registered = true;
111 snd_dg00x_transaction_unregister(dg00x);
112 snd_dg00x_stream_destroy_duplex(dg00x);
113 snd_card_free(dg00x->card);
114 dev_info(&dg00x->unit->device,
115 "Sound card registration failed: %d\n", err);
118 static int snd_dg00x_probe(struct fw_unit *unit,
119 const struct ieee1394_device_id *entry)
121 struct snd_dg00x *dg00x;
123 /* Allocate this independent of sound card instance. */
124 dg00x = kzalloc(sizeof(struct snd_dg00x), GFP_KERNEL);
128 dg00x->unit = fw_unit_get(unit);
129 dev_set_drvdata(&unit->device, dg00x);
131 mutex_init(&dg00x->mutex);
132 spin_lock_init(&dg00x->lock);
133 init_waitqueue_head(&dg00x->hwdep_wait);
135 dg00x->is_console = entry->model_id == MODEL_CONSOLE;
137 /* Allocate and register this sound card later. */
138 INIT_DEFERRABLE_WORK(&dg00x->dwork, do_registration);
139 snd_fw_schedule_registration(unit, &dg00x->dwork);
144 static void snd_dg00x_update(struct fw_unit *unit)
146 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
148 /* Postpone a workqueue for deferred registration. */
149 if (!dg00x->registered)
150 snd_fw_schedule_registration(unit, &dg00x->dwork);
152 snd_dg00x_transaction_reregister(dg00x);
155 * After registration, userspace can start packet streaming, then this
156 * code block works fine.
158 if (dg00x->registered) {
159 mutex_lock(&dg00x->mutex);
160 snd_dg00x_stream_update_duplex(dg00x);
161 mutex_unlock(&dg00x->mutex);
165 static void snd_dg00x_remove(struct fw_unit *unit)
167 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
170 * Confirm to stop the work for registration before the sound card is
171 * going to be released. The work is not scheduled again because bus
172 * reset handler is not called anymore.
174 cancel_delayed_work_sync(&dg00x->dwork);
176 if (dg00x->registered) {
177 /* No need to wait for releasing card object in this context. */
178 snd_card_free_when_closed(dg00x->card);
180 /* Don't forget this case. */
185 static const struct ieee1394_device_id snd_dg00x_id_table[] = {
186 /* Both of 002/003 use the same ID. */
188 .match_flags = IEEE1394_MATCH_VENDOR_ID |
189 IEEE1394_MATCH_VERSION |
190 IEEE1394_MATCH_MODEL_ID,
191 .vendor_id = VENDOR_DIGIDESIGN,
192 .version = SPEC_VERSION,
193 .model_id = MODEL_CONSOLE,
196 .match_flags = IEEE1394_MATCH_VENDOR_ID |
197 IEEE1394_MATCH_VERSION |
198 IEEE1394_MATCH_MODEL_ID,
199 .vendor_id = VENDOR_DIGIDESIGN,
200 .version = SPEC_VERSION,
201 .model_id = MODEL_RACK,
205 MODULE_DEVICE_TABLE(ieee1394, snd_dg00x_id_table);
207 static struct fw_driver dg00x_driver = {
209 .owner = THIS_MODULE,
210 .name = "snd-firewire-digi00x",
213 .probe = snd_dg00x_probe,
214 .update = snd_dg00x_update,
215 .remove = snd_dg00x_remove,
216 .id_table = snd_dg00x_id_table,
219 static int __init snd_dg00x_init(void)
221 return driver_register(&dg00x_driver.driver);
224 static void __exit snd_dg00x_exit(void)
226 driver_unregister(&dg00x_driver.driver);
229 module_init(snd_dg00x_init);
230 module_exit(snd_dg00x_exit);