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