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