1 // SPDX-License-Identifier: GPL-2.0-only
3 * digi00x.c - a part of driver for Digidesign Digi 002/003 family
5 * Copyright (c) 2014-2015 Takashi Sakamoto
10 MODULE_DESCRIPTION("Digidesign Digi 002/003 family Driver");
11 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
12 MODULE_LICENSE("GPL");
14 #define VENDOR_DIGIDESIGN 0x00a07e
15 #define MODEL_CONSOLE 0x000001
16 #define MODEL_RACK 0x000002
17 #define SPEC_VERSION 0x000001
19 static int name_card(struct snd_dg00x *dg00x)
21 struct fw_device *fw_dev = fw_parent_device(dg00x->unit);
26 err = fw_csr_string(dg00x->unit->directory, CSR_MODEL, name,
31 model = skip_spaces(name);
33 strcpy(dg00x->card->driver, "Digi00x");
34 strcpy(dg00x->card->shortname, model);
35 strcpy(dg00x->card->mixername, model);
36 snprintf(dg00x->card->longname, sizeof(dg00x->card->longname),
37 "Digidesign %s, GUID %08x%08x at %s, S%d", model,
38 fw_dev->config_rom[3], fw_dev->config_rom[4],
39 dev_name(&dg00x->unit->device), 100 << fw_dev->max_speed);
44 static void dg00x_card_free(struct snd_card *card)
46 struct snd_dg00x *dg00x = card->private_data;
48 snd_dg00x_stream_destroy_duplex(dg00x);
49 snd_dg00x_transaction_unregister(dg00x);
51 mutex_destroy(&dg00x->mutex);
52 fw_unit_put(dg00x->unit);
55 static int snd_dg00x_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry)
57 struct snd_card *card;
58 struct snd_dg00x *dg00x;
61 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, sizeof(*dg00x), &card);
64 card->private_free = dg00x_card_free;
66 dg00x = card->private_data;
67 dg00x->unit = fw_unit_get(unit);
68 dev_set_drvdata(&unit->device, dg00x);
71 mutex_init(&dg00x->mutex);
72 spin_lock_init(&dg00x->lock);
73 init_waitqueue_head(&dg00x->hwdep_wait);
75 dg00x->is_console = entry->model_id == MODEL_CONSOLE;
77 err = name_card(dg00x);
81 err = snd_dg00x_stream_init_duplex(dg00x);
85 snd_dg00x_proc_init(dg00x);
87 err = snd_dg00x_create_pcm_devices(dg00x);
91 err = snd_dg00x_create_midi_devices(dg00x);
95 err = snd_dg00x_create_hwdep_device(dg00x);
99 err = snd_dg00x_transaction_register(dg00x);
103 err = snd_card_register(card);
113 static void snd_dg00x_update(struct fw_unit *unit)
115 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
117 snd_dg00x_transaction_reregister(dg00x);
119 mutex_lock(&dg00x->mutex);
120 snd_dg00x_stream_update_duplex(dg00x);
121 mutex_unlock(&dg00x->mutex);
124 static void snd_dg00x_remove(struct fw_unit *unit)
126 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
128 // Block till all of ALSA character devices are released.
129 snd_card_free(dg00x->card);
132 static const struct ieee1394_device_id snd_dg00x_id_table[] = {
133 /* Both of 002/003 use the same ID. */
135 .match_flags = IEEE1394_MATCH_VENDOR_ID |
136 IEEE1394_MATCH_VERSION |
137 IEEE1394_MATCH_MODEL_ID,
138 .vendor_id = VENDOR_DIGIDESIGN,
139 .version = SPEC_VERSION,
140 .model_id = MODEL_CONSOLE,
143 .match_flags = IEEE1394_MATCH_VENDOR_ID |
144 IEEE1394_MATCH_VERSION |
145 IEEE1394_MATCH_MODEL_ID,
146 .vendor_id = VENDOR_DIGIDESIGN,
147 .version = SPEC_VERSION,
148 .model_id = MODEL_RACK,
152 MODULE_DEVICE_TABLE(ieee1394, snd_dg00x_id_table);
154 static struct fw_driver dg00x_driver = {
156 .owner = THIS_MODULE,
157 .name = KBUILD_MODNAME,
160 .probe = snd_dg00x_probe,
161 .update = snd_dg00x_update,
162 .remove = snd_dg00x_remove,
163 .id_table = snd_dg00x_id_table,
166 static int __init snd_dg00x_init(void)
168 return driver_register(&dg00x_driver.driver);
171 static void __exit snd_dg00x_exit(void)
173 driver_unregister(&dg00x_driver.driver);
176 module_init(snd_dg00x_init);
177 module_exit(snd_dg00x_exit);