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