motu-proc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * motu-proc.c - a part of driver for MOTU FireWire series
  3. *
  4. * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
  5. *
  6. * Licensed under the terms of the GNU General Public License, version 2.
  7. */
  8. #include "./motu.h"
  9. static const char *const clock_names[] = {
  10. [SND_MOTU_CLOCK_SOURCE_INTERNAL] = "Internal",
  11. [SND_MOTU_CLOCK_SOURCE_ADAT_ON_DSUB] = "ADAT on Dsub-9pin interface",
  12. [SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT] = "ADAT on optical interface",
  13. [SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_A] = "ADAT on optical interface A",
  14. [SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_B] = "ADAT on optical interface B",
  15. [SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT] = "S/PDIF on optical interface",
  16. [SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_A] = "S/PDIF on optical interface A",
  17. [SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_B] = "S/PDIF on optical interface B",
  18. [SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX] = "S/PDIF on coaxial interface",
  19. [SND_MOTU_CLOCK_SOURCE_AESEBU_ON_XLR] = "AESEBU on XLR interface",
  20. [SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC] = "Word clock on BNC interface",
  21. };
  22. static void proc_read_clock(struct snd_info_entry *entry,
  23. struct snd_info_buffer *buffer)
  24. {
  25. struct snd_motu *motu = entry->private_data;
  26. const struct snd_motu_protocol *const protocol = motu->spec->protocol;
  27. unsigned int rate;
  28. enum snd_motu_clock_source source;
  29. if (protocol->get_clock_rate(motu, &rate) < 0)
  30. return;
  31. if (protocol->get_clock_source(motu, &source) < 0)
  32. return;
  33. snd_iprintf(buffer, "Rate:\t%d\n", rate);
  34. snd_iprintf(buffer, "Source:\t%s\n", clock_names[source]);
  35. }
  36. static void proc_read_format(struct snd_info_entry *entry,
  37. struct snd_info_buffer *buffer)
  38. {
  39. struct snd_motu *motu = entry->private_data;
  40. const struct snd_motu_protocol *const protocol = motu->spec->protocol;
  41. unsigned int mode;
  42. struct snd_motu_packet_format *formats;
  43. int i;
  44. if (protocol->cache_packet_formats(motu) < 0)
  45. return;
  46. snd_iprintf(buffer, "tx:\tmsg\tfixed\tdiffered\n");
  47. for (i = 0; i < SND_MOTU_CLOCK_RATE_COUNT; ++i) {
  48. mode = i >> 1;
  49. formats = &motu->tx_packet_formats;
  50. snd_iprintf(buffer,
  51. "%u:\t%u\t%u\t%u\n",
  52. snd_motu_clock_rates[i],
  53. formats->msg_chunks,
  54. formats->fixed_part_pcm_chunks[mode],
  55. formats->differed_part_pcm_chunks[mode]);
  56. }
  57. snd_iprintf(buffer, "rx:\tmsg\tfixed\tdiffered\n");
  58. for (i = 0; i < SND_MOTU_CLOCK_RATE_COUNT; ++i) {
  59. mode = i >> 1;
  60. formats = &motu->rx_packet_formats;
  61. snd_iprintf(buffer,
  62. "%u:\t%u\t%u\t%u\n",
  63. snd_motu_clock_rates[i],
  64. formats->msg_chunks,
  65. formats->fixed_part_pcm_chunks[mode],
  66. formats->differed_part_pcm_chunks[mode]);
  67. }
  68. }
  69. static void add_node(struct snd_motu *motu, struct snd_info_entry *root,
  70. const char *name,
  71. void (*op)(struct snd_info_entry *e,
  72. struct snd_info_buffer *b))
  73. {
  74. struct snd_info_entry *entry;
  75. entry = snd_info_create_card_entry(motu->card, name, root);
  76. if (entry == NULL)
  77. return;
  78. snd_info_set_text_ops(entry, motu, op);
  79. if (snd_info_register(entry) < 0)
  80. snd_info_free_entry(entry);
  81. }
  82. void snd_motu_proc_init(struct snd_motu *motu)
  83. {
  84. struct snd_info_entry *root;
  85. /*
  86. * All nodes are automatically removed at snd_card_disconnect(),
  87. * by following to link list.
  88. */
  89. root = snd_info_create_card_entry(motu->card, "firewire",
  90. motu->card->proc_root);
  91. if (root == NULL)
  92. return;
  93. root->mode = S_IFDIR | S_IRUGO | S_IXUGO;
  94. if (snd_info_register(root) < 0) {
  95. snd_info_free_entry(root);
  96. return;
  97. }
  98. add_node(motu, root, "clock", proc_read_clock);
  99. add_node(motu, root, "format", proc_read_format);
  100. }