]>
Commit | Line | Data |
---|---|---|
31ef9134 | 1 | /* |
8832c5a7 | 2 | * oxfw.c - a part of driver for OXFW970/971 based devices |
31ef9134 CL |
3 | * |
4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> | |
5 | * Licensed under the terms of the GNU General Public License, version 2. | |
6 | */ | |
7 | ||
e2786ca6 | 8 | #include "oxfw.h" |
31ef9134 CL |
9 | |
10 | #define OXFORD_FIRMWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x50000) | |
11 | /* 0x970?vvvv or 0x971?vvvv, where vvvv = firmware version */ | |
12 | ||
13 | #define OXFORD_HARDWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x90020) | |
14 | #define OXFORD_HARDWARE_ID_OXFW970 0x39443841 | |
15 | #define OXFORD_HARDWARE_ID_OXFW971 0x39373100 | |
16 | ||
ec4dba50 | 17 | #define VENDOR_LOUD 0x000ff2 |
31ef9134 | 18 | #define VENDOR_GRIFFIN 0x001292 |
ec4dba50 | 19 | #define VENDOR_BEHRINGER 0x001564 |
31ef9134 | 20 | #define VENDOR_LACIE 0x00d04b |
759a2f40 | 21 | #define VENDOR_TASCAM 0x00022e |
9e2004f9 | 22 | #define OUI_STANTON 0x001260 |
fba43f45 | 23 | #define OUI_APOGEE 0x0003db |
31ef9134 | 24 | |
13f3a46d TS |
25 | #define MODEL_SATELLITE 0x00200f |
26 | ||
31ef9134 CL |
27 | #define SPECIFIER_1394TA 0x00a02d |
28 | #define VERSION_AVC 0x010001 | |
29 | ||
8832c5a7 | 30 | MODULE_DESCRIPTION("Oxford Semiconductor FW970/971 driver"); |
31ef9134 CL |
31 | MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); |
32 | MODULE_LICENSE("GPL v2"); | |
8832c5a7 | 33 | MODULE_ALIAS("snd-firewire-speakers"); |
9e2004f9 | 34 | MODULE_ALIAS("snd-scs1x"); |
31ef9134 | 35 | |
d6ce6bbd TS |
36 | struct compat_info { |
37 | const char *driver_name; | |
38 | const char *vendor_name; | |
39 | const char *model_name; | |
40 | }; | |
41 | ||
ec4dba50 TS |
42 | static bool detect_loud_models(struct fw_unit *unit) |
43 | { | |
44 | const char *const models[] = { | |
45 | "Onyxi", | |
46 | "Onyx-i", | |
03abd33a | 47 | "Onyx 1640i", |
ec4dba50 TS |
48 | "d.Pro", |
49 | "Mackie Onyx Satellite", | |
50 | "Tapco LINK.firewire 4x6", | |
51 | "U.420"}; | |
52 | char model[32]; | |
ec4dba50 TS |
53 | int err; |
54 | ||
55 | err = fw_csr_string(unit->directory, CSR_MODEL, | |
56 | model, sizeof(model)); | |
57 | if (err < 0) | |
0d3aba30 | 58 | return false; |
ec4dba50 | 59 | |
2cc47d31 | 60 | return match_string(models, ARRAY_SIZE(models), model) >= 0; |
ec4dba50 TS |
61 | } |
62 | ||
fec7b753 | 63 | static int name_card(struct snd_oxfw *oxfw) |
31ef9134 | 64 | { |
fec7b753 | 65 | struct fw_device *fw_dev = fw_parent_device(oxfw->unit); |
d6ce6bbd | 66 | const struct compat_info *info; |
ec4dba50 TS |
67 | char vendor[24]; |
68 | char model[32]; | |
fec7b753 TS |
69 | const char *d, *v, *m; |
70 | u32 firmware; | |
31ef9134 CL |
71 | int err; |
72 | ||
ec4dba50 TS |
73 | /* get vendor name from root directory */ |
74 | err = fw_csr_string(fw_dev->config_rom + 5, CSR_VENDOR, | |
75 | vendor, sizeof(vendor)); | |
76 | if (err < 0) | |
77 | goto end; | |
78 | ||
79 | /* get model name from unit directory */ | |
80 | err = fw_csr_string(oxfw->unit->directory, CSR_MODEL, | |
81 | model, sizeof(model)); | |
82 | if (err < 0) | |
83 | goto end; | |
84 | ||
fec7b753 TS |
85 | err = snd_fw_transaction(oxfw->unit, TCODE_READ_QUADLET_REQUEST, |
86 | OXFORD_FIRMWARE_ID_ADDRESS, &firmware, 4, 0); | |
87 | if (err < 0) | |
88 | goto end; | |
89 | be32_to_cpus(&firmware); | |
90 | ||
ec4dba50 | 91 | /* to apply card definitions */ |
27e66635 TS |
92 | if (oxfw->entry->vendor_id == VENDOR_GRIFFIN || |
93 | oxfw->entry->vendor_id == VENDOR_LACIE) { | |
d6ce6bbd | 94 | info = (const struct compat_info *)oxfw->entry->driver_data; |
27e66635 TS |
95 | d = info->driver_name; |
96 | v = info->vendor_name; | |
97 | m = info->model_name; | |
ec4dba50 TS |
98 | } else { |
99 | d = "OXFW"; | |
100 | v = vendor; | |
101 | m = model; | |
102 | } | |
fec7b753 TS |
103 | |
104 | strcpy(oxfw->card->driver, d); | |
105 | strcpy(oxfw->card->mixername, m); | |
106 | strcpy(oxfw->card->shortname, m); | |
107 | ||
108 | snprintf(oxfw->card->longname, sizeof(oxfw->card->longname), | |
109 | "%s %s (OXFW%x %04x), GUID %08x%08x at %s, S%d", | |
110 | v, m, firmware >> 20, firmware & 0xffff, | |
111 | fw_dev->config_rom[3], fw_dev->config_rom[4], | |
112 | dev_name(&oxfw->unit->device), 100 << fw_dev->max_speed); | |
113 | end: | |
114 | return err; | |
31ef9134 CL |
115 | } |
116 | ||
3babca45 | 117 | static void oxfw_card_free(struct snd_card *card) |
31ef9134 | 118 | { |
3babca45 TS |
119 | struct snd_oxfw *oxfw = card->private_data; |
120 | ||
dec84316 TS |
121 | snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream); |
122 | if (oxfw->has_output) | |
123 | snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream); | |
31ef9134 CL |
124 | } |
125 | ||
5ce8cc48 | 126 | static int detect_quirks(struct snd_oxfw *oxfw) |
13f3a46d TS |
127 | { |
128 | struct fw_device *fw_dev = fw_parent_device(oxfw->unit); | |
129 | struct fw_csr_iterator it; | |
130 | int key, val; | |
131 | int vendor, model; | |
132 | ||
5ce8cc48 TS |
133 | /* |
134 | * Add ALSA control elements for two models to keep compatibility to | |
135 | * old firewire-speaker module. | |
136 | */ | |
3e2f4570 TS |
137 | if (oxfw->entry->vendor_id == VENDOR_GRIFFIN) |
138 | return snd_oxfw_add_spkr(oxfw, false); | |
139 | if (oxfw->entry->vendor_id == VENDOR_LACIE) | |
140 | return snd_oxfw_add_spkr(oxfw, true); | |
5ce8cc48 | 141 | |
9e2004f9 TS |
142 | /* |
143 | * Stanton models supports asynchronous transactions for unique MIDI | |
144 | * messages. | |
145 | */ | |
de5126cc TS |
146 | if (oxfw->entry->vendor_id == OUI_STANTON) { |
147 | /* No physical MIDI ports. */ | |
148 | oxfw->midi_input_ports = 0; | |
149 | oxfw->midi_output_ports = 0; | |
150 | ||
151 | /* Output stream exists but no data channels are useful. */ | |
152 | oxfw->has_output = false; | |
153 | ||
9e2004f9 | 154 | return snd_oxfw_scs1x_add(oxfw); |
de5126cc | 155 | } |
9e2004f9 | 156 | |
27e66635 TS |
157 | /* |
158 | * TASCAM FireOne has physical control and requires a pair of additional | |
159 | * MIDI ports. | |
160 | */ | |
161 | if (oxfw->entry->vendor_id == VENDOR_TASCAM) { | |
162 | oxfw->midi_input_ports++; | |
163 | oxfw->midi_output_ports++; | |
5ce8cc48 | 164 | return 0; |
27e66635 TS |
165 | } |
166 | ||
13f3a46d TS |
167 | /* Seek from Root Directory of Config ROM. */ |
168 | vendor = model = 0; | |
169 | fw_csr_iterator_init(&it, fw_dev->config_rom + 5); | |
170 | while (fw_csr_iterator_next(&it, &key, &val)) { | |
171 | if (key == CSR_VENDOR) | |
172 | vendor = val; | |
173 | else if (key == CSR_MODEL) | |
174 | model = val; | |
175 | } | |
176 | ||
177 | /* | |
178 | * Mackie Onyx Satellite with base station has a quirk to report a wrong | |
179 | * value in 'dbs' field of CIP header against its format information. | |
180 | */ | |
181 | if (vendor == VENDOR_LOUD && model == MODEL_SATELLITE) | |
182 | oxfw->wrong_dbs = true; | |
5ce8cc48 TS |
183 | |
184 | return 0; | |
13f3a46d TS |
185 | } |
186 | ||
6c29230e | 187 | static void do_registration(struct work_struct *work) |
31ef9134 | 188 | { |
6c29230e | 189 | struct snd_oxfw *oxfw = container_of(work, struct snd_oxfw, dwork.work); |
31ef9134 CL |
190 | int err; |
191 | ||
6c29230e TS |
192 | if (oxfw->registered) |
193 | return; | |
ec4dba50 | 194 | |
6c29230e TS |
195 | err = snd_card_new(&oxfw->unit->device, -1, NULL, THIS_MODULE, 0, |
196 | &oxfw->card); | |
31ef9134 | 197 | if (err < 0) |
6c29230e | 198 | return; |
3babca45 TS |
199 | oxfw->card->private_free = oxfw_card_free; |
200 | oxfw->card->private_data = oxfw; | |
31ef9134 | 201 | |
6c29230e TS |
202 | err = name_card(oxfw); |
203 | if (err < 0) | |
204 | goto error; | |
31ef9134 | 205 | |
3d016d57 | 206 | err = snd_oxfw_stream_discover(oxfw); |
5cd1d3f4 TS |
207 | if (err < 0) |
208 | goto error; | |
209 | ||
3d016d57 | 210 | err = detect_quirks(oxfw); |
5ce8cc48 TS |
211 | if (err < 0) |
212 | goto error; | |
13f3a46d | 213 | |
6c29230e | 214 | err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->rx_stream); |
fec7b753 TS |
215 | if (err < 0) |
216 | goto error; | |
6c29230e TS |
217 | if (oxfw->has_output) { |
218 | err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->tx_stream); | |
219 | if (err < 0) | |
220 | goto error; | |
221 | } | |
31ef9134 | 222 | |
3713d93a | 223 | err = snd_oxfw_create_pcm(oxfw); |
31ef9134 CL |
224 | if (err < 0) |
225 | goto error; | |
226 | ||
3c96101f TS |
227 | snd_oxfw_proc_init(oxfw); |
228 | ||
05588d34 TS |
229 | err = snd_oxfw_create_midi(oxfw); |
230 | if (err < 0) | |
231 | goto error; | |
232 | ||
8985f4ac TS |
233 | err = snd_oxfw_create_hwdep(oxfw); |
234 | if (err < 0) | |
235 | goto error; | |
236 | ||
6c29230e | 237 | err = snd_card_register(oxfw->card); |
31ef9134 CL |
238 | if (err < 0) |
239 | goto error; | |
240 | ||
6c29230e TS |
241 | oxfw->registered = true; |
242 | ||
243 | return; | |
244 | error: | |
6c29230e TS |
245 | snd_card_free(oxfw->card); |
246 | dev_info(&oxfw->unit->device, | |
247 | "Sound card registration failed: %d\n", err); | |
248 | } | |
249 | ||
250 | static int oxfw_probe(struct fw_unit *unit, | |
251 | const struct ieee1394_device_id *entry) | |
252 | { | |
253 | struct snd_oxfw *oxfw; | |
254 | ||
255 | if (entry->vendor_id == VENDOR_LOUD && !detect_loud_models(unit)) | |
256 | return -ENODEV; | |
257 | ||
258 | /* Allocate this independent of sound card instance. */ | |
366a20d7 TS |
259 | oxfw = devm_kzalloc(&unit->device, sizeof(struct snd_oxfw), GFP_KERNEL); |
260 | if (!oxfw) | |
6c29230e | 261 | return -ENOMEM; |
6c29230e | 262 | oxfw->unit = fw_unit_get(unit); |
8832c5a7 | 263 | dev_set_drvdata(&unit->device, oxfw); |
31ef9134 | 264 | |
366a20d7 | 265 | oxfw->entry = entry; |
6c29230e TS |
266 | mutex_init(&oxfw->mutex); |
267 | spin_lock_init(&oxfw->lock); | |
268 | init_waitqueue_head(&oxfw->hwdep_wait); | |
269 | ||
270 | /* Allocate and register this sound card later. */ | |
271 | INIT_DEFERRABLE_WORK(&oxfw->dwork, do_registration); | |
272 | snd_fw_schedule_registration(unit, &oxfw->dwork); | |
273 | ||
31ef9134 | 274 | return 0; |
31ef9134 CL |
275 | } |
276 | ||
8832c5a7 | 277 | static void oxfw_bus_reset(struct fw_unit *unit) |
31ef9134 | 278 | { |
8832c5a7 | 279 | struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device); |
31ef9134 | 280 | |
6c29230e TS |
281 | if (!oxfw->registered) |
282 | snd_fw_schedule_registration(unit, &oxfw->dwork); | |
283 | ||
8832c5a7 | 284 | fcp_bus_reset(oxfw->unit); |
31ef9134 | 285 | |
6c29230e TS |
286 | if (oxfw->registered) { |
287 | mutex_lock(&oxfw->mutex); | |
b0ac0009 | 288 | |
6c29230e TS |
289 | snd_oxfw_stream_update_simplex(oxfw, &oxfw->rx_stream); |
290 | if (oxfw->has_output) | |
291 | snd_oxfw_stream_update_simplex(oxfw, &oxfw->tx_stream); | |
b0ac0009 | 292 | |
6c29230e | 293 | mutex_unlock(&oxfw->mutex); |
9e2004f9 | 294 | |
6c29230e TS |
295 | if (oxfw->entry->vendor_id == OUI_STANTON) |
296 | snd_oxfw_scs1x_update(oxfw); | |
297 | } | |
31ef9134 CL |
298 | } |
299 | ||
8832c5a7 | 300 | static void oxfw_remove(struct fw_unit *unit) |
94a87157 | 301 | { |
8832c5a7 | 302 | struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device); |
94a87157 | 303 | |
6c29230e TS |
304 | /* |
305 | * Confirm to stop the work for registration before the sound card is | |
306 | * going to be released. The work is not scheduled again because bus | |
307 | * reset handler is not called anymore. | |
308 | */ | |
309 | cancel_delayed_work_sync(&oxfw->dwork); | |
310 | ||
311 | if (oxfw->registered) { | |
61ccc6f6 TS |
312 | // Block till all of ALSA character devices are released. |
313 | snd_card_free(oxfw->card); | |
6c29230e | 314 | } |
5b14ec25 TS |
315 | |
316 | mutex_destroy(&oxfw->mutex); | |
317 | fw_unit_put(oxfw->unit); | |
94a87157 SR |
318 | } |
319 | ||
d6ce6bbd | 320 | static const struct compat_info griffin_firewave = { |
94a87157 | 321 | .driver_name = "FireWave", |
fec7b753 TS |
322 | .vendor_name = "Griffin", |
323 | .model_name = "FireWave", | |
94a87157 SR |
324 | }; |
325 | ||
d6ce6bbd | 326 | static const struct compat_info lacie_speakers = { |
94a87157 | 327 | .driver_name = "FWSpeakers", |
fec7b753 TS |
328 | .vendor_name = "LaCie", |
329 | .model_name = "FireWire Speakers", | |
94a87157 SR |
330 | }; |
331 | ||
8832c5a7 | 332 | static const struct ieee1394_device_id oxfw_id_table[] = { |
31ef9134 CL |
333 | { |
334 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
335 | IEEE1394_MATCH_MODEL_ID | | |
336 | IEEE1394_MATCH_SPECIFIER_ID | | |
337 | IEEE1394_MATCH_VERSION, | |
338 | .vendor_id = VENDOR_GRIFFIN, | |
339 | .model_id = 0x00f970, | |
340 | .specifier_id = SPECIFIER_1394TA, | |
341 | .version = VERSION_AVC, | |
94a87157 | 342 | .driver_data = (kernel_ulong_t)&griffin_firewave, |
31ef9134 CL |
343 | }, |
344 | { | |
345 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
346 | IEEE1394_MATCH_MODEL_ID | | |
347 | IEEE1394_MATCH_SPECIFIER_ID | | |
348 | IEEE1394_MATCH_VERSION, | |
349 | .vendor_id = VENDOR_LACIE, | |
350 | .model_id = 0x00f970, | |
351 | .specifier_id = SPECIFIER_1394TA, | |
352 | .version = VERSION_AVC, | |
94a87157 | 353 | .driver_data = (kernel_ulong_t)&lacie_speakers, |
31ef9134 | 354 | }, |
ec4dba50 TS |
355 | /* Behringer,F-Control Audio 202 */ |
356 | { | |
357 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
358 | IEEE1394_MATCH_MODEL_ID, | |
359 | .vendor_id = VENDOR_BEHRINGER, | |
360 | .model_id = 0x00fc22, | |
361 | }, | |
362 | /* | |
363 | * Any Mackie(Loud) models (name string/model id): | |
364 | * Onyx-i series (former models): 0x081216 | |
365 | * Mackie Onyx Satellite: 0x00200f | |
366 | * Tapco LINK.firewire 4x6: 0x000460 | |
367 | * d.2 pro: Unknown | |
368 | * d.4 pro: Unknown | |
369 | * U.420: Unknown | |
370 | * U.420d: Unknown | |
371 | */ | |
372 | { | |
373 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
374 | IEEE1394_MATCH_SPECIFIER_ID | | |
375 | IEEE1394_MATCH_VERSION, | |
376 | .vendor_id = VENDOR_LOUD, | |
377 | .specifier_id = SPECIFIER_1394TA, | |
378 | .version = VERSION_AVC, | |
379 | }, | |
759a2f40 TS |
380 | /* TASCAM, FireOne */ |
381 | { | |
382 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
383 | IEEE1394_MATCH_MODEL_ID, | |
384 | .vendor_id = VENDOR_TASCAM, | |
385 | .model_id = 0x800007, | |
386 | }, | |
9e2004f9 TS |
387 | /* Stanton, Stanton Controllers & Systems 1 Mixer (SCS.1m) */ |
388 | { | |
389 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
390 | IEEE1394_MATCH_MODEL_ID, | |
391 | .vendor_id = OUI_STANTON, | |
392 | .model_id = 0x001000, | |
393 | }, | |
394 | /* Stanton, Stanton Controllers & Systems 1 Deck (SCS.1d) */ | |
395 | { | |
396 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
397 | IEEE1394_MATCH_MODEL_ID, | |
398 | .vendor_id = OUI_STANTON, | |
399 | .model_id = 0x002000, | |
400 | }, | |
fba43f45 TS |
401 | // APOGEE, duet FireWire |
402 | { | |
403 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
404 | IEEE1394_MATCH_MODEL_ID, | |
405 | .vendor_id = OUI_APOGEE, | |
406 | .model_id = 0x01dddd, | |
407 | }, | |
31ef9134 CL |
408 | { } |
409 | }; | |
8832c5a7 | 410 | MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table); |
31ef9134 | 411 | |
8832c5a7 | 412 | static struct fw_driver oxfw_driver = { |
31ef9134 CL |
413 | .driver = { |
414 | .owner = THIS_MODULE, | |
415 | .name = KBUILD_MODNAME, | |
416 | .bus = &fw_bus_type, | |
31ef9134 | 417 | }, |
8832c5a7 TS |
418 | .probe = oxfw_probe, |
419 | .update = oxfw_bus_reset, | |
420 | .remove = oxfw_remove, | |
421 | .id_table = oxfw_id_table, | |
31ef9134 CL |
422 | }; |
423 | ||
8832c5a7 | 424 | static int __init snd_oxfw_init(void) |
31ef9134 | 425 | { |
8832c5a7 | 426 | return driver_register(&oxfw_driver.driver); |
31ef9134 CL |
427 | } |
428 | ||
8832c5a7 | 429 | static void __exit snd_oxfw_exit(void) |
31ef9134 | 430 | { |
8832c5a7 | 431 | driver_unregister(&oxfw_driver.driver); |
31ef9134 CL |
432 | } |
433 | ||
8832c5a7 TS |
434 | module_init(snd_oxfw_init); |
435 | module_exit(snd_oxfw_exit); |