blob: 1f33b7a1fca4c3695cc663789d7eeeff135c2a83 [file] [log] [blame]
Takashi Sakamoto9edf7232015-09-30 09:39:16 +09001/*
2 * digi00x.c - a part of driver for Digidesign Digi 002/003 family
3 *
4 * Copyright (c) 2014-2015 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9#include "digi00x.h"
10
11MODULE_DESCRIPTION("Digidesign Digi 002/003 family Driver");
12MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
13MODULE_LICENSE("GPL v2");
14
15#define VENDOR_DIGIDESIGN 0x00a07e
16#define MODEL_DIGI00X 0x000002
17
18static int name_card(struct snd_dg00x *dg00x)
19{
20 struct fw_device *fw_dev = fw_parent_device(dg00x->unit);
21 char name[32] = {0};
22 char *model;
23 int err;
24
25 err = fw_csr_string(dg00x->unit->directory, CSR_MODEL, name,
26 sizeof(name));
27 if (err < 0)
28 return err;
29
30 model = skip_spaces(name);
31
32 strcpy(dg00x->card->driver, "Digi00x");
33 strcpy(dg00x->card->shortname, model);
34 strcpy(dg00x->card->mixername, model);
35 snprintf(dg00x->card->longname, sizeof(dg00x->card->longname),
36 "Digidesign %s, GUID %08x%08x at %s, S%d", model,
Takashi Sakamotobd048092015-10-18 22:39:53 +090037 fw_dev->config_rom[3], fw_dev->config_rom[4],
Takashi Sakamoto9edf7232015-09-30 09:39:16 +090038 dev_name(&dg00x->unit->device), 100 << fw_dev->max_speed);
39
40 return 0;
41}
42
43static void dg00x_card_free(struct snd_card *card)
44{
45 struct snd_dg00x *dg00x = card->private_data;
46
Takashi Sakamoto3a2a1792015-09-30 09:39:18 +090047 snd_dg00x_stream_destroy_duplex(dg00x);
Takashi Sakamoto44b73082015-09-30 09:39:22 +090048 snd_dg00x_transaction_unregister(dg00x);
Takashi Sakamoto3a2a1792015-09-30 09:39:18 +090049
Takashi Sakamoto9edf7232015-09-30 09:39:16 +090050 fw_unit_put(dg00x->unit);
51
52 mutex_destroy(&dg00x->mutex);
53}
54
55static int snd_dg00x_probe(struct fw_unit *unit,
56 const struct ieee1394_device_id *entry)
57{
58 struct snd_card *card;
59 struct snd_dg00x *dg00x;
60 int err;
61
62 /* create card */
63 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
64 sizeof(struct snd_dg00x), &card);
65 if (err < 0)
66 return err;
67 card->private_free = dg00x_card_free;
68
69 /* initialize myself */
70 dg00x = card->private_data;
71 dg00x->card = card;
72 dg00x->unit = fw_unit_get(unit);
73
74 mutex_init(&dg00x->mutex);
Takashi Sakamoto660dd3d2015-09-30 09:39:21 +090075 spin_lock_init(&dg00x->lock);
76 init_waitqueue_head(&dg00x->hwdep_wait);
Takashi Sakamoto9edf7232015-09-30 09:39:16 +090077
78 err = name_card(dg00x);
79 if (err < 0)
80 goto error;
81
Takashi Sakamoto3a2a1792015-09-30 09:39:18 +090082 err = snd_dg00x_stream_init_duplex(dg00x);
83 if (err < 0)
84 goto error;
85
Takashi Sakamoto927f17d2015-09-30 09:39:19 +090086 snd_dg00x_proc_init(dg00x);
87
Takashi Sakamoto0120d0f2015-09-30 09:39:20 +090088 err = snd_dg00x_create_pcm_devices(dg00x);
89 if (err < 0)
90 goto error;
91
Takashi Sakamoto9fbfd382015-10-11 12:30:16 +090092 err = snd_dg00x_create_midi_devices(dg00x);
93 if (err < 0)
94 goto error;
95
Takashi Sakamoto660dd3d2015-09-30 09:39:21 +090096 err = snd_dg00x_create_hwdep_device(dg00x);
97 if (err < 0)
98 goto error;
99
Takashi Sakamoto44b73082015-09-30 09:39:22 +0900100 err = snd_dg00x_transaction_register(dg00x);
101 if (err < 0)
102 goto error;
103
Takashi Sakamoto9edf7232015-09-30 09:39:16 +0900104 err = snd_card_register(card);
105 if (err < 0)
106 goto error;
107
108 dev_set_drvdata(&unit->device, dg00x);
109
110 return err;
111error:
112 snd_card_free(card);
113 return err;
114}
115
116static void snd_dg00x_update(struct fw_unit *unit)
117{
Takashi Sakamoto3a2a1792015-09-30 09:39:18 +0900118 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
119
Takashi Sakamoto44b73082015-09-30 09:39:22 +0900120 snd_dg00x_transaction_reregister(dg00x);
121
Takashi Sakamoto3a2a1792015-09-30 09:39:18 +0900122 mutex_lock(&dg00x->mutex);
123 snd_dg00x_stream_update_duplex(dg00x);
124 mutex_unlock(&dg00x->mutex);
Takashi Sakamoto9edf7232015-09-30 09:39:16 +0900125}
126
127static void snd_dg00x_remove(struct fw_unit *unit)
128{
129 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
130
131 /* No need to wait for releasing card object in this context. */
132 snd_card_free_when_closed(dg00x->card);
133}
134
135static const struct ieee1394_device_id snd_dg00x_id_table[] = {
136 /* Both of 002/003 use the same ID. */
137 {
138 .match_flags = IEEE1394_MATCH_VENDOR_ID |
139 IEEE1394_MATCH_MODEL_ID,
140 .vendor_id = VENDOR_DIGIDESIGN,
141 .model_id = MODEL_DIGI00X,
142 },
143 {}
144};
145MODULE_DEVICE_TABLE(ieee1394, snd_dg00x_id_table);
146
147static struct fw_driver dg00x_driver = {
148 .driver = {
149 .owner = THIS_MODULE,
150 .name = "snd-firewire-digi00x",
151 .bus = &fw_bus_type,
152 },
153 .probe = snd_dg00x_probe,
154 .update = snd_dg00x_update,
155 .remove = snd_dg00x_remove,
156 .id_table = snd_dg00x_id_table,
157};
158
159static int __init snd_dg00x_init(void)
160{
161 return driver_register(&dg00x_driver.driver);
162}
163
164static void __exit snd_dg00x_exit(void)
165{
166 driver_unregister(&dg00x_driver.driver);
167}
168
169module_init(snd_dg00x_init);
170module_exit(snd_dg00x_exit);