fireworks_proc.c 6.5 KB

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