2 * oxfw.c - a part of driver for OXFW970/971 based devices
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
10 #define OXFORD_FIRMWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x50000)
11 /* 0x970?vvvv or 0x971?vvvv, where vvvv = firmware version */
13 #define OXFORD_HARDWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x90020)
14 #define OXFORD_HARDWARE_ID_OXFW970 0x39443841
15 #define OXFORD_HARDWARE_ID_OXFW971 0x39373100
17 #define VENDOR_LOUD 0x000ff2
18 #define VENDOR_GRIFFIN 0x001292
19 #define VENDOR_BEHRINGER 0x001564
20 #define VENDOR_LACIE 0x00d04b
21 #define VENDOR_TASCAM 0x00022e
22 #define OUI_STANTON 0x001260
24 #define MODEL_SATELLITE 0x00200f
26 #define SPECIFIER_1394TA 0x00a02d
27 #define VERSION_AVC 0x010001
29 MODULE_DESCRIPTION("Oxford Semiconductor FW970/971 driver");
30 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
31 MODULE_LICENSE("GPL v2");
32 MODULE_ALIAS("snd-firewire-speakers");
33 MODULE_ALIAS("snd-scs1x");
36 const char *driver_name
;
37 const char *vendor_name
;
38 const char *model_name
;
41 static bool detect_loud_models(struct fw_unit
*unit
)
43 const char *const models
[] = {
48 "Mackie Onyx Satellite",
49 "Tapco LINK.firewire 4x6",
55 err
= fw_csr_string(unit
->directory
, CSR_MODEL
,
56 model
, sizeof(model
));
60 for (i
= 0; i
< ARRAY_SIZE(models
); i
++) {
61 if (strcmp(models
[i
], model
) == 0)
65 return (i
< ARRAY_SIZE(models
));
68 static int name_card(struct snd_oxfw
*oxfw
)
70 struct fw_device
*fw_dev
= fw_parent_device(oxfw
->unit
);
71 const struct compat_info
*info
;
74 const char *d
, *v
, *m
;
78 /* get vendor name from root directory */
79 err
= fw_csr_string(fw_dev
->config_rom
+ 5, CSR_VENDOR
,
80 vendor
, sizeof(vendor
));
84 /* get model name from unit directory */
85 err
= fw_csr_string(oxfw
->unit
->directory
, CSR_MODEL
,
86 model
, sizeof(model
));
90 err
= snd_fw_transaction(oxfw
->unit
, TCODE_READ_QUADLET_REQUEST
,
91 OXFORD_FIRMWARE_ID_ADDRESS
, &firmware
, 4, 0);
94 be32_to_cpus(&firmware
);
96 /* to apply card definitions */
97 if (oxfw
->entry
->vendor_id
== VENDOR_GRIFFIN
||
98 oxfw
->entry
->vendor_id
== VENDOR_LACIE
) {
99 info
= (const struct compat_info
*)oxfw
->entry
->driver_data
;
100 d
= info
->driver_name
;
101 v
= info
->vendor_name
;
102 m
= info
->model_name
;
109 strcpy(oxfw
->card
->driver
, d
);
110 strcpy(oxfw
->card
->mixername
, m
);
111 strcpy(oxfw
->card
->shortname
, m
);
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
);
122 static void oxfw_free(struct snd_oxfw
*oxfw
)
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
);
130 fw_unit_put(oxfw
->unit
);
132 for (i
= 0; i
< SND_OXFW_STREAM_FORMAT_ENTRIES
; i
++) {
133 kfree(oxfw
->tx_stream_formats
[i
]);
134 kfree(oxfw
->rx_stream_formats
[i
]);
138 mutex_destroy(&oxfw
->mutex
);
143 * This module releases the FireWire unit data after all ALSA character devices
144 * are released by applications. This is for releasing stream data or finishing
145 * transactions safely. Thus at returning from .remove(), this module still keep
146 * references for the unit.
148 static void oxfw_card_free(struct snd_card
*card
)
150 oxfw_free(card
->private_data
);
153 static int detect_quirks(struct snd_oxfw
*oxfw
)
155 struct fw_device
*fw_dev
= fw_parent_device(oxfw
->unit
);
156 struct fw_csr_iterator it
;
161 * Add ALSA control elements for two models to keep compatibility to
162 * old firewire-speaker module.
164 if (oxfw
->entry
->vendor_id
== VENDOR_GRIFFIN
)
165 return snd_oxfw_add_spkr(oxfw
, false);
166 if (oxfw
->entry
->vendor_id
== VENDOR_LACIE
)
167 return snd_oxfw_add_spkr(oxfw
, true);
170 * Stanton models supports asynchronous transactions for unique MIDI
173 if (oxfw
->entry
->vendor_id
== OUI_STANTON
) {
174 /* No physical MIDI ports. */
175 oxfw
->midi_input_ports
= 0;
176 oxfw
->midi_output_ports
= 0;
178 /* Output stream exists but no data channels are useful. */
179 oxfw
->has_output
= false;
181 return snd_oxfw_scs1x_add(oxfw
);
185 * TASCAM FireOne has physical control and requires a pair of additional
188 if (oxfw
->entry
->vendor_id
== VENDOR_TASCAM
) {
189 oxfw
->midi_input_ports
++;
190 oxfw
->midi_output_ports
++;
194 /* Seek from Root Directory of Config ROM. */
196 fw_csr_iterator_init(&it
, fw_dev
->config_rom
+ 5);
197 while (fw_csr_iterator_next(&it
, &key
, &val
)) {
198 if (key
== CSR_VENDOR
)
200 else if (key
== CSR_MODEL
)
205 * Mackie Onyx Satellite with base station has a quirk to report a wrong
206 * value in 'dbs' field of CIP header against its format information.
208 if (vendor
== VENDOR_LOUD
&& model
== MODEL_SATELLITE
)
209 oxfw
->wrong_dbs
= true;
214 static void do_registration(struct work_struct
*work
)
216 struct snd_oxfw
*oxfw
= container_of(work
, struct snd_oxfw
, dwork
.work
);
220 if (oxfw
->registered
)
223 err
= snd_card_new(&oxfw
->unit
->device
, -1, NULL
, THIS_MODULE
, 0,
228 err
= name_card(oxfw
);
232 err
= snd_oxfw_stream_discover(oxfw
);
236 err
= detect_quirks(oxfw
);
240 err
= snd_oxfw_stream_init_simplex(oxfw
, &oxfw
->rx_stream
);
243 if (oxfw
->has_output
) {
244 err
= snd_oxfw_stream_init_simplex(oxfw
, &oxfw
->tx_stream
);
249 err
= snd_oxfw_create_pcm(oxfw
);
253 snd_oxfw_proc_init(oxfw
);
255 err
= snd_oxfw_create_midi(oxfw
);
259 err
= snd_oxfw_create_hwdep(oxfw
);
263 err
= snd_card_register(oxfw
->card
);
268 * After registered, oxfw instance can be released corresponding to
269 * releasing the sound card instance.
271 oxfw
->card
->private_free
= oxfw_card_free
;
272 oxfw
->card
->private_data
= oxfw
;
273 oxfw
->registered
= true;
277 snd_oxfw_stream_destroy_simplex(oxfw
, &oxfw
->rx_stream
);
278 if (oxfw
->has_output
)
279 snd_oxfw_stream_destroy_simplex(oxfw
, &oxfw
->tx_stream
);
280 for (i
= 0; i
< SND_OXFW_STREAM_FORMAT_ENTRIES
; ++i
) {
281 kfree(oxfw
->tx_stream_formats
[i
]);
282 oxfw
->tx_stream_formats
[i
] = NULL
;
283 kfree(oxfw
->rx_stream_formats
[i
]);
284 oxfw
->rx_stream_formats
[i
] = NULL
;
286 snd_card_free(oxfw
->card
);
289 dev_info(&oxfw
->unit
->device
,
290 "Sound card registration failed: %d\n", err
);
293 static int oxfw_probe(struct fw_unit
*unit
,
294 const struct ieee1394_device_id
*entry
)
296 struct snd_oxfw
*oxfw
;
298 if (entry
->vendor_id
== VENDOR_LOUD
&& !detect_loud_models(unit
))
301 /* Allocate this independent of sound card instance. */
302 oxfw
= kzalloc(sizeof(struct snd_oxfw
), GFP_KERNEL
);
307 oxfw
->unit
= fw_unit_get(unit
);
308 dev_set_drvdata(&unit
->device
, oxfw
);
310 mutex_init(&oxfw
->mutex
);
311 spin_lock_init(&oxfw
->lock
);
312 init_waitqueue_head(&oxfw
->hwdep_wait
);
314 /* Allocate and register this sound card later. */
315 INIT_DEFERRABLE_WORK(&oxfw
->dwork
, do_registration
);
316 snd_fw_schedule_registration(unit
, &oxfw
->dwork
);
321 static void oxfw_bus_reset(struct fw_unit
*unit
)
323 struct snd_oxfw
*oxfw
= dev_get_drvdata(&unit
->device
);
325 if (!oxfw
->registered
)
326 snd_fw_schedule_registration(unit
, &oxfw
->dwork
);
328 fcp_bus_reset(oxfw
->unit
);
330 if (oxfw
->registered
) {
331 mutex_lock(&oxfw
->mutex
);
333 snd_oxfw_stream_update_simplex(oxfw
, &oxfw
->rx_stream
);
334 if (oxfw
->has_output
)
335 snd_oxfw_stream_update_simplex(oxfw
, &oxfw
->tx_stream
);
337 mutex_unlock(&oxfw
->mutex
);
339 if (oxfw
->entry
->vendor_id
== OUI_STANTON
)
340 snd_oxfw_scs1x_update(oxfw
);
344 static void oxfw_remove(struct fw_unit
*unit
)
346 struct snd_oxfw
*oxfw
= dev_get_drvdata(&unit
->device
);
349 * Confirm to stop the work for registration before the sound card is
350 * going to be released. The work is not scheduled again because bus
351 * reset handler is not called anymore.
353 cancel_delayed_work_sync(&oxfw
->dwork
);
355 if (oxfw
->registered
) {
356 /* No need to wait for releasing card object in this context. */
357 snd_card_free_when_closed(oxfw
->card
);
359 /* Don't forget this case. */
364 static const struct compat_info griffin_firewave
= {
365 .driver_name
= "FireWave",
366 .vendor_name
= "Griffin",
367 .model_name
= "FireWave",
370 static const struct compat_info lacie_speakers
= {
371 .driver_name
= "FWSpeakers",
372 .vendor_name
= "LaCie",
373 .model_name
= "FireWire Speakers",
376 static const struct ieee1394_device_id oxfw_id_table
[] = {
378 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
379 IEEE1394_MATCH_MODEL_ID
|
380 IEEE1394_MATCH_SPECIFIER_ID
|
381 IEEE1394_MATCH_VERSION
,
382 .vendor_id
= VENDOR_GRIFFIN
,
383 .model_id
= 0x00f970,
384 .specifier_id
= SPECIFIER_1394TA
,
385 .version
= VERSION_AVC
,
386 .driver_data
= (kernel_ulong_t
)&griffin_firewave
,
389 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
390 IEEE1394_MATCH_MODEL_ID
|
391 IEEE1394_MATCH_SPECIFIER_ID
|
392 IEEE1394_MATCH_VERSION
,
393 .vendor_id
= VENDOR_LACIE
,
394 .model_id
= 0x00f970,
395 .specifier_id
= SPECIFIER_1394TA
,
396 .version
= VERSION_AVC
,
397 .driver_data
= (kernel_ulong_t
)&lacie_speakers
,
399 /* Behringer,F-Control Audio 202 */
401 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
402 IEEE1394_MATCH_MODEL_ID
,
403 .vendor_id
= VENDOR_BEHRINGER
,
404 .model_id
= 0x00fc22,
407 * Any Mackie(Loud) models (name string/model id):
408 * Onyx-i series (former models): 0x081216
409 * Mackie Onyx Satellite: 0x00200f
410 * Tapco LINK.firewire 4x6: 0x000460
417 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
418 IEEE1394_MATCH_SPECIFIER_ID
|
419 IEEE1394_MATCH_VERSION
,
420 .vendor_id
= VENDOR_LOUD
,
421 .specifier_id
= SPECIFIER_1394TA
,
422 .version
= VERSION_AVC
,
424 /* TASCAM, FireOne */
426 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
427 IEEE1394_MATCH_MODEL_ID
,
428 .vendor_id
= VENDOR_TASCAM
,
429 .model_id
= 0x800007,
431 /* Stanton, Stanton Controllers & Systems 1 Mixer (SCS.1m) */
433 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
434 IEEE1394_MATCH_MODEL_ID
,
435 .vendor_id
= OUI_STANTON
,
436 .model_id
= 0x001000,
438 /* Stanton, Stanton Controllers & Systems 1 Deck (SCS.1d) */
440 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
441 IEEE1394_MATCH_MODEL_ID
,
442 .vendor_id
= OUI_STANTON
,
443 .model_id
= 0x002000,
447 MODULE_DEVICE_TABLE(ieee1394
, oxfw_id_table
);
449 static struct fw_driver oxfw_driver
= {
451 .owner
= THIS_MODULE
,
452 .name
= KBUILD_MODNAME
,
456 .update
= oxfw_bus_reset
,
457 .remove
= oxfw_remove
,
458 .id_table
= oxfw_id_table
,
461 static int __init
snd_oxfw_init(void)
463 return driver_register(&oxfw_driver
.driver
);
466 static void __exit
snd_oxfw_exit(void)
468 driver_unregister(&oxfw_driver
.driver
);
471 module_init(snd_oxfw_init
);
472 module_exit(snd_oxfw_exit
);