1 /*
2 * tascam.c - a part of driver for TASCAM FireWire series
3 *
4 * Copyright (c) 2015 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9 #include "tascam.h"
10
11 MODULE_DESCRIPTION("TASCAM FireWire series Driver");
12 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
13 MODULE_LICENSE("GPL v2");
14
15 static struct snd_tscm_spec model_specs[] = {
16 {
17 .name = "FW-1884",
18 .has_adat = true,
19 .has_spdif = true,
20 .pcm_capture_analog_channels = 8,
21 .pcm_playback_analog_channels = 8,
22 .midi_capture_ports = 4,
23 .midi_playback_ports = 4,
24 .is_controller = true,
25 },
26 {
27 .name = "FW-1082",
28 .has_adat = false,
29 .has_spdif = true,
30 .pcm_capture_analog_channels = 8,
31 .pcm_playback_analog_channels = 2,
32 .midi_capture_ports = 2,
33 .midi_playback_ports = 2,
34 .is_controller = true,
35 },
36 /* FW-1804 may be supported. */
37 };
38
identify_model(struct snd_tscm * tscm)39 static int identify_model(struct snd_tscm *tscm)
40 {
41 struct fw_device *fw_dev = fw_parent_device(tscm->unit);
42 const u32 *config_rom = fw_dev->config_rom;
43 char model[9];
44 unsigned int i;
45 u8 c;
46
47 if (fw_dev->config_rom_length < 30) {
48 dev_err(&tscm->unit->device,
49 "Configuration ROM is too short.\n");
50 return -ENODEV;
51 }
52
53 /* Pick up model name from certain addresses. */
54 for (i = 0; i < 8; i++) {
55 c = config_rom[28 + i / 4] >> (24 - 8 * (i % 4));
56 if (c == '\0')
57 break;
58 model[i] = c;
59 }
60 model[i] = '\0';
61
62 for (i = 0; i < ARRAY_SIZE(model_specs); i++) {
63 if (strcmp(model, model_specs[i].name) == 0) {
64 tscm->spec = &model_specs[i];
65 break;
66 }
67 }
68 if (tscm->spec == NULL)
69 return -ENODEV;
70
71 strcpy(tscm->card->driver, "FW-TASCAM");
72 strcpy(tscm->card->shortname, model);
73 strcpy(tscm->card->mixername, model);
74 snprintf(tscm->card->longname, sizeof(tscm->card->longname),
75 "TASCAM %s, GUID %08x%08x at %s, S%d", model,
76 fw_dev->config_rom[3], fw_dev->config_rom[4],
77 dev_name(&tscm->unit->device), 100 << fw_dev->max_speed);
78
79 return 0;
80 }
81
tscm_card_free(struct snd_card * card)82 static void tscm_card_free(struct snd_card *card)
83 {
84 struct snd_tscm *tscm = card->private_data;
85
86 snd_tscm_transaction_unregister(tscm);
87 snd_tscm_stream_destroy_duplex(tscm);
88
89 fw_unit_put(tscm->unit);
90
91 mutex_destroy(&tscm->mutex);
92 }
93
snd_tscm_probe(struct fw_unit * unit,const struct ieee1394_device_id * entry)94 static int snd_tscm_probe(struct fw_unit *unit,
95 const struct ieee1394_device_id *entry)
96 {
97 struct snd_card *card;
98 struct snd_tscm *tscm;
99 int err;
100
101 /* create card */
102 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
103 sizeof(struct snd_tscm), &card);
104 if (err < 0)
105 return err;
106 card->private_free = tscm_card_free;
107
108 /* initialize myself */
109 tscm = card->private_data;
110 tscm->card = card;
111 tscm->unit = fw_unit_get(unit);
112
113 mutex_init(&tscm->mutex);
114 spin_lock_init(&tscm->lock);
115 init_waitqueue_head(&tscm->hwdep_wait);
116
117 err = identify_model(tscm);
118 if (err < 0)
119 goto error;
120
121 snd_tscm_proc_init(tscm);
122
123 err = snd_tscm_stream_init_duplex(tscm);
124 if (err < 0)
125 goto error;
126
127 err = snd_tscm_create_pcm_devices(tscm);
128 if (err < 0)
129 goto error;
130
131 err = snd_tscm_transaction_register(tscm);
132 if (err < 0)
133 goto error;
134
135 err = snd_tscm_create_midi_devices(tscm);
136 if (err < 0)
137 goto error;
138
139 err = snd_tscm_create_hwdep_device(tscm);
140 if (err < 0)
141 goto error;
142
143 err = snd_card_register(card);
144 if (err < 0)
145 goto error;
146
147 dev_set_drvdata(&unit->device, tscm);
148
149 return err;
150 error:
151 snd_card_free(card);
152 return err;
153 }
154
snd_tscm_update(struct fw_unit * unit)155 static void snd_tscm_update(struct fw_unit *unit)
156 {
157 struct snd_tscm *tscm = dev_get_drvdata(&unit->device);
158
159 snd_tscm_transaction_reregister(tscm);
160
161 mutex_lock(&tscm->mutex);
162 snd_tscm_stream_update_duplex(tscm);
163 mutex_unlock(&tscm->mutex);
164 }
165
snd_tscm_remove(struct fw_unit * unit)166 static void snd_tscm_remove(struct fw_unit *unit)
167 {
168 struct snd_tscm *tscm = dev_get_drvdata(&unit->device);
169
170 /* No need to wait for releasing card object in this context. */
171 snd_card_free_when_closed(tscm->card);
172 }
173
174 static const struct ieee1394_device_id snd_tscm_id_table[] = {
175 // Tascam, FW-1884.
176 {
177 .match_flags = IEEE1394_MATCH_VENDOR_ID |
178 IEEE1394_MATCH_SPECIFIER_ID |
179 IEEE1394_MATCH_VERSION,
180 .vendor_id = 0x00022e,
181 .specifier_id = 0x00022e,
182 .version = 0x800000,
183 },
184 // Tascam, FE-8 (.version = 0x800001)
185 // This kernel module doesn't support FE-8 because the most of features
186 // can be implemented in userspace without any specific support of this
187 // module.
188 //
189 // .version = 0x800002 is unknown.
190 //
191 // Tascam, FW-1082.
192 {
193 .match_flags = IEEE1394_MATCH_VENDOR_ID |
194 IEEE1394_MATCH_SPECIFIER_ID |
195 IEEE1394_MATCH_VERSION,
196 .vendor_id = 0x00022e,
197 .specifier_id = 0x00022e,
198 .version = 0x800003,
199 },
200 // Tascam, FW-1804.
201 {
202 .match_flags = IEEE1394_MATCH_VENDOR_ID |
203 IEEE1394_MATCH_SPECIFIER_ID |
204 IEEE1394_MATCH_VERSION,
205 .vendor_id = 0x00022e,
206 .specifier_id = 0x00022e,
207 .version = 0x800004,
208 },
209 /* FE-08 requires reverse-engineering because it just has faders. */
210 {}
211 };
212 MODULE_DEVICE_TABLE(ieee1394, snd_tscm_id_table);
213
214 static struct fw_driver tscm_driver = {
215 .driver = {
216 .owner = THIS_MODULE,
217 .name = "snd-firewire-tascam",
218 .bus = &fw_bus_type,
219 },
220 .probe = snd_tscm_probe,
221 .update = snd_tscm_update,
222 .remove = snd_tscm_remove,
223 .id_table = snd_tscm_id_table,
224 };
225
snd_tscm_init(void)226 static int __init snd_tscm_init(void)
227 {
228 return driver_register(&tscm_driver.driver);
229 }
230
snd_tscm_exit(void)231 static void __exit snd_tscm_exit(void)
232 {
233 driver_unregister(&tscm_driver.driver);
234 }
235
236 module_init(snd_tscm_init);
237 module_exit(snd_tscm_exit);
238