proc.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. *
  16. */
  17. #include <linux/init.h>
  18. #include <linux/usb.h>
  19. #include <sound/core.h>
  20. #include <sound/info.h>
  21. #include <sound/pcm.h>
  22. #include "usbaudio.h"
  23. #include "helper.h"
  24. #include "card.h"
  25. #include "endpoint.h"
  26. #include "proc.h"
  27. /* convert our full speed USB rate into sampling rate in Hz */
  28. static inline unsigned get_full_speed_hz(unsigned int usb_rate)
  29. {
  30. return (usb_rate * 125 + (1 << 12)) >> 13;
  31. }
  32. /* convert our high speed USB rate into sampling rate in Hz */
  33. static inline unsigned get_high_speed_hz(unsigned int usb_rate)
  34. {
  35. return (usb_rate * 125 + (1 << 9)) >> 10;
  36. }
  37. /*
  38. * common proc files to show the usb device info
  39. */
  40. static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  41. {
  42. struct snd_usb_audio *chip = entry->private_data;
  43. if (!atomic_read(&chip->shutdown))
  44. snd_iprintf(buffer, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum);
  45. }
  46. static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  47. {
  48. struct snd_usb_audio *chip = entry->private_data;
  49. if (!atomic_read(&chip->shutdown))
  50. snd_iprintf(buffer, "%04x:%04x\n",
  51. USB_ID_VENDOR(chip->usb_id),
  52. USB_ID_PRODUCT(chip->usb_id));
  53. }
  54. void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
  55. {
  56. struct snd_info_entry *entry;
  57. if (!snd_card_proc_new(chip->card, "usbbus", &entry))
  58. snd_info_set_text_ops(entry, chip, proc_audio_usbbus_read);
  59. if (!snd_card_proc_new(chip->card, "usbid", &entry))
  60. snd_info_set_text_ops(entry, chip, proc_audio_usbid_read);
  61. }
  62. /*
  63. * proc interface for list the supported pcm formats
  64. */
  65. static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
  66. {
  67. struct audioformat *fp;
  68. static char *sync_types[4] = {
  69. "NONE", "ASYNC", "ADAPTIVE", "SYNC"
  70. };
  71. list_for_each_entry(fp, &subs->fmt_list, list) {
  72. snd_pcm_format_t fmt;
  73. snd_iprintf(buffer, " Interface %d\n", fp->iface);
  74. snd_iprintf(buffer, " Altset %d\n", fp->altsetting);
  75. snd_iprintf(buffer, " Format:");
  76. for (fmt = 0; fmt <= SNDRV_PCM_FORMAT_LAST; ++fmt)
  77. if (fp->formats & pcm_format_to_bits(fmt))
  78. snd_iprintf(buffer, " %s",
  79. snd_pcm_format_name(fmt));
  80. snd_iprintf(buffer, "\n");
  81. snd_iprintf(buffer, " Channels: %d\n", fp->channels);
  82. snd_iprintf(buffer, " Endpoint: %d %s (%s)\n",
  83. fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
  84. fp->endpoint & USB_DIR_IN ? "IN" : "OUT",
  85. sync_types[(fp->ep_attr & USB_ENDPOINT_SYNCTYPE) >> 2]);
  86. if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) {
  87. snd_iprintf(buffer, " Rates: %d - %d (continuous)\n",
  88. fp->rate_min, fp->rate_max);
  89. } else {
  90. unsigned int i;
  91. snd_iprintf(buffer, " Rates: ");
  92. for (i = 0; i < fp->nr_rates; i++) {
  93. if (i > 0)
  94. snd_iprintf(buffer, ", ");
  95. snd_iprintf(buffer, "%d", fp->rate_table[i]);
  96. }
  97. snd_iprintf(buffer, "\n");
  98. }
  99. if (subs->speed != USB_SPEED_FULL)
  100. snd_iprintf(buffer, " Data packet interval: %d us\n",
  101. 125 * (1 << fp->datainterval));
  102. // snd_iprintf(buffer, " Max Packet Size = %d\n", fp->maxpacksize);
  103. // snd_iprintf(buffer, " EP Attribute = %#x\n", fp->attributes);
  104. }
  105. }
  106. static void proc_dump_ep_status(struct snd_usb_substream *subs,
  107. struct snd_usb_endpoint *data_ep,
  108. struct snd_usb_endpoint *sync_ep,
  109. struct snd_info_buffer *buffer)
  110. {
  111. if (!data_ep)
  112. return;
  113. snd_iprintf(buffer, " Packet Size = %d\n", data_ep->curpacksize);
  114. snd_iprintf(buffer, " Momentary freq = %u Hz (%#x.%04x)\n",
  115. subs->speed == USB_SPEED_FULL
  116. ? get_full_speed_hz(data_ep->freqm)
  117. : get_high_speed_hz(data_ep->freqm),
  118. data_ep->freqm >> 16, data_ep->freqm & 0xffff);
  119. if (sync_ep && data_ep->freqshift != INT_MIN) {
  120. int res = 16 - data_ep->freqshift;
  121. snd_iprintf(buffer, " Feedback Format = %d.%d\n",
  122. (sync_ep->syncmaxsize > 3 ? 32 : 24) - res, res);
  123. }
  124. }
  125. static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
  126. {
  127. if (subs->running) {
  128. snd_iprintf(buffer, " Status: Running\n");
  129. snd_iprintf(buffer, " Interface = %d\n", subs->interface);
  130. snd_iprintf(buffer, " Altset = %d\n", subs->altset_idx);
  131. proc_dump_ep_status(subs, subs->data_endpoint, subs->sync_endpoint, buffer);
  132. } else {
  133. snd_iprintf(buffer, " Status: Stop\n");
  134. }
  135. }
  136. static void proc_pcm_format_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  137. {
  138. struct snd_usb_stream *stream = entry->private_data;
  139. snd_iprintf(buffer, "%s : %s\n", stream->chip->card->longname, stream->pcm->name);
  140. if (stream->substream[SNDRV_PCM_STREAM_PLAYBACK].num_formats) {
  141. snd_iprintf(buffer, "\nPlayback:\n");
  142. proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
  143. proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
  144. }
  145. if (stream->substream[SNDRV_PCM_STREAM_CAPTURE].num_formats) {
  146. snd_iprintf(buffer, "\nCapture:\n");
  147. proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
  148. proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
  149. }
  150. }
  151. void snd_usb_proc_pcm_format_add(struct snd_usb_stream *stream)
  152. {
  153. struct snd_info_entry *entry;
  154. char name[32];
  155. struct snd_card *card = stream->chip->card;
  156. sprintf(name, "stream%d", stream->pcm_index);
  157. if (!snd_card_proc_new(card, name, &entry))
  158. snd_info_set_text_ops(entry, stream, proc_pcm_format_read);
  159. }