fireworks_proc.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * fireworks_proc.c - a part of driver for Fireworks based devices
  3. *
  4. * Copyright (c) 2009-2010 Clemens Ladisch
  5. * Copyright (c) 2013-2014 Takashi Sakamoto
  6. *
  7. * Licensed under the terms of the GNU General Public License, version 2.
  8. */
  9. #include "./fireworks.h"
  10. static inline const char*
  11. get_phys_name(struct snd_efw_phys_grp *grp, bool input)
  12. {
  13. const char *const ch_type[] = {
  14. "Analog", "S/PDIF", "ADAT", "S/PDIF or ADAT", "Mirroring",
  15. "Headphones", "I2S", "Guitar", "Pirzo Guitar", "Guitar String",
  16. };
  17. if (grp->type < ARRAY_SIZE(ch_type))
  18. return ch_type[grp->type];
  19. else if (input)
  20. return "Input";
  21. else
  22. return "Output";
  23. }
  24. static void
  25. proc_read_hwinfo(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  26. {
  27. struct snd_efw *efw = entry->private_data;
  28. unsigned short i;
  29. struct snd_efw_hwinfo *hwinfo;
  30. hwinfo = kmalloc(sizeof(struct snd_efw_hwinfo), GFP_KERNEL);
  31. if (hwinfo == NULL)
  32. return;
  33. if (snd_efw_command_get_hwinfo(efw, hwinfo) < 0)
  34. goto end;
  35. snd_iprintf(buffer, "guid_hi: 0x%X\n", hwinfo->guid_hi);
  36. snd_iprintf(buffer, "guid_lo: 0x%X\n", hwinfo->guid_lo);
  37. snd_iprintf(buffer, "type: 0x%X\n", hwinfo->type);
  38. snd_iprintf(buffer, "version: 0x%X\n", hwinfo->version);
  39. snd_iprintf(buffer, "vendor_name: %s\n", hwinfo->vendor_name);
  40. snd_iprintf(buffer, "model_name: %s\n", hwinfo->model_name);
  41. snd_iprintf(buffer, "dsp_version: 0x%X\n", hwinfo->dsp_version);
  42. snd_iprintf(buffer, "arm_version: 0x%X\n", hwinfo->arm_version);
  43. snd_iprintf(buffer, "fpga_version: 0x%X\n", hwinfo->fpga_version);
  44. snd_iprintf(buffer, "flags: 0x%X\n", hwinfo->flags);
  45. snd_iprintf(buffer, "max_sample_rate: 0x%X\n", hwinfo->max_sample_rate);
  46. snd_iprintf(buffer, "min_sample_rate: 0x%X\n", hwinfo->min_sample_rate);
  47. snd_iprintf(buffer, "supported_clock: 0x%X\n",
  48. hwinfo->supported_clocks);
  49. snd_iprintf(buffer, "phys out: 0x%X\n", hwinfo->phys_out);
  50. snd_iprintf(buffer, "phys in: 0x%X\n", hwinfo->phys_in);
  51. snd_iprintf(buffer, "phys in grps: 0x%X\n",
  52. hwinfo->phys_in_grp_count);
  53. for (i = 0; i < hwinfo->phys_in_grp_count; i++) {
  54. snd_iprintf(buffer,
  55. "phys in grp[%d]: type 0x%X, count 0x%X\n",
  56. i, hwinfo->phys_out_grps[i].type,
  57. hwinfo->phys_out_grps[i].count);
  58. }
  59. snd_iprintf(buffer, "phys out grps: 0x%X\n",
  60. hwinfo->phys_out_grp_count);
  61. for (i = 0; i < hwinfo->phys_out_grp_count; i++) {
  62. snd_iprintf(buffer,
  63. "phys out grps[%d]: type 0x%X, count 0x%X\n",
  64. i, hwinfo->phys_out_grps[i].type,
  65. hwinfo->phys_out_grps[i].count);
  66. }
  67. snd_iprintf(buffer, "amdtp rx pcm channels 1x: 0x%X\n",
  68. hwinfo->amdtp_rx_pcm_channels);
  69. snd_iprintf(buffer, "amdtp tx pcm channels 1x: 0x%X\n",
  70. hwinfo->amdtp_tx_pcm_channels);
  71. snd_iprintf(buffer, "amdtp rx pcm channels 2x: 0x%X\n",
  72. hwinfo->amdtp_rx_pcm_channels_2x);
  73. snd_iprintf(buffer, "amdtp tx pcm channels 2x: 0x%X\n",
  74. hwinfo->amdtp_tx_pcm_channels_2x);
  75. snd_iprintf(buffer, "amdtp rx pcm channels 4x: 0x%X\n",
  76. hwinfo->amdtp_rx_pcm_channels_4x);
  77. snd_iprintf(buffer, "amdtp tx pcm channels 4x: 0x%X\n",
  78. hwinfo->amdtp_tx_pcm_channels_4x);
  79. snd_iprintf(buffer, "midi out ports: 0x%X\n", hwinfo->midi_out_ports);
  80. snd_iprintf(buffer, "midi in ports: 0x%X\n", hwinfo->midi_in_ports);
  81. snd_iprintf(buffer, "mixer playback channels: 0x%X\n",
  82. hwinfo->mixer_playback_channels);
  83. snd_iprintf(buffer, "mixer capture channels: 0x%X\n",
  84. hwinfo->mixer_capture_channels);
  85. end:
  86. kfree(hwinfo);
  87. }
  88. static void
  89. proc_read_clock(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  90. {
  91. struct snd_efw *efw = entry->private_data;
  92. enum snd_efw_clock_source clock_source;
  93. unsigned int sampling_rate;
  94. if (snd_efw_command_get_clock_source(efw, &clock_source) < 0)
  95. return;
  96. if (snd_efw_command_get_sampling_rate(efw, &sampling_rate) < 0)
  97. return;
  98. snd_iprintf(buffer, "Clock Source: %d\n", clock_source);
  99. snd_iprintf(buffer, "Sampling Rate: %d\n", sampling_rate);
  100. }
  101. /*
  102. * NOTE:
  103. * dB = 20 * log10(linear / 0x01000000)
  104. * -144.0 dB when linear is 0
  105. */
  106. static void
  107. proc_read_phys_meters(struct snd_info_entry *entry,
  108. struct snd_info_buffer *buffer)
  109. {
  110. struct snd_efw *efw = entry->private_data;
  111. struct snd_efw_phys_meters *meters;
  112. unsigned int g, c, m, max, size;
  113. const char *name;
  114. u32 *linear;
  115. int err;
  116. size = sizeof(struct snd_efw_phys_meters) +
  117. (efw->phys_in + efw->phys_out) * sizeof(u32);
  118. meters = kzalloc(size, GFP_KERNEL);
  119. if (meters == NULL)
  120. return;
  121. err = snd_efw_command_get_phys_meters(efw, meters, size);
  122. if (err < 0)
  123. goto end;
  124. snd_iprintf(buffer, "Physical Meters:\n");
  125. m = 0;
  126. max = min(efw->phys_out, meters->out_meters);
  127. linear = meters->values;
  128. snd_iprintf(buffer, " %d Outputs:\n", max);
  129. for (g = 0; g < efw->phys_out_grp_count; g++) {
  130. name = get_phys_name(&efw->phys_out_grps[g], false);
  131. for (c = 0; c < efw->phys_out_grps[g].count; c++) {
  132. if (m < max)
  133. snd_iprintf(buffer, "\t%s [%d]: %d\n",
  134. name, c, linear[m++]);
  135. }
  136. }
  137. m = 0;
  138. max = min(efw->phys_in, meters->in_meters);
  139. linear = meters->values + meters->out_meters;
  140. snd_iprintf(buffer, " %d Inputs:\n", max);
  141. for (g = 0; g < efw->phys_in_grp_count; g++) {
  142. name = get_phys_name(&efw->phys_in_grps[g], true);
  143. for (c = 0; c < efw->phys_in_grps[g].count; c++)
  144. if (m < max)
  145. snd_iprintf(buffer, "\t%s [%d]: %d\n",
  146. name, c, linear[m++]);
  147. }
  148. end:
  149. kfree(meters);
  150. }
  151. static void
  152. proc_read_queues_state(struct snd_info_entry *entry,
  153. struct snd_info_buffer *buffer)
  154. {
  155. struct snd_efw *efw = entry->private_data;
  156. unsigned int consumed;
  157. if (efw->pull_ptr > efw->push_ptr)
  158. consumed = snd_efw_resp_buf_size -
  159. (unsigned int)(efw->pull_ptr - efw->push_ptr);
  160. else
  161. consumed = (unsigned int)(efw->push_ptr - efw->pull_ptr);
  162. snd_iprintf(buffer, "%d/%d\n",
  163. consumed, snd_efw_resp_buf_size);
  164. }
  165. static void
  166. add_node(struct snd_efw *efw, struct snd_info_entry *root, const char *name,
  167. void (*op)(struct snd_info_entry *e, struct snd_info_buffer *b))
  168. {
  169. struct snd_info_entry *entry;
  170. entry = snd_info_create_card_entry(efw->card, name, root);
  171. if (entry == NULL)
  172. return;
  173. snd_info_set_text_ops(entry, efw, op);
  174. if (snd_info_register(entry) < 0)
  175. snd_info_free_entry(entry);
  176. }
  177. void snd_efw_proc_init(struct snd_efw *efw)
  178. {
  179. struct snd_info_entry *root;
  180. /*
  181. * All nodes are automatically removed at snd_card_disconnect(),
  182. * by following to link list.
  183. */
  184. root = snd_info_create_card_entry(efw->card, "firewire",
  185. efw->card->proc_root);
  186. if (root == NULL)
  187. return;
  188. root->mode = S_IFDIR | S_IRUGO | S_IXUGO;
  189. if (snd_info_register(root) < 0) {
  190. snd_info_free_entry(root);
  191. return;
  192. }
  193. add_node(efw, root, "clock", proc_read_clock);
  194. add_node(efw, root, "firmware", proc_read_hwinfo);
  195. add_node(efw, root, "meters", proc_read_phys_meters);
  196. add_node(efw, root, "queues", proc_read_queues_state);
  197. }