bebob_proc.c 5.2 KB

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