bebob_proc.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * bebob_proc.c - a part of driver for BeBoB based devices
  4. *
  5. * Copyright (c) 2013-2014 Takashi Sakamoto
  6. */
  7. #include "./bebob.h"
  8. /* contents of information register */
  9. struct hw_info {
  10. u64 manufacturer;
  11. u32 protocol_ver;
  12. u32 bld_ver;
  13. u32 guid[2];
  14. u32 model_id;
  15. u32 model_rev;
  16. u64 fw_date;
  17. u64 fw_time;
  18. u32 fw_id;
  19. u32 fw_ver;
  20. u32 base_addr;
  21. u32 max_size;
  22. u64 bld_date;
  23. u64 bld_time;
  24. /* may not used in product
  25. u64 dbg_date;
  26. u64 dbg_time;
  27. u32 dbg_id;
  28. u32 dbg_version;
  29. */
  30. } __packed;
  31. static void
  32. proc_read_hw_info(struct snd_info_entry *entry,
  33. struct snd_info_buffer *buffer)
  34. {
  35. struct snd_bebob *bebob = entry->private_data;
  36. struct hw_info *info;
  37. info = kzalloc(sizeof(struct hw_info), GFP_KERNEL);
  38. if (info == NULL)
  39. return;
  40. if (snd_bebob_read_block(bebob->unit, 0,
  41. info, sizeof(struct hw_info)) < 0)
  42. goto end;
  43. snd_iprintf(buffer, "Manufacturer:\t%.8s\n",
  44. (char *)&info->manufacturer);
  45. snd_iprintf(buffer, "Protocol Ver:\t%d\n", info->protocol_ver);
  46. snd_iprintf(buffer, "Build Ver:\t%d\n", info->bld_ver);
  47. snd_iprintf(buffer, "GUID:\t\t0x%.8X%.8X\n",
  48. info->guid[0], info->guid[1]);
  49. snd_iprintf(buffer, "Model ID:\t0x%02X\n", info->model_id);
  50. snd_iprintf(buffer, "Model Rev:\t%d\n", info->model_rev);
  51. snd_iprintf(buffer, "Firmware Date:\t%.8s\n", (char *)&info->fw_date);
  52. snd_iprintf(buffer, "Firmware Time:\t%.8s\n", (char *)&info->fw_time);
  53. snd_iprintf(buffer, "Firmware ID:\t0x%X\n", info->fw_id);
  54. snd_iprintf(buffer, "Firmware Ver:\t%d\n", info->fw_ver);
  55. snd_iprintf(buffer, "Base Addr:\t0x%X\n", info->base_addr);
  56. snd_iprintf(buffer, "Max Size:\t%d\n", info->max_size);
  57. snd_iprintf(buffer, "Loader Date:\t%.8s\n", (char *)&info->bld_date);
  58. snd_iprintf(buffer, "Loader Time:\t%.8s\n", (char *)&info->bld_time);
  59. end:
  60. kfree(info);
  61. }
  62. static void
  63. proc_read_meters(struct snd_info_entry *entry,
  64. struct snd_info_buffer *buffer)
  65. {
  66. struct snd_bebob *bebob = entry->private_data;
  67. const struct snd_bebob_meter_spec *spec = bebob->spec->meter;
  68. u32 *buf;
  69. unsigned int i, c, channels, size;
  70. if (spec == NULL)
  71. return;
  72. channels = spec->num * 2;
  73. size = channels * sizeof(u32);
  74. buf = kmalloc(size, GFP_KERNEL);
  75. if (buf == NULL)
  76. return;
  77. if (spec->get(bebob, buf, size) < 0)
  78. goto end;
  79. for (i = 0, c = 1; i < channels; i++) {
  80. snd_iprintf(buffer, "%s %d:\t%d\n",
  81. spec->labels[i / 2], c++, buf[i]);
  82. if ((i + 1 < channels - 1) &&
  83. (strcmp(spec->labels[i / 2],
  84. spec->labels[(i + 1) / 2]) != 0))
  85. c = 1;
  86. }
  87. end:
  88. kfree(buf);
  89. }
  90. static void
  91. proc_read_formation(struct snd_info_entry *entry,
  92. struct snd_info_buffer *buffer)
  93. {
  94. struct snd_bebob *bebob = entry->private_data;
  95. struct snd_bebob_stream_formation *formation;
  96. unsigned int i;
  97. snd_iprintf(buffer, "Output Stream from device:\n");
  98. snd_iprintf(buffer, "\tRate\tPCM\tMIDI\n");
  99. formation = bebob->tx_stream_formations;
  100. for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {
  101. snd_iprintf(buffer,
  102. "\t%d\t%d\t%d\n", snd_bebob_rate_table[i],
  103. formation[i].pcm, formation[i].midi);
  104. }
  105. snd_iprintf(buffer, "Input Stream to device:\n");
  106. snd_iprintf(buffer, "\tRate\tPCM\tMIDI\n");
  107. formation = bebob->rx_stream_formations;
  108. for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {
  109. snd_iprintf(buffer,
  110. "\t%d\t%d\t%d\n", snd_bebob_rate_table[i],
  111. formation[i].pcm, formation[i].midi);
  112. }
  113. }
  114. static void
  115. proc_read_clock(struct snd_info_entry *entry,
  116. struct snd_info_buffer *buffer)
  117. {
  118. static const char *const clk_labels[] = {
  119. "Internal",
  120. "External",
  121. "SYT-Match",
  122. };
  123. struct snd_bebob *bebob = entry->private_data;
  124. const struct snd_bebob_rate_spec *rate_spec = bebob->spec->rate;
  125. const struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;
  126. enum snd_bebob_clock_type src;
  127. unsigned int rate;
  128. if (rate_spec->get(bebob, &rate) >= 0)
  129. snd_iprintf(buffer, "Sampling rate: %d\n", rate);
  130. if (snd_bebob_stream_get_clock_src(bebob, &src) >= 0) {
  131. if (clk_spec)
  132. snd_iprintf(buffer, "Clock Source: %s\n",
  133. clk_labels[src]);
  134. else
  135. snd_iprintf(buffer, "Clock Source: %s (MSU-dest: %d)\n",
  136. clk_labels[src], bebob->sync_input_plug);
  137. }
  138. }
  139. static void
  140. add_node(struct snd_bebob *bebob, struct snd_info_entry *root, const char *name,
  141. void (*op)(struct snd_info_entry *e, struct snd_info_buffer *b))
  142. {
  143. struct snd_info_entry *entry;
  144. entry = snd_info_create_card_entry(bebob->card, name, root);
  145. if (entry)
  146. snd_info_set_text_ops(entry, bebob, op);
  147. }
  148. void snd_bebob_proc_init(struct snd_bebob *bebob)
  149. {
  150. struct snd_info_entry *root;
  151. /*
  152. * All nodes are automatically removed at snd_card_disconnect(),
  153. * by following to link list.
  154. */
  155. root = snd_info_create_card_entry(bebob->card, "firewire",
  156. bebob->card->proc_root);
  157. if (root == NULL)
  158. return;
  159. root->mode = S_IFDIR | 0555;
  160. add_node(bebob, root, "clock", proc_read_clock);
  161. add_node(bebob, root, "firmware", proc_read_hw_info);
  162. add_node(bebob, root, "formation", proc_read_formation);
  163. if (bebob->spec->meter != NULL)
  164. add_node(bebob, root, "meter", proc_read_meters);
  165. }