interconnect: Add a common standard aggregate function
[linux/fpc-iii.git] / sound / firewire / oxfw / oxfw.c
blobfb6df3fc018edc27bf6964c57f67d761d6088f4f
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * oxfw.c - a part of driver for OXFW970/971 based devices
5 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
6 */
8 #include "oxfw.h"
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");
36 struct compat_info {
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[] = {
45 "Onyxi",
46 "Onyx-i",
47 "Onyx 1640i",
48 "d.Pro",
49 "Mackie Onyx Satellite",
50 "Tapco LINK.firewire 4x6",
51 "U.420"};
52 char model[32];
53 int err;
55 err = fw_csr_string(unit->directory, CSR_MODEL,
56 model, sizeof(model));
57 if (err < 0)
58 return false;
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;
67 char vendor[24];
68 char model[32];
69 const char *d, *v, *m;
70 u32 firmware;
71 int err;
73 /* get vendor name from root directory */
74 err = fw_csr_string(fw_dev->config_rom + 5, CSR_VENDOR,
75 vendor, sizeof(vendor));
76 if (err < 0)
77 goto end;
79 /* get model name from unit directory */
80 err = fw_csr_string(oxfw->unit->directory, CSR_MODEL,
81 model, sizeof(model));
82 if (err < 0)
83 goto end;
85 err = snd_fw_transaction(oxfw->unit, TCODE_READ_QUADLET_REQUEST,
86 OXFORD_FIRMWARE_ID_ADDRESS, &firmware, 4, 0);
87 if (err < 0)
88 goto end;
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;
97 m = info->model_name;
98 } else {
99 d = "OXFW";
100 v = vendor;
101 m = model;
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);
113 end:
114 return err;
117 static void oxfw_card_free(struct snd_card *card)
119 struct snd_oxfw *oxfw = card->private_data;
121 snd_oxfw_stream_destroy_duplex(oxfw);
124 static int detect_quirks(struct snd_oxfw *oxfw)
126 struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
127 struct fw_csr_iterator it;
128 int key, val;
129 int vendor, model;
132 * Add ALSA control elements for two models to keep compatibility to
133 * old firewire-speaker module.
135 if (oxfw->entry->vendor_id == VENDOR_GRIFFIN)
136 return snd_oxfw_add_spkr(oxfw, false);
137 if (oxfw->entry->vendor_id == VENDOR_LACIE)
138 return snd_oxfw_add_spkr(oxfw, true);
141 * Stanton models supports asynchronous transactions for unique MIDI
142 * messages.
144 if (oxfw->entry->vendor_id == OUI_STANTON) {
145 /* No physical MIDI ports. */
146 oxfw->midi_input_ports = 0;
147 oxfw->midi_output_ports = 0;
149 return snd_oxfw_scs1x_add(oxfw);
153 * TASCAM FireOne has physical control and requires a pair of additional
154 * MIDI ports.
156 if (oxfw->entry->vendor_id == VENDOR_TASCAM) {
157 oxfw->midi_input_ports++;
158 oxfw->midi_output_ports++;
159 return 0;
162 /* Seek from Root Directory of Config ROM. */
163 vendor = model = 0;
164 fw_csr_iterator_init(&it, fw_dev->config_rom + 5);
165 while (fw_csr_iterator_next(&it, &key, &val)) {
166 if (key == CSR_VENDOR)
167 vendor = val;
168 else if (key == CSR_MODEL)
169 model = val;
173 * Mackie Onyx Satellite with base station has a quirk to report a wrong
174 * value in 'dbs' field of CIP header against its format information.
176 if (vendor == VENDOR_LOUD && model == MODEL_SATELLITE)
177 oxfw->wrong_dbs = true;
179 return 0;
182 static void do_registration(struct work_struct *work)
184 struct snd_oxfw *oxfw = container_of(work, struct snd_oxfw, dwork.work);
185 int err;
187 if (oxfw->registered)
188 return;
190 err = snd_card_new(&oxfw->unit->device, -1, NULL, THIS_MODULE, 0,
191 &oxfw->card);
192 if (err < 0)
193 return;
194 oxfw->card->private_free = oxfw_card_free;
195 oxfw->card->private_data = oxfw;
197 err = name_card(oxfw);
198 if (err < 0)
199 goto error;
201 err = snd_oxfw_stream_discover(oxfw);
202 if (err < 0)
203 goto error;
205 err = detect_quirks(oxfw);
206 if (err < 0)
207 goto error;
209 err = snd_oxfw_stream_init_duplex(oxfw);
210 if (err < 0)
211 goto error;
213 err = snd_oxfw_create_pcm(oxfw);
214 if (err < 0)
215 goto error;
217 snd_oxfw_proc_init(oxfw);
219 err = snd_oxfw_create_midi(oxfw);
220 if (err < 0)
221 goto error;
223 err = snd_oxfw_create_hwdep(oxfw);
224 if (err < 0)
225 goto error;
227 err = snd_card_register(oxfw->card);
228 if (err < 0)
229 goto error;
231 oxfw->registered = true;
233 return;
234 error:
235 snd_card_free(oxfw->card);
236 dev_info(&oxfw->unit->device,
237 "Sound card registration failed: %d\n", err);
240 static int oxfw_probe(struct fw_unit *unit,
241 const struct ieee1394_device_id *entry)
243 struct snd_oxfw *oxfw;
245 if (entry->vendor_id == VENDOR_LOUD && !detect_loud_models(unit))
246 return -ENODEV;
248 /* Allocate this independent of sound card instance. */
249 oxfw = devm_kzalloc(&unit->device, sizeof(struct snd_oxfw), GFP_KERNEL);
250 if (!oxfw)
251 return -ENOMEM;
252 oxfw->unit = fw_unit_get(unit);
253 dev_set_drvdata(&unit->device, oxfw);
255 oxfw->entry = entry;
256 mutex_init(&oxfw->mutex);
257 spin_lock_init(&oxfw->lock);
258 init_waitqueue_head(&oxfw->hwdep_wait);
260 /* Allocate and register this sound card later. */
261 INIT_DEFERRABLE_WORK(&oxfw->dwork, do_registration);
262 snd_fw_schedule_registration(unit, &oxfw->dwork);
264 return 0;
267 static void oxfw_bus_reset(struct fw_unit *unit)
269 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
271 if (!oxfw->registered)
272 snd_fw_schedule_registration(unit, &oxfw->dwork);
274 fcp_bus_reset(oxfw->unit);
276 if (oxfw->registered) {
277 mutex_lock(&oxfw->mutex);
278 snd_oxfw_stream_update_duplex(oxfw);
279 mutex_unlock(&oxfw->mutex);
281 if (oxfw->entry->vendor_id == OUI_STANTON)
282 snd_oxfw_scs1x_update(oxfw);
286 static void oxfw_remove(struct fw_unit *unit)
288 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
291 * Confirm to stop the work for registration before the sound card is
292 * going to be released. The work is not scheduled again because bus
293 * reset handler is not called anymore.
295 cancel_delayed_work_sync(&oxfw->dwork);
297 if (oxfw->registered) {
298 // Block till all of ALSA character devices are released.
299 snd_card_free(oxfw->card);
302 mutex_destroy(&oxfw->mutex);
303 fw_unit_put(oxfw->unit);
306 static const struct compat_info griffin_firewave = {
307 .driver_name = "FireWave",
308 .vendor_name = "Griffin",
309 .model_name = "FireWave",
312 static const struct compat_info lacie_speakers = {
313 .driver_name = "FWSpeakers",
314 .vendor_name = "LaCie",
315 .model_name = "FireWire Speakers",
318 static const struct ieee1394_device_id oxfw_id_table[] = {
320 .match_flags = IEEE1394_MATCH_VENDOR_ID |
321 IEEE1394_MATCH_MODEL_ID |
322 IEEE1394_MATCH_SPECIFIER_ID |
323 IEEE1394_MATCH_VERSION,
324 .vendor_id = VENDOR_GRIFFIN,
325 .model_id = 0x00f970,
326 .specifier_id = SPECIFIER_1394TA,
327 .version = VERSION_AVC,
328 .driver_data = (kernel_ulong_t)&griffin_firewave,
331 .match_flags = IEEE1394_MATCH_VENDOR_ID |
332 IEEE1394_MATCH_MODEL_ID |
333 IEEE1394_MATCH_SPECIFIER_ID |
334 IEEE1394_MATCH_VERSION,
335 .vendor_id = VENDOR_LACIE,
336 .model_id = 0x00f970,
337 .specifier_id = SPECIFIER_1394TA,
338 .version = VERSION_AVC,
339 .driver_data = (kernel_ulong_t)&lacie_speakers,
341 /* Behringer,F-Control Audio 202 */
343 .match_flags = IEEE1394_MATCH_VENDOR_ID |
344 IEEE1394_MATCH_MODEL_ID,
345 .vendor_id = VENDOR_BEHRINGER,
346 .model_id = 0x00fc22,
349 * Any Mackie(Loud) models (name string/model id):
350 * Onyx-i series (former models): 0x081216
351 * Mackie Onyx Satellite: 0x00200f
352 * Tapco LINK.firewire 4x6: 0x000460
353 * d.2 pro: Unknown
354 * d.4 pro: Unknown
355 * U.420: Unknown
356 * U.420d: Unknown
359 .match_flags = IEEE1394_MATCH_VENDOR_ID |
360 IEEE1394_MATCH_SPECIFIER_ID |
361 IEEE1394_MATCH_VERSION,
362 .vendor_id = VENDOR_LOUD,
363 .specifier_id = SPECIFIER_1394TA,
364 .version = VERSION_AVC,
366 /* TASCAM, FireOne */
368 .match_flags = IEEE1394_MATCH_VENDOR_ID |
369 IEEE1394_MATCH_MODEL_ID,
370 .vendor_id = VENDOR_TASCAM,
371 .model_id = 0x800007,
373 /* Stanton, Stanton Controllers & Systems 1 Mixer (SCS.1m) */
375 .match_flags = IEEE1394_MATCH_VENDOR_ID |
376 IEEE1394_MATCH_MODEL_ID,
377 .vendor_id = OUI_STANTON,
378 .model_id = 0x001000,
380 /* Stanton, Stanton Controllers & Systems 1 Deck (SCS.1d) */
382 .match_flags = IEEE1394_MATCH_VENDOR_ID |
383 IEEE1394_MATCH_MODEL_ID,
384 .vendor_id = OUI_STANTON,
385 .model_id = 0x002000,
387 // APOGEE, duet FireWire
389 .match_flags = IEEE1394_MATCH_VENDOR_ID |
390 IEEE1394_MATCH_MODEL_ID,
391 .vendor_id = OUI_APOGEE,
392 .model_id = 0x01dddd,
396 MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table);
398 static struct fw_driver oxfw_driver = {
399 .driver = {
400 .owner = THIS_MODULE,
401 .name = KBUILD_MODNAME,
402 .bus = &fw_bus_type,
404 .probe = oxfw_probe,
405 .update = oxfw_bus_reset,
406 .remove = oxfw_remove,
407 .id_table = oxfw_id_table,
410 static int __init snd_oxfw_init(void)
412 return driver_register(&oxfw_driver.driver);
415 static void __exit snd_oxfw_exit(void)
417 driver_unregister(&oxfw_driver.driver);
420 module_init(snd_oxfw_init);
421 module_exit(snd_oxfw_exit);