ff.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * ff.c - a part of driver for RME Fireface series
  3. *
  4. * Copyright (c) 2015-2017 Takashi Sakamoto
  5. *
  6. * Licensed under the terms of the GNU General Public License, version 2.
  7. */
  8. #include "ff.h"
  9. #define OUI_RME 0x000a35
  10. MODULE_DESCRIPTION("RME Fireface series Driver");
  11. MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
  12. MODULE_LICENSE("GPL v2");
  13. static void name_card(struct snd_ff *ff)
  14. {
  15. struct fw_device *fw_dev = fw_parent_device(ff->unit);
  16. strcpy(ff->card->driver, "Fireface");
  17. strcpy(ff->card->shortname, ff->spec->name);
  18. strcpy(ff->card->mixername, ff->spec->name);
  19. snprintf(ff->card->longname, sizeof(ff->card->longname),
  20. "RME %s, GUID %08x%08x at %s, S%d", ff->spec->name,
  21. fw_dev->config_rom[3], fw_dev->config_rom[4],
  22. dev_name(&ff->unit->device), 100 << fw_dev->max_speed);
  23. }
  24. static void ff_free(struct snd_ff *ff)
  25. {
  26. snd_ff_stream_destroy_duplex(ff);
  27. snd_ff_transaction_unregister(ff);
  28. fw_unit_put(ff->unit);
  29. mutex_destroy(&ff->mutex);
  30. kfree(ff);
  31. }
  32. static void ff_card_free(struct snd_card *card)
  33. {
  34. ff_free(card->private_data);
  35. }
  36. static void do_registration(struct work_struct *work)
  37. {
  38. struct snd_ff *ff = container_of(work, struct snd_ff, dwork.work);
  39. int err;
  40. if (ff->registered)
  41. return;
  42. err = snd_card_new(&ff->unit->device, -1, NULL, THIS_MODULE, 0,
  43. &ff->card);
  44. if (err < 0)
  45. return;
  46. err = snd_ff_transaction_register(ff);
  47. if (err < 0)
  48. goto error;
  49. name_card(ff);
  50. err = snd_ff_stream_init_duplex(ff);
  51. if (err < 0)
  52. goto error;
  53. snd_ff_proc_init(ff);
  54. err = snd_ff_create_midi_devices(ff);
  55. if (err < 0)
  56. goto error;
  57. err = snd_ff_create_pcm_devices(ff);
  58. if (err < 0)
  59. goto error;
  60. err = snd_ff_create_hwdep_devices(ff);
  61. if (err < 0)
  62. goto error;
  63. err = snd_card_register(ff->card);
  64. if (err < 0)
  65. goto error;
  66. ff->card->private_free = ff_card_free;
  67. ff->card->private_data = ff;
  68. ff->registered = true;
  69. return;
  70. error:
  71. snd_ff_transaction_unregister(ff);
  72. snd_ff_stream_destroy_duplex(ff);
  73. snd_card_free(ff->card);
  74. dev_info(&ff->unit->device,
  75. "Sound card registration failed: %d\n", err);
  76. }
  77. static int snd_ff_probe(struct fw_unit *unit,
  78. const struct ieee1394_device_id *entry)
  79. {
  80. struct snd_ff *ff;
  81. ff = kzalloc(sizeof(struct snd_ff), GFP_KERNEL);
  82. if (ff == NULL)
  83. return -ENOMEM;
  84. /* initialize myself */
  85. ff->unit = fw_unit_get(unit);
  86. dev_set_drvdata(&unit->device, ff);
  87. mutex_init(&ff->mutex);
  88. spin_lock_init(&ff->lock);
  89. init_waitqueue_head(&ff->hwdep_wait);
  90. ff->spec = (const struct snd_ff_spec *)entry->driver_data;
  91. /* Register this sound card later. */
  92. INIT_DEFERRABLE_WORK(&ff->dwork, do_registration);
  93. snd_fw_schedule_registration(unit, &ff->dwork);
  94. return 0;
  95. }
  96. static void snd_ff_update(struct fw_unit *unit)
  97. {
  98. struct snd_ff *ff = dev_get_drvdata(&unit->device);
  99. /* Postpone a workqueue for deferred registration. */
  100. if (!ff->registered)
  101. snd_fw_schedule_registration(unit, &ff->dwork);
  102. snd_ff_transaction_reregister(ff);
  103. if (ff->registered)
  104. snd_ff_stream_update_duplex(ff);
  105. }
  106. static void snd_ff_remove(struct fw_unit *unit)
  107. {
  108. struct snd_ff *ff = dev_get_drvdata(&unit->device);
  109. /*
  110. * Confirm to stop the work for registration before the sound card is
  111. * going to be released. The work is not scheduled again because bus
  112. * reset handler is not called anymore.
  113. */
  114. cancel_work_sync(&ff->dwork.work);
  115. if (ff->registered) {
  116. /* No need to wait for releasing card object in this context. */
  117. snd_card_free_when_closed(ff->card);
  118. } else {
  119. /* Don't forget this case. */
  120. ff_free(ff);
  121. }
  122. }
  123. static const struct snd_ff_spec spec_ff400 = {
  124. .name = "Fireface400",
  125. .pcm_capture_channels = {18, 14, 10},
  126. .pcm_playback_channels = {18, 14, 10},
  127. .midi_in_ports = 2,
  128. .midi_out_ports = 2,
  129. .protocol = &snd_ff_protocol_ff400,
  130. };
  131. static const struct ieee1394_device_id snd_ff_id_table[] = {
  132. /* Fireface 400 */
  133. {
  134. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  135. IEEE1394_MATCH_SPECIFIER_ID |
  136. IEEE1394_MATCH_VERSION |
  137. IEEE1394_MATCH_MODEL_ID,
  138. .vendor_id = OUI_RME,
  139. .specifier_id = 0x000a35,
  140. .version = 0x000002,
  141. .model_id = 0x101800,
  142. .driver_data = (kernel_ulong_t)&spec_ff400,
  143. },
  144. {}
  145. };
  146. MODULE_DEVICE_TABLE(ieee1394, snd_ff_id_table);
  147. static struct fw_driver ff_driver = {
  148. .driver = {
  149. .owner = THIS_MODULE,
  150. .name = "snd-fireface",
  151. .bus = &fw_bus_type,
  152. },
  153. .probe = snd_ff_probe,
  154. .update = snd_ff_update,
  155. .remove = snd_ff_remove,
  156. .id_table = snd_ff_id_table,
  157. };
  158. static int __init snd_ff_init(void)
  159. {
  160. return driver_register(&ff_driver.driver);
  161. }
  162. static void __exit snd_ff_exit(void)
  163. {
  164. driver_unregister(&ff_driver.driver);
  165. }
  166. module_init(snd_ff_init);
  167. module_exit(snd_ff_exit);