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",
54 err
= fw_csr_string(unit
->directory
, CSR_MODEL
,
55 model
, sizeof(model
));
59 return match_string(models
, ARRAY_SIZE(models
), model
) >= 0;
62 static int name_card(struct snd_oxfw
*oxfw
)
64 struct fw_device
*fw_dev
= fw_parent_device(oxfw
->unit
);
65 const struct compat_info
*info
;
68 const char *d
, *v
, *m
;
72 /* get vendor name from root directory */
73 err
= fw_csr_string(fw_dev
->config_rom
+ 5, CSR_VENDOR
,
74 vendor
, sizeof(vendor
));
78 /* get model name from unit directory */
79 err
= fw_csr_string(oxfw
->unit
->directory
, CSR_MODEL
,
80 model
, sizeof(model
));
84 err
= snd_fw_transaction(oxfw
->unit
, TCODE_READ_QUADLET_REQUEST
,
85 OXFORD_FIRMWARE_ID_ADDRESS
, &firmware
, 4, 0);
88 be32_to_cpus(&firmware
);
90 /* to apply card definitions */
91 if (oxfw
->entry
->vendor_id
== VENDOR_GRIFFIN
||
92 oxfw
->entry
->vendor_id
== VENDOR_LACIE
) {
93 info
= (const struct compat_info
*)oxfw
->entry
->driver_data
;
94 d
= info
->driver_name
;
95 v
= info
->vendor_name
;
103 strcpy(oxfw
->card
->driver
, d
);
104 strcpy(oxfw
->card
->mixername
, m
);
105 strcpy(oxfw
->card
->shortname
, m
);
107 snprintf(oxfw
->card
->longname
, sizeof(oxfw
->card
->longname
),
108 "%s %s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
109 v
, m
, firmware
>> 20, firmware
& 0xffff,
110 fw_dev
->config_rom
[3], fw_dev
->config_rom
[4],
111 dev_name(&oxfw
->unit
->device
), 100 << fw_dev
->max_speed
);
116 static void oxfw_free(struct snd_oxfw
*oxfw
)
120 snd_oxfw_stream_destroy_simplex(oxfw
, &oxfw
->rx_stream
);
121 if (oxfw
->has_output
)
122 snd_oxfw_stream_destroy_simplex(oxfw
, &oxfw
->tx_stream
);
124 fw_unit_put(oxfw
->unit
);
126 for (i
= 0; i
< SND_OXFW_STREAM_FORMAT_ENTRIES
; i
++) {
127 kfree(oxfw
->tx_stream_formats
[i
]);
128 kfree(oxfw
->rx_stream_formats
[i
]);
132 mutex_destroy(&oxfw
->mutex
);
136 * This module releases the FireWire unit data after all ALSA character devices
137 * are released by applications. This is for releasing stream data or finishing
138 * transactions safely. Thus at returning from .remove(), this module still keep
139 * references for the unit.
141 static void oxfw_card_free(struct snd_card
*card
)
143 oxfw_free(card
->private_data
);
146 static int detect_quirks(struct snd_oxfw
*oxfw
)
148 struct fw_device
*fw_dev
= fw_parent_device(oxfw
->unit
);
149 struct fw_csr_iterator it
;
154 * Add ALSA control elements for two models to keep compatibility to
155 * old firewire-speaker module.
157 if (oxfw
->entry
->vendor_id
== VENDOR_GRIFFIN
)
158 return snd_oxfw_add_spkr(oxfw
, false);
159 if (oxfw
->entry
->vendor_id
== VENDOR_LACIE
)
160 return snd_oxfw_add_spkr(oxfw
, true);
163 * Stanton models supports asynchronous transactions for unique MIDI
166 if (oxfw
->entry
->vendor_id
== OUI_STANTON
) {
167 /* No physical MIDI ports. */
168 oxfw
->midi_input_ports
= 0;
169 oxfw
->midi_output_ports
= 0;
171 /* Output stream exists but no data channels are useful. */
172 oxfw
->has_output
= false;
174 return snd_oxfw_scs1x_add(oxfw
);
178 * TASCAM FireOne has physical control and requires a pair of additional
181 if (oxfw
->entry
->vendor_id
== VENDOR_TASCAM
) {
182 oxfw
->midi_input_ports
++;
183 oxfw
->midi_output_ports
++;
187 /* Seek from Root Directory of Config ROM. */
189 fw_csr_iterator_init(&it
, fw_dev
->config_rom
+ 5);
190 while (fw_csr_iterator_next(&it
, &key
, &val
)) {
191 if (key
== CSR_VENDOR
)
193 else if (key
== CSR_MODEL
)
198 * Mackie Onyx Satellite with base station has a quirk to report a wrong
199 * value in 'dbs' field of CIP header against its format information.
201 if (vendor
== VENDOR_LOUD
&& model
== MODEL_SATELLITE
)
202 oxfw
->wrong_dbs
= true;
207 static void do_registration(struct work_struct
*work
)
209 struct snd_oxfw
*oxfw
= container_of(work
, struct snd_oxfw
, dwork
.work
);
212 if (oxfw
->registered
)
215 err
= snd_card_new(&oxfw
->unit
->device
, -1, NULL
, THIS_MODULE
, 0,
220 err
= name_card(oxfw
);
224 err
= snd_oxfw_stream_discover(oxfw
);
228 err
= detect_quirks(oxfw
);
232 err
= snd_oxfw_stream_init_simplex(oxfw
, &oxfw
->rx_stream
);
235 if (oxfw
->has_output
) {
236 err
= snd_oxfw_stream_init_simplex(oxfw
, &oxfw
->tx_stream
);
241 err
= snd_oxfw_create_pcm(oxfw
);
245 snd_oxfw_proc_init(oxfw
);
247 err
= snd_oxfw_create_midi(oxfw
);
251 err
= snd_oxfw_create_hwdep(oxfw
);
255 err
= snd_card_register(oxfw
->card
);
260 * After registered, oxfw instance can be released corresponding to
261 * releasing the sound card instance.
263 oxfw
->card
->private_free
= oxfw_card_free
;
264 oxfw
->card
->private_data
= oxfw
;
265 oxfw
->registered
= true;
269 snd_oxfw_stream_destroy_simplex(oxfw
, &oxfw
->rx_stream
);
270 if (oxfw
->has_output
)
271 snd_oxfw_stream_destroy_simplex(oxfw
, &oxfw
->tx_stream
);
272 snd_card_free(oxfw
->card
);
273 dev_info(&oxfw
->unit
->device
,
274 "Sound card registration failed: %d\n", err
);
277 static int oxfw_probe(struct fw_unit
*unit
,
278 const struct ieee1394_device_id
*entry
)
280 struct snd_oxfw
*oxfw
;
282 if (entry
->vendor_id
== VENDOR_LOUD
&& !detect_loud_models(unit
))
285 /* Allocate this independent of sound card instance. */
286 oxfw
= kzalloc(sizeof(struct snd_oxfw
), GFP_KERNEL
);
291 oxfw
->unit
= fw_unit_get(unit
);
292 dev_set_drvdata(&unit
->device
, oxfw
);
294 mutex_init(&oxfw
->mutex
);
295 spin_lock_init(&oxfw
->lock
);
296 init_waitqueue_head(&oxfw
->hwdep_wait
);
298 /* Allocate and register this sound card later. */
299 INIT_DEFERRABLE_WORK(&oxfw
->dwork
, do_registration
);
300 snd_fw_schedule_registration(unit
, &oxfw
->dwork
);
305 static void oxfw_bus_reset(struct fw_unit
*unit
)
307 struct snd_oxfw
*oxfw
= dev_get_drvdata(&unit
->device
);
309 if (!oxfw
->registered
)
310 snd_fw_schedule_registration(unit
, &oxfw
->dwork
);
312 fcp_bus_reset(oxfw
->unit
);
314 if (oxfw
->registered
) {
315 mutex_lock(&oxfw
->mutex
);
317 snd_oxfw_stream_update_simplex(oxfw
, &oxfw
->rx_stream
);
318 if (oxfw
->has_output
)
319 snd_oxfw_stream_update_simplex(oxfw
, &oxfw
->tx_stream
);
321 mutex_unlock(&oxfw
->mutex
);
323 if (oxfw
->entry
->vendor_id
== OUI_STANTON
)
324 snd_oxfw_scs1x_update(oxfw
);
328 static void oxfw_remove(struct fw_unit
*unit
)
330 struct snd_oxfw
*oxfw
= dev_get_drvdata(&unit
->device
);
333 * Confirm to stop the work for registration before the sound card is
334 * going to be released. The work is not scheduled again because bus
335 * reset handler is not called anymore.
337 cancel_delayed_work_sync(&oxfw
->dwork
);
339 if (oxfw
->registered
) {
340 /* No need to wait for releasing card object in this context. */
341 snd_card_free_when_closed(oxfw
->card
);
343 /* Don't forget this case. */
348 static const struct compat_info griffin_firewave
= {
349 .driver_name
= "FireWave",
350 .vendor_name
= "Griffin",
351 .model_name
= "FireWave",
354 static const struct compat_info lacie_speakers
= {
355 .driver_name
= "FWSpeakers",
356 .vendor_name
= "LaCie",
357 .model_name
= "FireWire Speakers",
360 static const struct ieee1394_device_id oxfw_id_table
[] = {
362 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
363 IEEE1394_MATCH_MODEL_ID
|
364 IEEE1394_MATCH_SPECIFIER_ID
|
365 IEEE1394_MATCH_VERSION
,
366 .vendor_id
= VENDOR_GRIFFIN
,
367 .model_id
= 0x00f970,
368 .specifier_id
= SPECIFIER_1394TA
,
369 .version
= VERSION_AVC
,
370 .driver_data
= (kernel_ulong_t
)&griffin_firewave
,
373 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
374 IEEE1394_MATCH_MODEL_ID
|
375 IEEE1394_MATCH_SPECIFIER_ID
|
376 IEEE1394_MATCH_VERSION
,
377 .vendor_id
= VENDOR_LACIE
,
378 .model_id
= 0x00f970,
379 .specifier_id
= SPECIFIER_1394TA
,
380 .version
= VERSION_AVC
,
381 .driver_data
= (kernel_ulong_t
)&lacie_speakers
,
383 /* Behringer,F-Control Audio 202 */
385 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
386 IEEE1394_MATCH_MODEL_ID
,
387 .vendor_id
= VENDOR_BEHRINGER
,
388 .model_id
= 0x00fc22,
391 * Any Mackie(Loud) models (name string/model id):
392 * Onyx-i series (former models): 0x081216
393 * Mackie Onyx Satellite: 0x00200f
394 * Tapco LINK.firewire 4x6: 0x000460
401 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
402 IEEE1394_MATCH_SPECIFIER_ID
|
403 IEEE1394_MATCH_VERSION
,
404 .vendor_id
= VENDOR_LOUD
,
405 .specifier_id
= SPECIFIER_1394TA
,
406 .version
= VERSION_AVC
,
408 /* TASCAM, FireOne */
410 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
411 IEEE1394_MATCH_MODEL_ID
,
412 .vendor_id
= VENDOR_TASCAM
,
413 .model_id
= 0x800007,
415 /* Stanton, Stanton Controllers & Systems 1 Mixer (SCS.1m) */
417 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
418 IEEE1394_MATCH_MODEL_ID
,
419 .vendor_id
= OUI_STANTON
,
420 .model_id
= 0x001000,
422 /* Stanton, Stanton Controllers & Systems 1 Deck (SCS.1d) */
424 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
425 IEEE1394_MATCH_MODEL_ID
,
426 .vendor_id
= OUI_STANTON
,
427 .model_id
= 0x002000,
431 MODULE_DEVICE_TABLE(ieee1394
, oxfw_id_table
);
433 static struct fw_driver oxfw_driver
= {
435 .owner
= THIS_MODULE
,
436 .name
= KBUILD_MODNAME
,
440 .update
= oxfw_bus_reset
,
441 .remove
= oxfw_remove
,
442 .id_table
= oxfw_id_table
,
445 static int __init
snd_oxfw_init(void)
447 return driver_register(&oxfw_driver
.driver
);
450 static void __exit
snd_oxfw_exit(void)
452 driver_unregister(&oxfw_driver
.driver
);
455 module_init(snd_oxfw_init
);
456 module_exit(snd_oxfw_exit
);