dice.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * TC Applied Technologies Digital Interface Communications Engine driver
  4. *
  5. * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
  6. */
  7. #include "dice.h"
  8. MODULE_DESCRIPTION("DICE driver");
  9. MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
  10. MODULE_LICENSE("GPL");
  11. #define OUI_WEISS 0x001c6a
  12. #define OUI_LOUD 0x000ff2
  13. #define OUI_FOCUSRITE 0x00130e
  14. #define OUI_TCELECTRONIC 0x000166
  15. #define OUI_ALESIS 0x000595
  16. #define OUI_MAUDIO 0x000d6c
  17. #define OUI_MYTEK 0x001ee8
  18. #define OUI_SSL 0x0050c2 // Actually ID reserved by IEEE.
  19. #define OUI_PRESONUS 0x000a92
  20. #define OUI_HARMAN 0x000fd7
  21. #define OUI_AVID 0x00a07e
  22. #define DICE_CATEGORY_ID 0x04
  23. #define WEISS_CATEGORY_ID 0x00
  24. #define LOUD_CATEGORY_ID 0x10
  25. #define HARMAN_CATEGORY_ID 0x20
  26. #define MODEL_ALESIS_IO_BOTH 0x000001
  27. static int check_dice_category(struct fw_unit *unit)
  28. {
  29. struct fw_device *device = fw_parent_device(unit);
  30. struct fw_csr_iterator it;
  31. int key, val, vendor = -1, model = -1;
  32. unsigned int category;
  33. /*
  34. * Check that GUID and unit directory are constructed according to DICE
  35. * rules, i.e., that the specifier ID is the GUID's OUI, and that the
  36. * GUID chip ID consists of the 8-bit category ID, the 10-bit product
  37. * ID, and a 22-bit serial number.
  38. */
  39. fw_csr_iterator_init(&it, unit->directory);
  40. while (fw_csr_iterator_next(&it, &key, &val)) {
  41. switch (key) {
  42. case CSR_SPECIFIER_ID:
  43. vendor = val;
  44. break;
  45. case CSR_MODEL:
  46. model = val;
  47. break;
  48. }
  49. }
  50. if (vendor == OUI_WEISS)
  51. category = WEISS_CATEGORY_ID;
  52. else if (vendor == OUI_LOUD)
  53. category = LOUD_CATEGORY_ID;
  54. else if (vendor == OUI_HARMAN)
  55. category = HARMAN_CATEGORY_ID;
  56. else
  57. category = DICE_CATEGORY_ID;
  58. if (device->config_rom[3] != ((vendor << 8) | category) ||
  59. device->config_rom[4] >> 22 != model)
  60. return -ENODEV;
  61. return 0;
  62. }
  63. static int check_clock_caps(struct snd_dice *dice)
  64. {
  65. __be32 value;
  66. int err;
  67. /* some very old firmwares don't tell about their clock support */
  68. if (dice->clock_caps > 0) {
  69. err = snd_dice_transaction_read_global(dice,
  70. GLOBAL_CLOCK_CAPABILITIES,
  71. &value, 4);
  72. if (err < 0)
  73. return err;
  74. dice->clock_caps = be32_to_cpu(value);
  75. } else {
  76. /* this should be supported by any device */
  77. dice->clock_caps = CLOCK_CAP_RATE_44100 |
  78. CLOCK_CAP_RATE_48000 |
  79. CLOCK_CAP_SOURCE_ARX1 |
  80. CLOCK_CAP_SOURCE_INTERNAL;
  81. }
  82. return 0;
  83. }
  84. static void dice_card_strings(struct snd_dice *dice)
  85. {
  86. struct snd_card *card = dice->card;
  87. struct fw_device *dev = fw_parent_device(dice->unit);
  88. char vendor[32], model[32];
  89. unsigned int i;
  90. int err;
  91. strcpy(card->driver, "DICE");
  92. strcpy(card->shortname, "DICE");
  93. BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
  94. err = snd_dice_transaction_read_global(dice, GLOBAL_NICK_NAME,
  95. card->shortname,
  96. sizeof(card->shortname));
  97. if (err >= 0) {
  98. /* DICE strings are returned in "always-wrong" endianness */
  99. BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
  100. for (i = 0; i < sizeof(card->shortname); i += 4)
  101. swab32s((u32 *)&card->shortname[i]);
  102. card->shortname[sizeof(card->shortname) - 1] = '\0';
  103. }
  104. strcpy(vendor, "?");
  105. fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
  106. strcpy(model, "?");
  107. fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
  108. snprintf(card->longname, sizeof(card->longname),
  109. "%s %s (serial %u) at %s, S%d",
  110. vendor, model, dev->config_rom[4] & 0x3fffff,
  111. dev_name(&dice->unit->device), 100 << dev->max_speed);
  112. strcpy(card->mixername, "DICE");
  113. }
  114. static void dice_card_free(struct snd_card *card)
  115. {
  116. struct snd_dice *dice = card->private_data;
  117. snd_dice_stream_destroy_duplex(dice);
  118. snd_dice_transaction_destroy(dice);
  119. mutex_destroy(&dice->mutex);
  120. fw_unit_put(dice->unit);
  121. }
  122. static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry)
  123. {
  124. struct snd_card *card;
  125. struct snd_dice *dice;
  126. snd_dice_detect_formats_t detect_formats;
  127. int err;
  128. if (!entry->driver_data && entry->vendor_id != OUI_SSL) {
  129. err = check_dice_category(unit);
  130. if (err < 0)
  131. return -ENODEV;
  132. }
  133. err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, sizeof(*dice), &card);
  134. if (err < 0)
  135. return err;
  136. card->private_free = dice_card_free;
  137. dice = card->private_data;
  138. dice->unit = fw_unit_get(unit);
  139. dev_set_drvdata(&unit->device, dice);
  140. dice->card = card;
  141. if (!entry->driver_data)
  142. detect_formats = snd_dice_stream_detect_current_formats;
  143. else
  144. detect_formats = (snd_dice_detect_formats_t)entry->driver_data;
  145. // Below models are compliant to IEC 61883-1/6 and have no quirk at high sampling transfer
  146. // frequency.
  147. // * Avid M-Box 3 Pro
  148. // * M-Audio Profire 610
  149. // * M-Audio Profire 2626
  150. if (entry->vendor_id == OUI_MAUDIO || entry->vendor_id == OUI_AVID)
  151. dice->disable_double_pcm_frames = true;
  152. spin_lock_init(&dice->lock);
  153. mutex_init(&dice->mutex);
  154. init_completion(&dice->clock_accepted);
  155. init_waitqueue_head(&dice->hwdep_wait);
  156. err = snd_dice_transaction_init(dice);
  157. if (err < 0)
  158. goto error;
  159. err = check_clock_caps(dice);
  160. if (err < 0)
  161. goto error;
  162. dice_card_strings(dice);
  163. err = detect_formats(dice);
  164. if (err < 0)
  165. goto error;
  166. err = snd_dice_stream_init_duplex(dice);
  167. if (err < 0)
  168. goto error;
  169. snd_dice_create_proc(dice);
  170. err = snd_dice_create_pcm(dice);
  171. if (err < 0)
  172. goto error;
  173. err = snd_dice_create_midi(dice);
  174. if (err < 0)
  175. goto error;
  176. err = snd_dice_create_hwdep(dice);
  177. if (err < 0)
  178. goto error;
  179. err = snd_card_register(card);
  180. if (err < 0)
  181. goto error;
  182. return 0;
  183. error:
  184. snd_card_free(card);
  185. return err;
  186. }
  187. static void dice_remove(struct fw_unit *unit)
  188. {
  189. struct snd_dice *dice = dev_get_drvdata(&unit->device);
  190. // Block till all of ALSA character devices are released.
  191. snd_card_free(dice->card);
  192. }
  193. static void dice_bus_reset(struct fw_unit *unit)
  194. {
  195. struct snd_dice *dice = dev_get_drvdata(&unit->device);
  196. /* The handler address register becomes initialized. */
  197. snd_dice_transaction_reinit(dice);
  198. mutex_lock(&dice->mutex);
  199. snd_dice_stream_update_duplex(dice);
  200. mutex_unlock(&dice->mutex);
  201. }
  202. #define DICE_INTERFACE 0x000001
  203. #define DICE_DEV_ENTRY_TYPICAL(vendor, model, data) \
  204. { \
  205. .match_flags = IEEE1394_MATCH_VENDOR_ID | \
  206. IEEE1394_MATCH_MODEL_ID | \
  207. IEEE1394_MATCH_SPECIFIER_ID | \
  208. IEEE1394_MATCH_VERSION, \
  209. .vendor_id = (vendor), \
  210. .model_id = (model), \
  211. .specifier_id = (vendor), \
  212. .version = DICE_INTERFACE, \
  213. .driver_data = (kernel_ulong_t)(data), \
  214. }
  215. static const struct ieee1394_device_id dice_id_table[] = {
  216. // Avid M-Box 3 Pro. To match in probe function.
  217. DICE_DEV_ENTRY_TYPICAL(OUI_AVID, 0x000004, snd_dice_detect_extension_formats),
  218. /* M-Audio Profire 2626 has a different value in version field. */
  219. {
  220. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  221. IEEE1394_MATCH_MODEL_ID,
  222. .vendor_id = OUI_MAUDIO,
  223. .model_id = 0x000010,
  224. .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
  225. },
  226. /* M-Audio Profire 610 has a different value in version field. */
  227. {
  228. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  229. IEEE1394_MATCH_MODEL_ID,
  230. .vendor_id = OUI_MAUDIO,
  231. .model_id = 0x000011,
  232. .driver_data = (kernel_ulong_t)snd_dice_detect_extension_formats,
  233. },
  234. /* TC Electronic Konnekt 24D. */
  235. {
  236. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  237. IEEE1394_MATCH_MODEL_ID,
  238. .vendor_id = OUI_TCELECTRONIC,
  239. .model_id = 0x000020,
  240. .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
  241. },
  242. /* TC Electronic Konnekt 8. */
  243. {
  244. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  245. IEEE1394_MATCH_MODEL_ID,
  246. .vendor_id = OUI_TCELECTRONIC,
  247. .model_id = 0x000021,
  248. .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
  249. },
  250. /* TC Electronic Studio Konnekt 48. */
  251. {
  252. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  253. IEEE1394_MATCH_MODEL_ID,
  254. .vendor_id = OUI_TCELECTRONIC,
  255. .model_id = 0x000022,
  256. .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
  257. },
  258. /* TC Electronic Konnekt Live. */
  259. {
  260. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  261. IEEE1394_MATCH_MODEL_ID,
  262. .vendor_id = OUI_TCELECTRONIC,
  263. .model_id = 0x000023,
  264. .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
  265. },
  266. /* TC Electronic Desktop Konnekt 6. */
  267. {
  268. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  269. IEEE1394_MATCH_MODEL_ID,
  270. .vendor_id = OUI_TCELECTRONIC,
  271. .model_id = 0x000024,
  272. .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
  273. },
  274. /* TC Electronic Impact Twin. */
  275. {
  276. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  277. IEEE1394_MATCH_MODEL_ID,
  278. .vendor_id = OUI_TCELECTRONIC,
  279. .model_id = 0x000027,
  280. .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
  281. },
  282. /* TC Electronic Digital Konnekt x32. */
  283. {
  284. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  285. IEEE1394_MATCH_MODEL_ID,
  286. .vendor_id = OUI_TCELECTRONIC,
  287. .model_id = 0x000030,
  288. .driver_data = (kernel_ulong_t)snd_dice_detect_tcelectronic_formats,
  289. },
  290. /* Alesis iO14/iO26. */
  291. {
  292. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  293. IEEE1394_MATCH_MODEL_ID,
  294. .vendor_id = OUI_ALESIS,
  295. .model_id = MODEL_ALESIS_IO_BOTH,
  296. .driver_data = (kernel_ulong_t)snd_dice_detect_alesis_formats,
  297. },
  298. // Alesis MasterControl.
  299. {
  300. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  301. IEEE1394_MATCH_MODEL_ID,
  302. .vendor_id = OUI_ALESIS,
  303. .model_id = 0x000002,
  304. .driver_data = (kernel_ulong_t)snd_dice_detect_alesis_mastercontrol_formats,
  305. },
  306. /* Mytek Stereo 192 DSD-DAC. */
  307. {
  308. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  309. IEEE1394_MATCH_MODEL_ID,
  310. .vendor_id = OUI_MYTEK,
  311. .model_id = 0x000002,
  312. .driver_data = (kernel_ulong_t)snd_dice_detect_mytek_formats,
  313. },
  314. // Solid State Logic, Duende Classic and Mini.
  315. // NOTE: each field of GUID in config ROM is not compliant to standard
  316. // DICE scheme.
  317. {
  318. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  319. IEEE1394_MATCH_MODEL_ID,
  320. .vendor_id = OUI_SSL,
  321. .model_id = 0x000070,
  322. },
  323. // Presonus FireStudio.
  324. {
  325. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  326. IEEE1394_MATCH_MODEL_ID,
  327. .vendor_id = OUI_PRESONUS,
  328. .model_id = 0x000008,
  329. .driver_data = (kernel_ulong_t)snd_dice_detect_presonus_formats,
  330. },
  331. // Lexicon I-ONYX FW810S.
  332. {
  333. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  334. IEEE1394_MATCH_MODEL_ID,
  335. .vendor_id = OUI_HARMAN,
  336. .model_id = 0x000001,
  337. .driver_data = (kernel_ulong_t)snd_dice_detect_harman_formats,
  338. },
  339. // Focusrite Saffire Pro 40 with TCD3070-CH.
  340. // The model has quirk in its GUID, in which model field is 0x000013 and different from
  341. // model ID (0x0000de) in its root/unit directory.
  342. {
  343. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  344. IEEE1394_MATCH_MODEL_ID,
  345. .vendor_id = OUI_FOCUSRITE,
  346. .model_id = 0x0000de,
  347. .driver_data = (kernel_ulong_t)snd_dice_detect_focusrite_pro40_tcd3070_formats,
  348. },
  349. // Weiss DAC202: 192kHz 2-channel DAC
  350. {
  351. .match_flags = IEEE1394_MATCH_VENDOR_ID | IEEE1394_MATCH_MODEL_ID,
  352. .vendor_id = OUI_WEISS,
  353. .model_id = 0x000007,
  354. .driver_data = (kernel_ulong_t)snd_dice_detect_weiss_formats,
  355. },
  356. // Weiss DAC202: 192kHz 2-channel DAC (Maya edition)
  357. {
  358. .match_flags = IEEE1394_MATCH_VENDOR_ID | IEEE1394_MATCH_MODEL_ID,
  359. .vendor_id = OUI_WEISS,
  360. .model_id = 0x000008,
  361. .driver_data = (kernel_ulong_t)snd_dice_detect_weiss_formats,
  362. },
  363. // Weiss MAN301: 192kHz 2-channel music archive network player
  364. {
  365. .match_flags = IEEE1394_MATCH_VENDOR_ID | IEEE1394_MATCH_MODEL_ID,
  366. .vendor_id = OUI_WEISS,
  367. .model_id = 0x00000b,
  368. .driver_data = (kernel_ulong_t)snd_dice_detect_weiss_formats,
  369. },
  370. // Weiss INT202: 192kHz unidirectional 2-channel digital Firewire face
  371. {
  372. .match_flags = IEEE1394_MATCH_VENDOR_ID | IEEE1394_MATCH_MODEL_ID,
  373. .vendor_id = OUI_WEISS,
  374. .model_id = 0x000006,
  375. .driver_data = (kernel_ulong_t)snd_dice_detect_weiss_formats,
  376. },
  377. // Weiss INT203: 192kHz bidirectional 2-channel digital Firewire face
  378. {
  379. .match_flags = IEEE1394_MATCH_VENDOR_ID | IEEE1394_MATCH_MODEL_ID,
  380. .vendor_id = OUI_WEISS,
  381. .model_id = 0x00000a,
  382. .driver_data = (kernel_ulong_t)snd_dice_detect_weiss_formats,
  383. },
  384. // Weiss ADC2: 192kHz A/D converter with microphone preamps and inputs
  385. {
  386. .match_flags = IEEE1394_MATCH_VENDOR_ID | IEEE1394_MATCH_MODEL_ID,
  387. .vendor_id = OUI_WEISS,
  388. .model_id = 0x000001,
  389. .driver_data = (kernel_ulong_t)snd_dice_detect_weiss_formats,
  390. },
  391. // Weiss DAC2/Minerva: 192kHz 2-channel DAC
  392. {
  393. .match_flags = IEEE1394_MATCH_VENDOR_ID | IEEE1394_MATCH_MODEL_ID,
  394. .vendor_id = OUI_WEISS,
  395. .model_id = 0x000003,
  396. .driver_data = (kernel_ulong_t)snd_dice_detect_weiss_formats,
  397. },
  398. // Weiss Vesta: 192kHz 2-channel Firewire to AES/EBU interface
  399. {
  400. .match_flags = IEEE1394_MATCH_VENDOR_ID | IEEE1394_MATCH_MODEL_ID,
  401. .vendor_id = OUI_WEISS,
  402. .model_id = 0x000002,
  403. .driver_data = (kernel_ulong_t)snd_dice_detect_weiss_formats,
  404. },
  405. // Weiss AFI1: 192kHz 24-channel Firewire to ADAT or AES/EBU face
  406. {
  407. .match_flags = IEEE1394_MATCH_VENDOR_ID | IEEE1394_MATCH_MODEL_ID,
  408. .vendor_id = OUI_WEISS,
  409. .model_id = 0x000004,
  410. .driver_data = (kernel_ulong_t)snd_dice_detect_weiss_formats,
  411. },
  412. {
  413. .match_flags = IEEE1394_MATCH_VERSION,
  414. .version = DICE_INTERFACE,
  415. },
  416. { }
  417. };
  418. MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
  419. static struct fw_driver dice_driver = {
  420. .driver = {
  421. .owner = THIS_MODULE,
  422. .name = KBUILD_MODNAME,
  423. .bus = &fw_bus_type,
  424. },
  425. .probe = dice_probe,
  426. .update = dice_bus_reset,
  427. .remove = dice_remove,
  428. .id_table = dice_id_table,
  429. };
  430. static int __init alsa_dice_init(void)
  431. {
  432. return driver_register(&dice_driver.driver);
  433. }
  434. static void __exit alsa_dice_exit(void)
  435. {
  436. driver_unregister(&dice_driver.driver);
  437. }
  438. module_init(alsa_dice_init);
  439. module_exit(alsa_dice_exit);