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[] = {
53 err = fw_csr_string(unit->directory, CSR_MODEL,
54 model, sizeof(model));
58 return match_string(models, ARRAY_SIZE(models), model) >= 0;
61 static int name_card(struct snd_oxfw *oxfw)
63 struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
64 const struct compat_info *info;
67 const char *d, *v, *m;
71 /* get vendor name from root directory */
72 err = fw_csr_string(fw_dev->config_rom + 5, CSR_VENDOR,
73 vendor, sizeof(vendor));
77 /* get model name from unit directory */
78 err = fw_csr_string(oxfw->unit->directory, CSR_MODEL,
79 model, sizeof(model));
83 err = snd_fw_transaction(oxfw->unit, TCODE_READ_QUADLET_REQUEST,
84 OXFORD_FIRMWARE_ID_ADDRESS, &firmware, 4, 0);
87 be32_to_cpus(&firmware);
89 if (firmware >> 20 == 0x970)
90 oxfw->quirks |= SND_OXFW_QUIRK_JUMBO_PAYLOAD;
92 /* to apply card definitions */
93 if (oxfw->entry->vendor_id == VENDOR_GRIFFIN ||
94 oxfw->entry->vendor_id == VENDOR_LACIE) {
95 info = (const struct compat_info *)oxfw->entry->driver_data;
96 d = info->driver_name;
97 v = info->vendor_name;
105 strcpy(oxfw->card->driver, d);
106 strcpy(oxfw->card->mixername, m);
107 strcpy(oxfw->card->shortname, m);
109 snprintf(oxfw->card->longname, sizeof(oxfw->card->longname),
110 "%s %s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
111 v, m, firmware >> 20, firmware & 0xffff,
112 fw_dev->config_rom[3], fw_dev->config_rom[4],
113 dev_name(&oxfw->unit->device), 100 << fw_dev->max_speed);
118 static void oxfw_card_free(struct snd_card *card)
120 struct snd_oxfw *oxfw = card->private_data;
122 if (oxfw->has_output || oxfw->has_input)
123 snd_oxfw_stream_destroy_duplex(oxfw);
126 static int detect_quirks(struct snd_oxfw *oxfw)
128 struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
129 struct fw_csr_iterator it;
134 * Add ALSA control elements for two models to keep compatibility to
135 * old firewire-speaker module.
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);
143 * Stanton models supports asynchronous transactions for unique MIDI
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;
151 return snd_oxfw_scs1x_add(oxfw);
155 * TASCAM FireOne has physical control and requires a pair of additional
158 if (oxfw->entry->vendor_id == VENDOR_TASCAM) {
159 oxfw->midi_input_ports++;
160 oxfw->midi_output_ports++;
164 /* Seek from Root Directory of Config ROM. */
166 fw_csr_iterator_init(&it, fw_dev->config_rom + 5);
167 while (fw_csr_iterator_next(&it, &key, &val)) {
168 if (key == CSR_VENDOR)
170 else if (key == CSR_MODEL)
175 * Mackie Onyx Satellite with base station has a quirk to report a wrong
176 * value in 'dbs' field of CIP header against its format information.
178 if (vendor == VENDOR_LOUD && model == MODEL_SATELLITE)
179 oxfw->wrong_dbs = true;
184 static void do_registration(struct work_struct *work)
186 struct snd_oxfw *oxfw = container_of(work, struct snd_oxfw, dwork.work);
189 if (oxfw->registered)
192 err = snd_card_new(&oxfw->unit->device, -1, NULL, THIS_MODULE, 0,
196 oxfw->card->private_free = oxfw_card_free;
197 oxfw->card->private_data = oxfw;
199 err = name_card(oxfw);
203 err = snd_oxfw_stream_discover(oxfw);
207 err = detect_quirks(oxfw);
211 if (oxfw->has_output || oxfw->has_input) {
212 err = snd_oxfw_stream_init_duplex(oxfw);
216 err = snd_oxfw_create_pcm(oxfw);
220 snd_oxfw_proc_init(oxfw);
222 err = snd_oxfw_create_midi(oxfw);
226 err = snd_oxfw_create_hwdep(oxfw);
231 err = snd_card_register(oxfw->card);
235 oxfw->registered = true;
239 snd_card_free(oxfw->card);
240 dev_info(&oxfw->unit->device,
241 "Sound card registration failed: %d\n", err);
244 static int oxfw_probe(struct fw_unit *unit,
245 const struct ieee1394_device_id *entry)
247 struct snd_oxfw *oxfw;
249 if (entry->vendor_id == VENDOR_LOUD && entry->model_id == 0 && !detect_loud_models(unit))
252 /* Allocate this independent of sound card instance. */
253 oxfw = devm_kzalloc(&unit->device, sizeof(struct snd_oxfw), GFP_KERNEL);
256 oxfw->unit = fw_unit_get(unit);
257 dev_set_drvdata(&unit->device, oxfw);
260 mutex_init(&oxfw->mutex);
261 spin_lock_init(&oxfw->lock);
262 init_waitqueue_head(&oxfw->hwdep_wait);
264 /* Allocate and register this sound card later. */
265 INIT_DEFERRABLE_WORK(&oxfw->dwork, do_registration);
266 snd_fw_schedule_registration(unit, &oxfw->dwork);
271 static void oxfw_bus_reset(struct fw_unit *unit)
273 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
275 if (!oxfw->registered)
276 snd_fw_schedule_registration(unit, &oxfw->dwork);
278 fcp_bus_reset(oxfw->unit);
280 if (oxfw->registered) {
281 if (oxfw->has_output || oxfw->has_input) {
282 mutex_lock(&oxfw->mutex);
283 snd_oxfw_stream_update_duplex(oxfw);
284 mutex_unlock(&oxfw->mutex);
287 if (oxfw->entry->vendor_id == OUI_STANTON)
288 snd_oxfw_scs1x_update(oxfw);
292 static void oxfw_remove(struct fw_unit *unit)
294 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
297 * Confirm to stop the work for registration before the sound card is
298 * going to be released. The work is not scheduled again because bus
299 * reset handler is not called anymore.
301 cancel_delayed_work_sync(&oxfw->dwork);
303 if (oxfw->registered) {
304 // Block till all of ALSA character devices are released.
305 snd_card_free(oxfw->card);
308 mutex_destroy(&oxfw->mutex);
309 fw_unit_put(oxfw->unit);
312 static const struct compat_info griffin_firewave = {
313 .driver_name = "FireWave",
314 .vendor_name = "Griffin",
315 .model_name = "FireWave",
318 static const struct compat_info lacie_speakers = {
319 .driver_name = "FWSpeakers",
320 .vendor_name = "LaCie",
321 .model_name = "FireWire Speakers",
324 #define OXFW_DEV_ENTRY(vendor, model, data) \
326 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
327 IEEE1394_MATCH_MODEL_ID | \
328 IEEE1394_MATCH_SPECIFIER_ID | \
329 IEEE1394_MATCH_VERSION, \
330 .vendor_id = vendor, \
332 .specifier_id = SPECIFIER_1394TA, \
333 .version = VERSION_AVC, \
334 .driver_data = (kernel_ulong_t)data, \
337 static const struct ieee1394_device_id oxfw_id_table[] = {
340 // Initial firmware has a quirk to postpone isoc packet transmission during finishing async
341 // transaction. As a result, several isochronous cycles are skipped to transfer the packets
342 // and the audio data frames which should have been transferred during the cycles are put
343 // into packet at the first isoc cycle after the postpone. Furthermore, the value of SYT
344 // field in CIP header is not reliable as synchronization timing,
346 OXFW_DEV_ENTRY(VENDOR_GRIFFIN, 0x00f970, &griffin_firewave),
347 OXFW_DEV_ENTRY(VENDOR_LACIE, 0x00f970, &lacie_speakers),
348 // Behringer,F-Control Audio 202. The value of SYT field is not reliable at all.
349 OXFW_DEV_ENTRY(VENDOR_BEHRINGER, 0x00fc22, NULL),
350 // Loud Technologies, Tapco Link.FireWire 4x6. The value of SYT field is always 0xffff.
351 OXFW_DEV_ENTRY(VENDOR_LOUD, 0x000460, NULL),
352 // Loud Technologies, Mackie Onyx Satellite. Although revised version of firmware is
353 // installed to avoid the postpone, the value of SYT field is always 0xffff.
354 OXFW_DEV_ENTRY(VENDOR_LOUD, MODEL_SATELLITE, NULL),
355 // Miglia HarmonyAudio. Not yet identified.
359 // The value of SYT field in CIP header is enough reliable. Both of blocking and non-blocking
360 // transmission methods are available.
362 // Any Mackie(Loud) models (name string/model id):
363 // Onyx-i series (former models): 0x081216
364 // Onyx 1640i: 0x001640
365 // d.2 pro/d.4 pro (built-in card): Unknown
369 .match_flags = IEEE1394_MATCH_VENDOR_ID |
370 IEEE1394_MATCH_SPECIFIER_ID |
371 IEEE1394_MATCH_VERSION,
372 .vendor_id = VENDOR_LOUD,
374 .specifier_id = SPECIFIER_1394TA,
375 .version = VERSION_AVC,
378 OXFW_DEV_ENTRY(VENDOR_TASCAM, 0x800007, NULL),
379 // Stanton, Stanton Controllers & Systems 1 Mixer (SCS.1m).
380 OXFW_DEV_ENTRY(OUI_STANTON, 0x001000, NULL),
381 // Stanton, Stanton Controllers & Systems 1 Deck (SCS.1d).
382 OXFW_DEV_ENTRY(OUI_STANTON, 0x002000, NULL),
383 // APOGEE, duet FireWire.
384 OXFW_DEV_ENTRY(OUI_APOGEE, 0x01dddd, NULL),
387 MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table);
389 static struct fw_driver oxfw_driver = {
391 .owner = THIS_MODULE,
392 .name = KBUILD_MODNAME,
396 .update = oxfw_bus_reset,
397 .remove = oxfw_remove,
398 .id_table = oxfw_id_table,
401 static int __init snd_oxfw_init(void)
403 return driver_register(&oxfw_driver.driver);
406 static void __exit snd_oxfw_exit(void)
408 driver_unregister(&oxfw_driver.driver);
411 module_init(snd_oxfw_init);
412 module_exit(snd_oxfw_exit);