1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include "bebob.h"
16
17MODULE_DESCRIPTION("BridgeCo BeBoB driver");
18MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
19MODULE_LICENSE("GPL v2");
20
21static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
22static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
23static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
24
25module_param_array(index, int, NULL, 0444);
26MODULE_PARM_DESC(index, "card index");
27module_param_array(id, charp, NULL, 0444);
28MODULE_PARM_DESC(id, "ID string");
29module_param_array(enable, bool, NULL, 0444);
30MODULE_PARM_DESC(enable, "enable BeBoB sound card");
31
32static DEFINE_MUTEX(devices_mutex);
33static DECLARE_BITMAP(devices_used, SNDRV_CARDS);
34
35
36#define INFO_OFFSET_BEBOB_VERSION 0x08
37#define INFO_OFFSET_GUID 0x10
38#define INFO_OFFSET_HW_MODEL_ID 0x18
39#define INFO_OFFSET_HW_MODEL_REVISION 0x1c
40
41#define VEN_EDIROL 0x000040ab
42#define VEN_PRESONUS 0x00000a92
43#define VEN_BRIDGECO 0x000007f5
44#define VEN_MACKIE1 0x0000000f
45#define VEN_MACKIE2 0x00000ff2
46#define VEN_STANTON 0x00001260
47#define VEN_TASCAM 0x0000022e
48#define VEN_BEHRINGER 0x00001564
49#define VEN_APOGEE 0x000003db
50#define VEN_ESI 0x00000f1b
51#define VEN_ACOUSTIC 0x00000002
52#define VEN_CME 0x0000000a
53#define VEN_PHONIC 0x00001496
54#define VEN_LYNX 0x000019e5
55#define VEN_ICON 0x00001a9e
56#define VEN_PRISMSOUND 0x00001198
57#define VEN_TERRATEC 0x00000aac
58#define VEN_YAMAHA 0x0000a0de
59#define VEN_FOCUSRITE 0x0000130e
60#define VEN_MAUDIO1 0x00000d6c
61#define VEN_MAUDIO2 0x000007f5
62#define VEN_DIGIDESIGN 0x00a07e
63
64#define MODEL_FOCUSRITE_SAFFIRE_BOTH 0x00000000
65#define MODEL_MAUDIO_AUDIOPHILE_BOTH 0x00010060
66#define MODEL_MAUDIO_FW1814 0x00010071
67#define MODEL_MAUDIO_PROJECTMIX 0x00010091
68
69static int
70name_device(struct snd_bebob *bebob)
71{
72 struct fw_device *fw_dev = fw_parent_device(bebob->unit);
73 char vendor[24] = {0};
74 char model[32] = {0};
75 u32 hw_id;
76 u32 data[2] = {0};
77 u32 revision;
78 u32 version;
79 int err;
80
81
82 err = fw_csr_string(fw_dev->config_rom + 5, CSR_VENDOR,
83 vendor, sizeof(vendor));
84 if (err < 0)
85 goto end;
86
87
88 err = fw_csr_string(bebob->unit->directory, CSR_MODEL,
89 model, sizeof(model));
90 if (err < 0)
91 goto end;
92
93
94 err = snd_bebob_read_quad(bebob->unit, INFO_OFFSET_HW_MODEL_ID,
95 &hw_id);
96 if (err < 0)
97 goto end;
98
99
100 err = snd_bebob_read_quad(bebob->unit, INFO_OFFSET_HW_MODEL_REVISION,
101 &revision);
102 if (err < 0)
103 goto end;
104
105
106 err = snd_bebob_read_block(bebob->unit, INFO_OFFSET_GUID,
107 data, sizeof(data));
108 if (err < 0)
109 goto end;
110
111 err = snd_bebob_read_quad(bebob->unit, INFO_OFFSET_BEBOB_VERSION,
112 &version);
113 if (err < 0)
114 goto end;
115 bebob->version = version;
116
117 strcpy(bebob->card->driver, "BeBoB");
118 strcpy(bebob->card->shortname, model);
119 strcpy(bebob->card->mixername, model);
120 snprintf(bebob->card->longname, sizeof(bebob->card->longname),
121 "%s %s (id:%d, rev:%d), GUID %08x%08x at %s, S%d",
122 vendor, model, hw_id, revision,
123 data[0], data[1], dev_name(&bebob->unit->device),
124 100 << fw_dev->max_speed);
125end:
126 return err;
127}
128
129static void bebob_free(struct snd_bebob *bebob)
130{
131 snd_bebob_stream_destroy_duplex(bebob);
132 fw_unit_put(bebob->unit);
133
134 kfree(bebob->maudio_special_quirk);
135
136 mutex_destroy(&bebob->mutex);
137 kfree(bebob);
138}
139
140
141
142
143
144
145
146static void
147bebob_card_free(struct snd_card *card)
148{
149 struct snd_bebob *bebob = card->private_data;
150
151 mutex_lock(&devices_mutex);
152 clear_bit(bebob->card_index, devices_used);
153 mutex_unlock(&devices_mutex);
154
155 bebob_free(card->private_data);
156}
157
158static const struct snd_bebob_spec *
159get_saffire_spec(struct fw_unit *unit)
160{
161 char name[24] = {0};
162
163 if (fw_csr_string(unit->directory, CSR_MODEL, name, sizeof(name)) < 0)
164 return NULL;
165
166 if (strcmp(name, "SaffireLE") == 0)
167 return &saffire_le_spec;
168 else
169 return &saffire_spec;
170}
171
172static bool
173check_audiophile_booted(struct fw_unit *unit)
174{
175 char name[28] = {0};
176
177 if (fw_csr_string(unit->directory, CSR_MODEL, name, sizeof(name)) < 0)
178 return false;
179
180 return strncmp(name, "FW Audiophile Bootloader", 24) != 0;
181}
182
183static void
184do_registration(struct work_struct *work)
185{
186 struct snd_bebob *bebob =
187 container_of(work, struct snd_bebob, dwork.work);
188 unsigned int card_index;
189 int err;
190
191 if (bebob->registered)
192 return;
193
194 mutex_lock(&devices_mutex);
195
196 for (card_index = 0; card_index < SNDRV_CARDS; card_index++) {
197 if (!test_bit(card_index, devices_used) && enable[card_index])
198 break;
199 }
200 if (card_index >= SNDRV_CARDS) {
201 mutex_unlock(&devices_mutex);
202 return;
203 }
204
205 err = snd_card_new(&bebob->unit->device, index[card_index],
206 id[card_index], THIS_MODULE, 0, &bebob->card);
207 if (err < 0) {
208 mutex_unlock(&devices_mutex);
209 return;
210 }
211
212 err = name_device(bebob);
213 if (err < 0)
214 goto error;
215
216 if (bebob->spec == &maudio_special_spec) {
217 if (bebob->entry->model_id == MODEL_MAUDIO_FW1814)
218 err = snd_bebob_maudio_special_discover(bebob, true);
219 else
220 err = snd_bebob_maudio_special_discover(bebob, false);
221 } else {
222 err = snd_bebob_stream_discover(bebob);
223 }
224 if (err < 0)
225 goto error;
226
227 err = snd_bebob_stream_init_duplex(bebob);
228 if (err < 0)
229 goto error;
230
231 snd_bebob_proc_init(bebob);
232
233 if (bebob->midi_input_ports > 0 || bebob->midi_output_ports > 0) {
234 err = snd_bebob_create_midi_devices(bebob);
235 if (err < 0)
236 goto error;
237 }
238
239 err = snd_bebob_create_pcm_devices(bebob);
240 if (err < 0)
241 goto error;
242
243 err = snd_bebob_create_hwdep_device(bebob);
244 if (err < 0)
245 goto error;
246
247 err = snd_card_register(bebob->card);
248 if (err < 0)
249 goto error;
250
251 set_bit(card_index, devices_used);
252 mutex_unlock(&devices_mutex);
253
254
255
256
257
258 bebob->card->private_free = bebob_card_free;
259 bebob->card->private_data = bebob;
260 bebob->registered = true;
261
262 return;
263error:
264 mutex_unlock(&devices_mutex);
265 snd_bebob_stream_destroy_duplex(bebob);
266 snd_card_free(bebob->card);
267 dev_info(&bebob->unit->device,
268 "Sound card registration failed: %d\n", err);
269}
270
271static int
272bebob_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry)
273{
274 struct snd_bebob *bebob;
275 const struct snd_bebob_spec *spec;
276
277 if (entry->vendor_id == VEN_FOCUSRITE &&
278 entry->model_id == MODEL_FOCUSRITE_SAFFIRE_BOTH)
279 spec = get_saffire_spec(unit);
280 else if (entry->vendor_id == VEN_MAUDIO1 &&
281 entry->model_id == MODEL_MAUDIO_AUDIOPHILE_BOTH &&
282 !check_audiophile_booted(unit))
283 spec = NULL;
284 else
285 spec = (const struct snd_bebob_spec *)entry->driver_data;
286
287 if (spec == NULL) {
288 if (entry->vendor_id == VEN_MAUDIO1 ||
289 entry->vendor_id == VEN_MAUDIO2)
290 return snd_bebob_maudio_load_firmware(unit);
291 else
292 return -ENODEV;
293 }
294
295
296 bebob = kzalloc(sizeof(struct snd_bebob), GFP_KERNEL);
297 if (bebob == NULL)
298 return -ENOMEM;
299
300 bebob->unit = fw_unit_get(unit);
301 bebob->entry = entry;
302 bebob->spec = spec;
303 dev_set_drvdata(&unit->device, bebob);
304
305 mutex_init(&bebob->mutex);
306 spin_lock_init(&bebob->lock);
307 init_waitqueue_head(&bebob->hwdep_wait);
308
309
310 INIT_DEFERRABLE_WORK(&bebob->dwork, do_registration);
311
312 if (entry->vendor_id != VEN_MAUDIO1 ||
313 (entry->model_id != MODEL_MAUDIO_FW1814 &&
314 entry->model_id != MODEL_MAUDIO_PROJECTMIX)) {
315 snd_fw_schedule_registration(unit, &bebob->dwork);
316 } else {
317
318
319
320
321
322
323
324
325
326
327 fw_schedule_bus_reset(fw_parent_device(bebob->unit)->card,
328 false, true);
329 }
330
331 return 0;
332}
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350static void
351bebob_update(struct fw_unit *unit)
352{
353 struct snd_bebob *bebob = dev_get_drvdata(&unit->device);
354
355 if (bebob == NULL)
356 return;
357
358
359 if (!bebob->registered)
360 snd_fw_schedule_registration(unit, &bebob->dwork);
361 else
362 fcp_bus_reset(bebob->unit);
363}
364
365static void bebob_remove(struct fw_unit *unit)
366{
367 struct snd_bebob *bebob = dev_get_drvdata(&unit->device);
368
369 if (bebob == NULL)
370 return;
371
372
373
374
375
376
377 cancel_delayed_work_sync(&bebob->dwork);
378
379 if (bebob->registered) {
380
381 snd_card_free_when_closed(bebob->card);
382 } else {
383
384 bebob_free(bebob);
385 }
386}
387
388static const struct snd_bebob_rate_spec normal_rate_spec = {
389 .get = &snd_bebob_stream_get_rate,
390 .set = &snd_bebob_stream_set_rate
391};
392static const struct snd_bebob_spec spec_normal = {
393 .clock = NULL,
394 .rate = &normal_rate_spec,
395 .meter = NULL
396};
397
398static const struct ieee1394_device_id bebob_id_table[] = {
399
400 SND_BEBOB_DEV_ENTRY(VEN_EDIROL, 0x00010049, &spec_normal),
401
402 SND_BEBOB_DEV_ENTRY(VEN_EDIROL, 0x00010048, &spec_normal),
403
404 SND_BEBOB_DEV_ENTRY(VEN_PRESONUS, 0x00010000, &spec_normal),
405
406 SND_BEBOB_DEV_ENTRY(VEN_PRESONUS, 0x00010066, &spec_normal),
407
408 SND_BEBOB_DEV_ENTRY(VEN_PRESONUS, 0x00010001, &spec_normal),
409
410 SND_BEBOB_DEV_ENTRY(VEN_BRIDGECO, 0x00010048, &spec_normal),
411
412 SND_BEBOB_DEV_ENTRY(VEN_BRIDGECO, 0x00010049, &spec_normal),
413
414 SND_BEBOB_DEV_ENTRY(VEN_MACKIE2, 0x00010065, &spec_normal),
415
416 SND_BEBOB_DEV_ENTRY(VEN_MACKIE1, 0x00010067, &spec_normal),
417
418 SND_BEBOB_DEV_ENTRY(VEN_STANTON, 0x00000001, &spec_normal),
419
420 SND_BEBOB_DEV_ENTRY(VEN_TASCAM, 0x00010067, &spec_normal),
421
422 SND_BEBOB_DEV_ENTRY(VEN_BEHRINGER, 0x00001204, &spec_normal),
423
424 SND_BEBOB_DEV_ENTRY(VEN_BEHRINGER, 0x00001604, &spec_normal),
425
426 SND_BEBOB_DEV_ENTRY(VEN_BEHRINGER, 0x00000006, &spec_normal),
427
428 SND_BEBOB_DEV_ENTRY(VEN_BEHRINGER, 0x001616, &spec_normal),
429
430 SND_BEBOB_DEV_ENTRY(VEN_BEHRINGER, 0x000610, &spec_normal),
431
432
433 SND_BEBOB_DEV_ENTRY(VEN_APOGEE, 0x00010048, &spec_normal),
434
435 SND_BEBOB_DEV_ENTRY(VEN_APOGEE, 0x00001eee, &spec_normal),
436
437 SND_BEBOB_DEV_ENTRY(VEN_ESI, 0x00010064, &spec_normal),
438
439 SND_BEBOB_DEV_ENTRY(VEN_ACOUSTIC, 0x00000002, &spec_normal),
440
441 SND_BEBOB_DEV_ENTRY(VEN_CME, 0x00030000, &spec_normal),
442
443 SND_BEBOB_DEV_ENTRY(VEN_PHONIC, 0x00050000, &spec_normal),
444
445 SND_BEBOB_DEV_ENTRY(VEN_PHONIC, 0x00060000, &spec_normal),
446
447 SND_BEBOB_DEV_ENTRY(VEN_PHONIC, 0x00070000, &spec_normal),
448
449 SND_BEBOB_DEV_ENTRY(VEN_PHONIC, 0x00000000, &spec_normal),
450
451 SND_BEBOB_DEV_ENTRY(VEN_LYNX, 0x00000001, &spec_normal),
452
453 SND_BEBOB_DEV_ENTRY(VEN_ICON, 0x00000001, &spec_normal),
454
455 SND_BEBOB_DEV_ENTRY(VEN_PRISMSOUND, 0x00010048, &spec_normal),
456
457 SND_BEBOB_DEV_ENTRY(VEN_PRISMSOUND, 0x0000ada8, &spec_normal),
458
459 SND_BEBOB_DEV_ENTRY(VEN_TERRATEC, 0x00000003, &phase88_rack_spec),
460
461 SND_BEBOB_DEV_ENTRY(VEN_TERRATEC, 0x00000004, &yamaha_terratec_spec),
462
463 SND_BEBOB_DEV_ENTRY(VEN_TERRATEC, 0x00000007, &yamaha_terratec_spec),
464
465 SND_BEBOB_DEV_ENTRY(VEN_TERRATEC, 0x00000005, &spec_normal),
466
467 SND_BEBOB_DEV_ENTRY(VEN_TERRATEC, 0x00000002, &spec_normal),
468
469 SND_BEBOB_DEV_ENTRY(VEN_YAMAHA, 0x0010000b, &yamaha_terratec_spec),
470
471 SND_BEBOB_DEV_ENTRY(VEN_YAMAHA, 0x0010000c, &yamaha_terratec_spec),
472
473 SND_BEBOB_DEV_ENTRY(VEN_FOCUSRITE, 0x00000003, &saffirepro_26_spec),
474
475 SND_BEBOB_DEV_ENTRY(VEN_FOCUSRITE, 0x00000006, &saffirepro_10_spec),
476
477 SND_BEBOB_DEV_ENTRY(VEN_FOCUSRITE, MODEL_FOCUSRITE_SAFFIRE_BOTH,
478 &saffire_spec),
479
480 SND_BEBOB_DEV_ENTRY(VEN_MAUDIO2, 0x00010058, NULL),
481 SND_BEBOB_DEV_ENTRY(VEN_MAUDIO2, 0x00010046, &maudio_fw410_spec),
482
483 SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, MODEL_MAUDIO_AUDIOPHILE_BOTH,
484 &maudio_audiophile_spec),
485
486 SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, 0x00010062, &maudio_solo_spec),
487
488 SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, 0x0000000a, &maudio_ozonic_spec),
489
490 SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, 0x00010081, &maudio_nrv10_spec),
491
492 SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, 0x000100a1, &spec_normal),
493
494 SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, 0x00010070, NULL),
495 SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, MODEL_MAUDIO_FW1814,
496 &maudio_special_spec),
497
498 SND_BEBOB_DEV_ENTRY(VEN_MAUDIO1, MODEL_MAUDIO_PROJECTMIX,
499 &maudio_special_spec),
500
501 SND_BEBOB_DEV_ENTRY(VEN_DIGIDESIGN, 0x0000a9, &spec_normal),
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518 {}
519};
520MODULE_DEVICE_TABLE(ieee1394, bebob_id_table);
521
522static struct fw_driver bebob_driver = {
523 .driver = {
524 .owner = THIS_MODULE,
525 .name = "snd-bebob",
526 .bus = &fw_bus_type,
527 },
528 .probe = bebob_probe,
529 .update = bebob_update,
530 .remove = bebob_remove,
531 .id_table = bebob_id_table,
532};
533
534static int __init
535snd_bebob_init(void)
536{
537 return driver_register(&bebob_driver.driver);
538}
539
540static void __exit
541snd_bebob_exit(void)
542{
543 driver_unregister(&bebob_driver.driver);
544}
545
546module_init(snd_bebob_init);
547module_exit(snd_bebob_exit);
548