proc.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. fp = list_entry(p, struct audioformat, list);
  73. snd_iprintf(buffer, " Interface %d\n", fp->iface);
  74. snd_iprintf(buffer, " Altset %d\n", fp->altsetting);
  75. snd_iprintf(buffer, " Format: %s\n",
  76. snd_pcm_format_name(fp->format));
  77. snd_iprintf(buffer, " Channels: %d\n", fp->channels);
  78. snd_iprintf(buffer, " Endpoint: %d %s (%s)\n",
  79. fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
  80. fp->endpoint & USB_DIR_IN ? "IN" : "OUT",
  81. sync_types[(fp->ep_attr & USB_ENDPOINT_SYNCTYPE) >> 2]);
  82. if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) {
  83. snd_iprintf(buffer, " Rates: %d - %d (continuous)\n",
  84. fp->rate_min, fp->rate_max);
  85. } else {
  86. unsigned int i;
  87. snd_iprintf(buffer, " Rates: ");
  88. for (i = 0; i < fp->nr_rates; i++) {
  89. if (i > 0)
  90. snd_iprintf(buffer, ", ");
  91. snd_iprintf(buffer, "%d", fp->rate_table[i]);
  92. }
  93. snd_iprintf(buffer, "\n");
  94. }
  95. if (snd_usb_get_speed(subs->dev) == USB_SPEED_HIGH)
  96. snd_iprintf(buffer, " Data packet interval: %d us\n",
  97. 125 * (1 << fp->datainterval));
  98. // snd_iprintf(buffer, " Max Packet Size = %d\n", fp->maxpacksize);
  99. // snd_iprintf(buffer, " EP Attribute = %#x\n", fp->attributes);
  100. }
  101. }
  102. static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
  103. {
  104. if (subs->running) {
  105. unsigned int i;
  106. snd_iprintf(buffer, " Status: Running\n");
  107. snd_iprintf(buffer, " Interface = %d\n", subs->interface);
  108. snd_iprintf(buffer, " Altset = %d\n", subs->format);
  109. snd_iprintf(buffer, " URBs = %d [ ", subs->nurbs);
  110. for (i = 0; i < subs->nurbs; i++)
  111. snd_iprintf(buffer, "%d ", subs->dataurb[i].packets);
  112. snd_iprintf(buffer, "]\n");
  113. snd_iprintf(buffer, " Packet Size = %d\n", subs->curpacksize);
  114. snd_iprintf(buffer, " Momentary freq = %u Hz (%#x.%04x)\n",
  115. snd_usb_get_speed(subs->dev) == USB_SPEED_FULL
  116. ? get_full_speed_hz(subs->freqm)
  117. : get_high_speed_hz(subs->freqm),
  118. subs->freqm >> 16, subs->freqm & 0xffff);
  119. } else {
  120. snd_iprintf(buffer, " Status: Stop\n");
  121. }
  122. }
  123. static void proc_pcm_format_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  124. {
  125. struct snd_usb_stream *stream = entry->private_data;
  126. snd_iprintf(buffer, "%s : %s\n", stream->chip->card->longname, stream->pcm->name);
  127. if (stream->substream[SNDRV_PCM_STREAM_PLAYBACK].num_formats) {
  128. snd_iprintf(buffer, "\nPlayback:\n");
  129. proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
  130. proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
  131. }
  132. if (stream->substream[SNDRV_PCM_STREAM_CAPTURE].num_formats) {
  133. snd_iprintf(buffer, "\nCapture:\n");
  134. proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
  135. proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
  136. }
  137. }
  138. void snd_usb_proc_pcm_format_add(struct snd_usb_stream *stream)
  139. {
  140. struct snd_info_entry *entry;
  141. char name[32];
  142. struct snd_card *card = stream->chip->card;
  143. sprintf(name, "stream%d", stream->pcm_index);
  144. if (!snd_card_proc_new(card, name, &entry))
  145. snd_info_set_text_ops(entry, stream, proc_pcm_format_read);
  146. }