ff.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ff.c - a part of driver for RME Fireface series
  4. *
  5. * Copyright (c) 2015-2017 Takashi Sakamoto
  6. */
  7. #include "ff.h"
  8. #define OUI_RME 0x000a35
  9. MODULE_DESCRIPTION("RME Fireface series Driver");
  10. MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
  11. MODULE_LICENSE("GPL");
  12. static void name_card(struct snd_ff *ff)
  13. {
  14. struct fw_device *fw_dev = fw_parent_device(ff->unit);
  15. static const char *const names[] = {
  16. [SND_FF_UNIT_VERSION_FF800] = "Fireface800",
  17. [SND_FF_UNIT_VERSION_FF400] = "Fireface400",
  18. [SND_FF_UNIT_VERSION_UFX] = "FirefaceUFX",
  19. [SND_FF_UNIT_VERSION_UCX] = "FirefaceUCX",
  20. [SND_FF_UNIT_VERSION_802] = "Fireface802",
  21. };
  22. const char *name;
  23. name = names[ff->unit_version];
  24. strcpy(ff->card->driver, "Fireface");
  25. strcpy(ff->card->shortname, name);
  26. strcpy(ff->card->mixername, name);
  27. snprintf(ff->card->longname, sizeof(ff->card->longname),
  28. "RME %s, GUID %08x%08x at %s, S%d", name,
  29. fw_dev->config_rom[3], fw_dev->config_rom[4],
  30. dev_name(&ff->unit->device), 100 << fw_dev->max_speed);
  31. }
  32. static void ff_card_free(struct snd_card *card)
  33. {
  34. struct snd_ff *ff = card->private_data;
  35. snd_ff_stream_destroy_duplex(ff);
  36. snd_ff_transaction_unregister(ff);
  37. kfree(ff->msg_parser);
  38. mutex_destroy(&ff->mutex);
  39. fw_unit_put(ff->unit);
  40. }
  41. static int snd_ff_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry)
  42. {
  43. struct snd_card *card;
  44. struct snd_ff *ff;
  45. int err;
  46. err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, sizeof(*ff), &card);
  47. if (err < 0)
  48. return err;
  49. card->private_free = ff_card_free;
  50. ff = card->private_data;
  51. ff->unit = fw_unit_get(unit);
  52. dev_set_drvdata(&unit->device, ff);
  53. ff->card = card;
  54. mutex_init(&ff->mutex);
  55. spin_lock_init(&ff->lock);
  56. init_waitqueue_head(&ff->hwdep_wait);
  57. ff->unit_version = entry->version;
  58. ff->spec = (const struct snd_ff_spec *)entry->driver_data;
  59. err = snd_ff_transaction_register(ff);
  60. if (err < 0)
  61. goto error;
  62. name_card(ff);
  63. err = snd_ff_stream_init_duplex(ff);
  64. if (err < 0)
  65. goto error;
  66. snd_ff_proc_init(ff);
  67. err = snd_ff_create_midi_devices(ff);
  68. if (err < 0)
  69. goto error;
  70. err = snd_ff_create_pcm_devices(ff);
  71. if (err < 0)
  72. goto error;
  73. err = snd_ff_create_hwdep_devices(ff);
  74. if (err < 0)
  75. goto error;
  76. if (ff->spec->protocol->msg_parser_size > 0) {
  77. ff->msg_parser = kzalloc(ff->spec->protocol->msg_parser_size, GFP_KERNEL);
  78. if (!ff->msg_parser) {
  79. err = -ENOMEM;
  80. goto error;
  81. }
  82. }
  83. err = snd_card_register(card);
  84. if (err < 0)
  85. goto error;
  86. return 0;
  87. error:
  88. snd_card_free(card);
  89. return err;
  90. }
  91. static void snd_ff_update(struct fw_unit *unit)
  92. {
  93. struct snd_ff *ff = dev_get_drvdata(&unit->device);
  94. snd_ff_transaction_reregister(ff);
  95. snd_ff_stream_update_duplex(ff);
  96. }
  97. static void snd_ff_remove(struct fw_unit *unit)
  98. {
  99. struct snd_ff *ff = dev_get_drvdata(&unit->device);
  100. // Block till all of ALSA character devices are released.
  101. snd_card_free(ff->card);
  102. }
  103. static const struct snd_ff_spec spec_ff800 = {
  104. .pcm_capture_channels = {28, 20, 12},
  105. .pcm_playback_channels = {28, 20, 12},
  106. .midi_in_ports = 1,
  107. .midi_out_ports = 1,
  108. .protocol = &snd_ff_protocol_ff800,
  109. .midi_high_addr = 0x000200000320ull,
  110. .midi_addr_range = 12,
  111. .midi_rx_addrs = {0x000080180000ull, 0},
  112. };
  113. static const struct snd_ff_spec spec_ff400 = {
  114. .pcm_capture_channels = {18, 14, 10},
  115. .pcm_playback_channels = {18, 14, 10},
  116. .midi_in_ports = 2,
  117. .midi_out_ports = 2,
  118. .protocol = &snd_ff_protocol_ff400,
  119. .midi_high_addr = 0x0000801003f4ull,
  120. .midi_addr_range = SND_FF_MAXIMIM_MIDI_QUADS * 4,
  121. .midi_rx_addrs = {0x000080180000ull, 0x000080190000ull},
  122. };
  123. static const struct snd_ff_spec spec_ucx = {
  124. .pcm_capture_channels = {18, 14, 12},
  125. .pcm_playback_channels = {18, 14, 12},
  126. .midi_in_ports = 2,
  127. .midi_out_ports = 2,
  128. .protocol = &snd_ff_protocol_latter,
  129. .midi_high_addr = 0xffff00000034ull,
  130. .midi_addr_range = 0x80,
  131. .midi_rx_addrs = {0xffff00000030ull, 0xffff00000030ull},
  132. };
  133. static const struct snd_ff_spec spec_ufx_802 = {
  134. .pcm_capture_channels = {30, 22, 14},
  135. .pcm_playback_channels = {30, 22, 14},
  136. .midi_in_ports = 1,
  137. .midi_out_ports = 1,
  138. .protocol = &snd_ff_protocol_latter,
  139. .midi_high_addr = 0xffff00000034ull,
  140. .midi_addr_range = 0x80,
  141. .midi_rx_addrs = {0xffff00000030ull, 0xffff00000030ull},
  142. };
  143. static const struct ieee1394_device_id snd_ff_id_table[] = {
  144. /* Fireface 800 */
  145. {
  146. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  147. IEEE1394_MATCH_SPECIFIER_ID |
  148. IEEE1394_MATCH_VERSION |
  149. IEEE1394_MATCH_MODEL_ID,
  150. .vendor_id = OUI_RME,
  151. .specifier_id = OUI_RME,
  152. .version = SND_FF_UNIT_VERSION_FF800,
  153. .model_id = 0x101800,
  154. .driver_data = (kernel_ulong_t)&spec_ff800,
  155. },
  156. /* Fireface 400 */
  157. {
  158. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  159. IEEE1394_MATCH_SPECIFIER_ID |
  160. IEEE1394_MATCH_VERSION |
  161. IEEE1394_MATCH_MODEL_ID,
  162. .vendor_id = OUI_RME,
  163. .specifier_id = OUI_RME,
  164. .version = SND_FF_UNIT_VERSION_FF400,
  165. .model_id = 0x101800,
  166. .driver_data = (kernel_ulong_t)&spec_ff400,
  167. },
  168. // Fireface UFX.
  169. {
  170. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  171. IEEE1394_MATCH_SPECIFIER_ID |
  172. IEEE1394_MATCH_VERSION |
  173. IEEE1394_MATCH_MODEL_ID,
  174. .vendor_id = OUI_RME,
  175. .specifier_id = OUI_RME,
  176. .version = SND_FF_UNIT_VERSION_UFX,
  177. .model_id = 0x101800,
  178. .driver_data = (kernel_ulong_t)&spec_ufx_802,
  179. },
  180. // Fireface UCX.
  181. {
  182. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  183. IEEE1394_MATCH_SPECIFIER_ID |
  184. IEEE1394_MATCH_VERSION |
  185. IEEE1394_MATCH_MODEL_ID,
  186. .vendor_id = OUI_RME,
  187. .specifier_id = OUI_RME,
  188. .version = SND_FF_UNIT_VERSION_UCX,
  189. .model_id = 0x101800,
  190. .driver_data = (kernel_ulong_t)&spec_ucx,
  191. },
  192. // Fireface 802.
  193. {
  194. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  195. IEEE1394_MATCH_SPECIFIER_ID |
  196. IEEE1394_MATCH_VERSION |
  197. IEEE1394_MATCH_MODEL_ID,
  198. .vendor_id = OUI_RME,
  199. .specifier_id = OUI_RME,
  200. .version = SND_FF_UNIT_VERSION_802,
  201. .model_id = 0x101800,
  202. .driver_data = (kernel_ulong_t)&spec_ufx_802,
  203. },
  204. {}
  205. };
  206. MODULE_DEVICE_TABLE(ieee1394, snd_ff_id_table);
  207. static struct fw_driver ff_driver = {
  208. .driver = {
  209. .owner = THIS_MODULE,
  210. .name = KBUILD_MODNAME,
  211. .bus = &fw_bus_type,
  212. },
  213. .probe = snd_ff_probe,
  214. .update = snd_ff_update,
  215. .remove = snd_ff_remove,
  216. .id_table = snd_ff_id_table,
  217. };
  218. static int __init snd_ff_init(void)
  219. {
  220. return driver_register(&ff_driver.driver);
  221. }
  222. static void __exit snd_ff_exit(void)
  223. {
  224. driver_unregister(&ff_driver.driver);
  225. }
  226. module_init(snd_ff_init);
  227. module_exit(snd_ff_exit);