proc.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 "proc.h"
  26. /* convert our full speed USB rate into sampling rate in Hz */
  27. static inline unsigned get_full_speed_hz(unsigned int usb_rate)
  28. {
  29. return (usb_rate * 125 + (1 << 12)) >> 13;
  30. }
  31. /* convert our high speed USB rate into sampling rate in Hz */
  32. static inline unsigned get_high_speed_hz(unsigned int usb_rate)
  33. {
  34. return (usb_rate * 125 + (1 << 9)) >> 10;
  35. }
  36. /*
  37. * common proc files to show the usb device info
  38. */
  39. static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  40. {
  41. struct snd_usb_audio *chip = entry->private_data;
  42. if (!chip->shutdown)
  43. snd_iprintf(buffer, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum);
  44. }
  45. static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  46. {
  47. struct snd_usb_audio *chip = entry->private_data;
  48. if (!chip->shutdown)
  49. snd_iprintf(buffer, "%04x:%04x\n",
  50. USB_ID_VENDOR(chip->usb_id),
  51. USB_ID_PRODUCT(chip->usb_id));
  52. }
  53. void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
  54. {
  55. struct snd_info_entry *entry;
  56. if (!snd_card_proc_new(chip->card, "usbbus", &entry))
  57. snd_info_set_text_ops(entry, chip, proc_audio_usbbus_read);
  58. if (!snd_card_proc_new(chip->card, "usbid", &entry))
  59. snd_info_set_text_ops(entry, chip, proc_audio_usbid_read);
  60. }
  61. /*
  62. * proc interface for list the supported pcm formats
  63. */
  64. static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
  65. {
  66. struct list_head *p;
  67. static char *sync_types[4] = {
  68. "NONE", "ASYNC", "ADAPTIVE", "SYNC"
  69. };
  70. list_for_each(p, &subs->fmt_list) {
  71. struct audioformat *fp;
  72. snd_pcm_format_t fmt;
  73. fp = list_entry(p, struct audioformat, list);
  74. snd_iprintf(buffer, " Interface %d\n", fp->iface);
  75. snd_iprintf(buffer, " Altset %d\n", fp->altsetting);
  76. snd_iprintf(buffer, " Format:");
  77. for (fmt = 0; fmt <= SNDRV_PCM_FORMAT_LAST; ++fmt)
  78. if (fp->formats & (1uLL << fmt))
  79. snd_iprintf(buffer, " %s",
  80. snd_pcm_format_name(fmt));
  81. snd_iprintf(buffer, "\n");
  82. snd_iprintf(buffer, " Channels: %d\n", fp->channels);
  83. snd_iprintf(buffer, " Endpoint: %d %s (%s)\n",
  84. fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
  85. fp->endpoint & USB_DIR_IN ? "IN" : "OUT",
  86. sync_types[(fp->ep_attr & USB_ENDPOINT_SYNCTYPE) >> 2]);
  87. if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) {
  88. snd_iprintf(buffer, " Rates: %d - %d (continuous)\n",
  89. fp->rate_min, fp->rate_max);
  90. } else {
  91. unsigned int i;
  92. snd_iprintf(buffer, " Rates: ");
  93. for (i = 0; i < fp->nr_rates; i++) {
  94. if (i > 0)
  95. snd_iprintf(buffer, ", ");
  96. snd_iprintf(buffer, "%d", fp->rate_table[i]);
  97. }
  98. snd_iprintf(buffer, "\n");
  99. }
  100. if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL)
  101. snd_iprintf(buffer, " Data packet interval: %d us\n",
  102. 125 * (1 << fp->datainterval));
  103. // snd_iprintf(buffer, " Max Packet Size = %d\n", fp->maxpacksize);
  104. // snd_iprintf(buffer, " EP Attribute = %#x\n", fp->attributes);
  105. }
  106. }
  107. static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
  108. {
  109. if (subs->running) {
  110. unsigned int i;
  111. snd_iprintf(buffer, " Status: Running\n");
  112. snd_iprintf(buffer, " Interface = %d\n", subs->interface);
  113. snd_iprintf(buffer, " Altset = %d\n", subs->altset_idx);
  114. snd_iprintf(buffer, " URBs = %d [ ", subs->nurbs);
  115. for (i = 0; i < subs->nurbs; i++)
  116. snd_iprintf(buffer, "%d ", subs->dataurb[i].packets);
  117. snd_iprintf(buffer, "]\n");
  118. snd_iprintf(buffer, " Packet Size = %d\n", subs->curpacksize);
  119. snd_iprintf(buffer, " Momentary freq = %u Hz (%#x.%04x)\n",
  120. snd_usb_get_speed(subs->dev) == USB_SPEED_FULL
  121. ? get_full_speed_hz(subs->freqm)
  122. : get_high_speed_hz(subs->freqm),
  123. subs->freqm >> 16, subs->freqm & 0xffff);
  124. if (subs->freqshift != INT_MIN)
  125. snd_iprintf(buffer, " Feedback Format = %d.%d\n",
  126. (subs->syncmaxsize > 3 ? 32 : 24)
  127. - (16 - subs->freqshift),
  128. 16 - subs->freqshift);
  129. } else {
  130. snd_iprintf(buffer, " Status: Stop\n");
  131. }
  132. }
  133. static void proc_pcm_format_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  134. {
  135. struct snd_usb_stream *stream = entry->private_data;
  136. snd_iprintf(buffer, "%s : %s\n", stream->chip->card->longname, stream->pcm->name);
  137. if (stream->substream[SNDRV_PCM_STREAM_PLAYBACK].num_formats) {
  138. snd_iprintf(buffer, "\nPlayback:\n");
  139. proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
  140. proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
  141. }
  142. if (stream->substream[SNDRV_PCM_STREAM_CAPTURE].num_formats) {
  143. snd_iprintf(buffer, "\nCapture:\n");
  144. proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
  145. proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
  146. }
  147. }
  148. void snd_usb_proc_pcm_format_add(struct snd_usb_stream *stream)
  149. {
  150. struct snd_info_entry *entry;
  151. char name[32];
  152. struct snd_card *card = stream->chip->card;
  153. sprintf(name, "stream%d", stream->pcm_index);
  154. if (!snd_card_proc_new(card, name, &entry))
  155. snd_info_set_text_ops(entry, stream, proc_pcm_format_read);
  156. }