1 // SPDX-License-Identifier: GPL-2.0-only
3 * oxfw.c - a part of driver for OXFW970/971 based devices
5 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
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
23 #define OUI_APOGEE 0x0003db
25 #define MODEL_SATELLITE 0x00200f
27 #define SPECIFIER_1394TA 0x00a02d
28 #define VERSION_AVC 0x010001
30 MODULE_DESCRIPTION("Oxford Semiconductor FW970/971 driver");
31 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
32 MODULE_LICENSE("GPL v2");
33 MODULE_ALIAS("snd-firewire-speakers");
34 MODULE_ALIAS("snd-scs1x");
37 const char *driver_name
;
38 const char *vendor_name
;
39 const char *model_name
;
42 static bool detect_loud_models(struct fw_unit
*unit
)
44 const char *const models
[] = {
49 "Mackie Onyx Satellite",
50 "Tapco LINK.firewire 4x6",
55 err
= fw_csr_string(unit
->directory
, CSR_MODEL
,
56 model
, sizeof(model
));
60 return match_string(models
, ARRAY_SIZE(models
), model
) >= 0;
63 static int name_card(struct snd_oxfw
*oxfw
)
65 struct fw_device
*fw_dev
= fw_parent_device(oxfw
->unit
);
66 const struct compat_info
*info
;
69 const char *d
, *v
, *m
;
73 /* get vendor name from root directory */
74 err
= fw_csr_string(fw_dev
->config_rom
+ 5, CSR_VENDOR
,
75 vendor
, sizeof(vendor
));
79 /* get model name from unit directory */
80 err
= fw_csr_string(oxfw
->unit
->directory
, CSR_MODEL
,
81 model
, sizeof(model
));
85 err
= snd_fw_transaction(oxfw
->unit
, TCODE_READ_QUADLET_REQUEST
,
86 OXFORD_FIRMWARE_ID_ADDRESS
, &firmware
, 4, 0);
89 be32_to_cpus(&firmware
);
91 /* to apply card definitions */
92 if (oxfw
->entry
->vendor_id
== VENDOR_GRIFFIN
||
93 oxfw
->entry
->vendor_id
== VENDOR_LACIE
) {
94 info
= (const struct compat_info
*)oxfw
->entry
->driver_data
;
95 d
= info
->driver_name
;
96 v
= info
->vendor_name
;
104 strcpy(oxfw
->card
->driver
, d
);
105 strcpy(oxfw
->card
->mixername
, m
);
106 strcpy(oxfw
->card
->shortname
, m
);
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
);
117 static void oxfw_card_free(struct snd_card
*card
)
119 struct snd_oxfw
*oxfw
= card
->private_data
;
121 if (oxfw
->has_output
|| oxfw
->has_input
)
122 snd_oxfw_stream_destroy_duplex(oxfw
);
125 static int detect_quirks(struct snd_oxfw
*oxfw
)
127 struct fw_device
*fw_dev
= fw_parent_device(oxfw
->unit
);
128 struct fw_csr_iterator it
;
133 * Add ALSA control elements for two models to keep compatibility to
134 * old firewire-speaker module.
136 if (oxfw
->entry
->vendor_id
== VENDOR_GRIFFIN
)
137 return snd_oxfw_add_spkr(oxfw
, false);
138 if (oxfw
->entry
->vendor_id
== VENDOR_LACIE
)
139 return snd_oxfw_add_spkr(oxfw
, true);
142 * Stanton models supports asynchronous transactions for unique MIDI
145 if (oxfw
->entry
->vendor_id
== OUI_STANTON
) {
146 /* No physical MIDI ports. */
147 oxfw
->midi_input_ports
= 0;
148 oxfw
->midi_output_ports
= 0;
150 return snd_oxfw_scs1x_add(oxfw
);
154 * TASCAM FireOne has physical control and requires a pair of additional
157 if (oxfw
->entry
->vendor_id
== VENDOR_TASCAM
) {
158 oxfw
->midi_input_ports
++;
159 oxfw
->midi_output_ports
++;
163 /* Seek from Root Directory of Config ROM. */
165 fw_csr_iterator_init(&it
, fw_dev
->config_rom
+ 5);
166 while (fw_csr_iterator_next(&it
, &key
, &val
)) {
167 if (key
== CSR_VENDOR
)
169 else if (key
== CSR_MODEL
)
174 * Mackie Onyx Satellite with base station has a quirk to report a wrong
175 * value in 'dbs' field of CIP header against its format information.
177 if (vendor
== VENDOR_LOUD
&& model
== MODEL_SATELLITE
)
178 oxfw
->wrong_dbs
= true;
183 static void do_registration(struct work_struct
*work
)
185 struct snd_oxfw
*oxfw
= container_of(work
, struct snd_oxfw
, dwork
.work
);
188 if (oxfw
->registered
)
191 err
= snd_card_new(&oxfw
->unit
->device
, -1, NULL
, THIS_MODULE
, 0,
195 oxfw
->card
->private_free
= oxfw_card_free
;
196 oxfw
->card
->private_data
= oxfw
;
198 err
= name_card(oxfw
);
202 err
= snd_oxfw_stream_discover(oxfw
);
206 err
= detect_quirks(oxfw
);
210 if (oxfw
->has_output
|| oxfw
->has_input
) {
211 err
= snd_oxfw_stream_init_duplex(oxfw
);
215 err
= snd_oxfw_create_pcm(oxfw
);
219 snd_oxfw_proc_init(oxfw
);
221 err
= snd_oxfw_create_midi(oxfw
);
225 err
= snd_oxfw_create_hwdep(oxfw
);
230 err
= snd_card_register(oxfw
->card
);
234 oxfw
->registered
= true;
238 snd_card_free(oxfw
->card
);
239 dev_info(&oxfw
->unit
->device
,
240 "Sound card registration failed: %d\n", err
);
243 static int oxfw_probe(struct fw_unit
*unit
,
244 const struct ieee1394_device_id
*entry
)
246 struct snd_oxfw
*oxfw
;
248 if (entry
->vendor_id
== VENDOR_LOUD
&& !detect_loud_models(unit
))
251 /* Allocate this independent of sound card instance. */
252 oxfw
= devm_kzalloc(&unit
->device
, sizeof(struct snd_oxfw
), GFP_KERNEL
);
255 oxfw
->unit
= fw_unit_get(unit
);
256 dev_set_drvdata(&unit
->device
, oxfw
);
259 mutex_init(&oxfw
->mutex
);
260 spin_lock_init(&oxfw
->lock
);
261 init_waitqueue_head(&oxfw
->hwdep_wait
);
263 /* Allocate and register this sound card later. */
264 INIT_DEFERRABLE_WORK(&oxfw
->dwork
, do_registration
);
265 snd_fw_schedule_registration(unit
, &oxfw
->dwork
);
270 static void oxfw_bus_reset(struct fw_unit
*unit
)
272 struct snd_oxfw
*oxfw
= dev_get_drvdata(&unit
->device
);
274 if (!oxfw
->registered
)
275 snd_fw_schedule_registration(unit
, &oxfw
->dwork
);
277 fcp_bus_reset(oxfw
->unit
);
279 if (oxfw
->registered
) {
280 if (oxfw
->has_output
|| oxfw
->has_input
) {
281 mutex_lock(&oxfw
->mutex
);
282 snd_oxfw_stream_update_duplex(oxfw
);
283 mutex_unlock(&oxfw
->mutex
);
286 if (oxfw
->entry
->vendor_id
== OUI_STANTON
)
287 snd_oxfw_scs1x_update(oxfw
);
291 static void oxfw_remove(struct fw_unit
*unit
)
293 struct snd_oxfw
*oxfw
= dev_get_drvdata(&unit
->device
);
296 * Confirm to stop the work for registration before the sound card is
297 * going to be released. The work is not scheduled again because bus
298 * reset handler is not called anymore.
300 cancel_delayed_work_sync(&oxfw
->dwork
);
302 if (oxfw
->registered
) {
303 // Block till all of ALSA character devices are released.
304 snd_card_free(oxfw
->card
);
307 mutex_destroy(&oxfw
->mutex
);
308 fw_unit_put(oxfw
->unit
);
311 static const struct compat_info griffin_firewave
= {
312 .driver_name
= "FireWave",
313 .vendor_name
= "Griffin",
314 .model_name
= "FireWave",
317 static const struct compat_info lacie_speakers
= {
318 .driver_name
= "FWSpeakers",
319 .vendor_name
= "LaCie",
320 .model_name
= "FireWire Speakers",
323 static const struct ieee1394_device_id oxfw_id_table
[] = {
325 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
326 IEEE1394_MATCH_MODEL_ID
|
327 IEEE1394_MATCH_SPECIFIER_ID
|
328 IEEE1394_MATCH_VERSION
,
329 .vendor_id
= VENDOR_GRIFFIN
,
330 .model_id
= 0x00f970,
331 .specifier_id
= SPECIFIER_1394TA
,
332 .version
= VERSION_AVC
,
333 .driver_data
= (kernel_ulong_t
)&griffin_firewave
,
336 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
337 IEEE1394_MATCH_MODEL_ID
|
338 IEEE1394_MATCH_SPECIFIER_ID
|
339 IEEE1394_MATCH_VERSION
,
340 .vendor_id
= VENDOR_LACIE
,
341 .model_id
= 0x00f970,
342 .specifier_id
= SPECIFIER_1394TA
,
343 .version
= VERSION_AVC
,
344 .driver_data
= (kernel_ulong_t
)&lacie_speakers
,
346 /* Behringer,F-Control Audio 202 */
348 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
349 IEEE1394_MATCH_MODEL_ID
,
350 .vendor_id
= VENDOR_BEHRINGER
,
351 .model_id
= 0x00fc22,
354 * Any Mackie(Loud) models (name string/model id):
355 * Onyx-i series (former models): 0x081216
356 * Mackie Onyx Satellite: 0x00200f
357 * Tapco LINK.firewire 4x6: 0x000460
364 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
365 IEEE1394_MATCH_SPECIFIER_ID
|
366 IEEE1394_MATCH_VERSION
,
367 .vendor_id
= VENDOR_LOUD
,
368 .specifier_id
= SPECIFIER_1394TA
,
369 .version
= VERSION_AVC
,
371 /* TASCAM, FireOne */
373 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
374 IEEE1394_MATCH_MODEL_ID
,
375 .vendor_id
= VENDOR_TASCAM
,
376 .model_id
= 0x800007,
378 /* Stanton, Stanton Controllers & Systems 1 Mixer (SCS.1m) */
380 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
381 IEEE1394_MATCH_MODEL_ID
,
382 .vendor_id
= OUI_STANTON
,
383 .model_id
= 0x001000,
385 /* Stanton, Stanton Controllers & Systems 1 Deck (SCS.1d) */
387 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
388 IEEE1394_MATCH_MODEL_ID
,
389 .vendor_id
= OUI_STANTON
,
390 .model_id
= 0x002000,
392 // APOGEE, duet FireWire
394 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
395 IEEE1394_MATCH_MODEL_ID
,
396 .vendor_id
= OUI_APOGEE
,
397 .model_id
= 0x01dddd,
401 MODULE_DEVICE_TABLE(ieee1394
, oxfw_id_table
);
403 static struct fw_driver oxfw_driver
= {
405 .owner
= THIS_MODULE
,
406 .name
= KBUILD_MODNAME
,
410 .update
= oxfw_bus_reset
,
411 .remove
= oxfw_remove
,
412 .id_table
= oxfw_id_table
,
415 static int __init
snd_oxfw_init(void)
417 return driver_register(&oxfw_driver
.driver
);
420 static void __exit
snd_oxfw_exit(void)
422 driver_unregister(&oxfw_driver
.driver
);
425 module_init(snd_oxfw_init
);
426 module_exit(snd_oxfw_exit
);