digi00x.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * digi00x.c - a part of driver for Digidesign Digi 002/003 family
  4. *
  5. * Copyright (c) 2014-2015 Takashi Sakamoto
  6. */
  7. #include "digi00x.h"
  8. MODULE_DESCRIPTION("Digidesign Digi 002/003 family Driver");
  9. MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
  10. MODULE_LICENSE("GPL");
  11. #define VENDOR_DIGIDESIGN 0x00a07e
  12. #define MODEL_CONSOLE 0x000001
  13. #define MODEL_RACK 0x000002
  14. #define SPEC_VERSION 0x000001
  15. static int name_card(struct snd_dg00x *dg00x)
  16. {
  17. struct fw_device *fw_dev = fw_parent_device(dg00x->unit);
  18. char name[32] = {0};
  19. char *model;
  20. int err;
  21. err = fw_csr_string(dg00x->unit->directory, CSR_MODEL, name,
  22. sizeof(name));
  23. if (err < 0)
  24. return err;
  25. model = skip_spaces(name);
  26. strcpy(dg00x->card->driver, "Digi00x");
  27. strcpy(dg00x->card->shortname, model);
  28. strcpy(dg00x->card->mixername, model);
  29. snprintf(dg00x->card->longname, sizeof(dg00x->card->longname),
  30. "Digidesign %s, GUID %08x%08x at %s, S%d", model,
  31. fw_dev->config_rom[3], fw_dev->config_rom[4],
  32. dev_name(&dg00x->unit->device), 100 << fw_dev->max_speed);
  33. return 0;
  34. }
  35. static void dg00x_card_free(struct snd_card *card)
  36. {
  37. struct snd_dg00x *dg00x = card->private_data;
  38. snd_dg00x_stream_destroy_duplex(dg00x);
  39. snd_dg00x_transaction_unregister(dg00x);
  40. mutex_destroy(&dg00x->mutex);
  41. fw_unit_put(dg00x->unit);
  42. }
  43. static int snd_dg00x_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry)
  44. {
  45. struct snd_card *card;
  46. struct snd_dg00x *dg00x;
  47. int err;
  48. err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, sizeof(*dg00x), &card);
  49. if (err < 0)
  50. return err;
  51. card->private_free = dg00x_card_free;
  52. dg00x = card->private_data;
  53. dg00x->unit = fw_unit_get(unit);
  54. dev_set_drvdata(&unit->device, dg00x);
  55. dg00x->card = card;
  56. mutex_init(&dg00x->mutex);
  57. spin_lock_init(&dg00x->lock);
  58. init_waitqueue_head(&dg00x->hwdep_wait);
  59. dg00x->is_console = entry->model_id == MODEL_CONSOLE;
  60. err = name_card(dg00x);
  61. if (err < 0)
  62. goto error;
  63. err = snd_dg00x_stream_init_duplex(dg00x);
  64. if (err < 0)
  65. goto error;
  66. snd_dg00x_proc_init(dg00x);
  67. err = snd_dg00x_create_pcm_devices(dg00x);
  68. if (err < 0)
  69. goto error;
  70. err = snd_dg00x_create_midi_devices(dg00x);
  71. if (err < 0)
  72. goto error;
  73. err = snd_dg00x_create_hwdep_device(dg00x);
  74. if (err < 0)
  75. goto error;
  76. err = snd_dg00x_transaction_register(dg00x);
  77. if (err < 0)
  78. goto error;
  79. err = snd_card_register(card);
  80. if (err < 0)
  81. goto error;
  82. return 0;
  83. error:
  84. snd_card_free(card);
  85. return err;
  86. }
  87. static void snd_dg00x_update(struct fw_unit *unit)
  88. {
  89. struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
  90. snd_dg00x_transaction_reregister(dg00x);
  91. mutex_lock(&dg00x->mutex);
  92. snd_dg00x_stream_update_duplex(dg00x);
  93. mutex_unlock(&dg00x->mutex);
  94. }
  95. static void snd_dg00x_remove(struct fw_unit *unit)
  96. {
  97. struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
  98. // Block till all of ALSA character devices are released.
  99. snd_card_free(dg00x->card);
  100. }
  101. static const struct ieee1394_device_id snd_dg00x_id_table[] = {
  102. /* Both of 002/003 use the same ID. */
  103. {
  104. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  105. IEEE1394_MATCH_VERSION |
  106. IEEE1394_MATCH_MODEL_ID,
  107. .vendor_id = VENDOR_DIGIDESIGN,
  108. .version = SPEC_VERSION,
  109. .model_id = MODEL_CONSOLE,
  110. },
  111. {
  112. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  113. IEEE1394_MATCH_VERSION |
  114. IEEE1394_MATCH_MODEL_ID,
  115. .vendor_id = VENDOR_DIGIDESIGN,
  116. .version = SPEC_VERSION,
  117. .model_id = MODEL_RACK,
  118. },
  119. {}
  120. };
  121. MODULE_DEVICE_TABLE(ieee1394, snd_dg00x_id_table);
  122. static struct fw_driver dg00x_driver = {
  123. .driver = {
  124. .owner = THIS_MODULE,
  125. .name = KBUILD_MODNAME,
  126. .bus = &fw_bus_type,
  127. },
  128. .probe = snd_dg00x_probe,
  129. .update = snd_dg00x_update,
  130. .remove = snd_dg00x_remove,
  131. .id_table = snd_dg00x_id_table,
  132. };
  133. static int __init snd_dg00x_init(void)
  134. {
  135. return driver_register(&dg00x_driver.driver);
  136. }
  137. static void __exit snd_dg00x_exit(void)
  138. {
  139. driver_unregister(&dg00x_driver.driver);
  140. }
  141. module_init(snd_dg00x_init);
  142. module_exit(snd_dg00x_exit);