blob: 49e3f176aaf5ae2143dd8f84f27b1f0c1954c9a3 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Daniel Macke5779992010-03-04 19:46:13 +01002/*
Daniel Macke5779992010-03-04 19:46:13 +01003 */
4
5#include <linux/init.h>
6#include <linux/usb.h>
7
8#include <sound/core.h>
9#include <sound/info.h>
10#include <sound/pcm.h>
11
12#include "usbaudio.h"
13#include "helper.h"
14#include "card.h"
Daniel Mackc89a5d92012-04-21 13:52:12 +020015#include "endpoint.h"
Daniel Macke5779992010-03-04 19:46:13 +010016#include "proc.h"
17
18/* convert our full speed USB rate into sampling rate in Hz */
19static inline unsigned get_full_speed_hz(unsigned int usb_rate)
20{
21 return (usb_rate * 125 + (1 << 12)) >> 13;
22}
23
24/* convert our high speed USB rate into sampling rate in Hz */
25static inline unsigned get_high_speed_hz(unsigned int usb_rate)
26{
27 return (usb_rate * 125 + (1 << 9)) >> 10;
28}
29
30/*
31 * common proc files to show the usb device info
32 */
33static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
34{
35 struct snd_usb_audio *chip = entry->private_data;
Takashi Iwai47ab1542015-08-25 16:09:00 +020036 if (!atomic_read(&chip->shutdown))
Daniel Macke5779992010-03-04 19:46:13 +010037 snd_iprintf(buffer, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum);
38}
39
40static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
41{
42 struct snd_usb_audio *chip = entry->private_data;
Takashi Iwai47ab1542015-08-25 16:09:00 +020043 if (!atomic_read(&chip->shutdown))
Daniel Macke5779992010-03-04 19:46:13 +010044 snd_iprintf(buffer, "%04x:%04x\n",
45 USB_ID_VENDOR(chip->usb_id),
46 USB_ID_PRODUCT(chip->usb_id));
47}
48
49void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
50{
Takashi Iwai74490542019-02-04 16:07:35 +010051 snd_card_ro_proc_new(chip->card, "usbbus", chip,
52 proc_audio_usbbus_read);
53 snd_card_ro_proc_new(chip->card, "usbid", chip,
54 proc_audio_usbid_read);
Daniel Macke5779992010-03-04 19:46:13 +010055}
56
57/*
58 * proc interface for list the supported pcm formats
59 */
60static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
61{
Eldad Zack88766f02013-04-03 23:18:49 +020062 struct audioformat *fp;
Daniel Macke5779992010-03-04 19:46:13 +010063 static char *sync_types[4] = {
64 "NONE", "ASYNC", "ADAPTIVE", "SYNC"
65 };
66
Eldad Zack88766f02013-04-03 23:18:49 +020067 list_for_each_entry(fp, &subs->fmt_list, list) {
Clemens Ladisch015eb0b2010-03-04 19:46:15 +010068 snd_pcm_format_t fmt;
Eldad Zack88766f02013-04-03 23:18:49 +020069
Daniel Macke5779992010-03-04 19:46:13 +010070 snd_iprintf(buffer, " Interface %d\n", fp->iface);
71 snd_iprintf(buffer, " Altset %d\n", fp->altsetting);
Clemens Ladisch015eb0b2010-03-04 19:46:15 +010072 snd_iprintf(buffer, " Format:");
73 for (fmt = 0; fmt <= SNDRV_PCM_FORMAT_LAST; ++fmt)
Eldad Zack74c34ca2013-04-23 01:00:41 +020074 if (fp->formats & pcm_format_to_bits(fmt))
Clemens Ladisch015eb0b2010-03-04 19:46:15 +010075 snd_iprintf(buffer, " %s",
76 snd_pcm_format_name(fmt));
77 snd_iprintf(buffer, "\n");
Daniel Macke5779992010-03-04 19:46:13 +010078 snd_iprintf(buffer, " Channels: %d\n", fp->channels);
79 snd_iprintf(buffer, " Endpoint: %d %s (%s)\n",
80 fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
81 fp->endpoint & USB_DIR_IN ? "IN" : "OUT",
82 sync_types[(fp->ep_attr & USB_ENDPOINT_SYNCTYPE) >> 2]);
83 if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) {
84 snd_iprintf(buffer, " Rates: %d - %d (continuous)\n",
85 fp->rate_min, fp->rate_max);
86 } else {
87 unsigned int i;
88 snd_iprintf(buffer, " Rates: ");
89 for (i = 0; i < fp->nr_rates; i++) {
90 if (i > 0)
91 snd_iprintf(buffer, ", ");
92 snd_iprintf(buffer, "%d", fp->rate_table[i]);
93 }
94 snd_iprintf(buffer, "\n");
95 }
Takashi Iwai978520b2012-10-12 15:12:55 +020096 if (subs->speed != USB_SPEED_FULL)
Daniel Macke5779992010-03-04 19:46:13 +010097 snd_iprintf(buffer, " Data packet interval: %d us\n",
98 125 * (1 << fp->datainterval));
Jussi Laakoc7a13262019-02-18 00:17:21 +020099 snd_iprintf(buffer, " Bits: %d\n", fp->fmt_bits);
Daniel Macke5779992010-03-04 19:46:13 +0100100 // snd_iprintf(buffer, " Max Packet Size = %d\n", fp->maxpacksize);
101 // snd_iprintf(buffer, " EP Attribute = %#x\n", fp->attributes);
102 }
103}
104
Takashi Iwai22026c12012-04-13 12:57:39 +0200105static void proc_dump_ep_status(struct snd_usb_substream *subs,
Torstein Heggee6135fe2013-05-16 20:26:17 +0200106 struct snd_usb_endpoint *data_ep,
107 struct snd_usb_endpoint *sync_ep,
Takashi Iwai22026c12012-04-13 12:57:39 +0200108 struct snd_info_buffer *buffer)
109{
Torstein Heggee6135fe2013-05-16 20:26:17 +0200110 if (!data_ep)
Takashi Iwai22026c12012-04-13 12:57:39 +0200111 return;
Torstein Heggee6135fe2013-05-16 20:26:17 +0200112 snd_iprintf(buffer, " Packet Size = %d\n", data_ep->curpacksize);
Takashi Iwai22026c12012-04-13 12:57:39 +0200113 snd_iprintf(buffer, " Momentary freq = %u Hz (%#x.%04x)\n",
Takashi Iwai978520b2012-10-12 15:12:55 +0200114 subs->speed == USB_SPEED_FULL
Torstein Heggee6135fe2013-05-16 20:26:17 +0200115 ? get_full_speed_hz(data_ep->freqm)
116 : get_high_speed_hz(data_ep->freqm),
117 data_ep->freqm >> 16, data_ep->freqm & 0xffff);
118 if (sync_ep && data_ep->freqshift != INT_MIN) {
119 int res = 16 - data_ep->freqshift;
Takashi Iwai22026c12012-04-13 12:57:39 +0200120 snd_iprintf(buffer, " Feedback Format = %d.%d\n",
Torstein Heggee6135fe2013-05-16 20:26:17 +0200121 (sync_ep->syncmaxsize > 3 ? 32 : 24) - res, res);
Takashi Iwai22026c12012-04-13 12:57:39 +0200122 }
123}
124
Daniel Macke5779992010-03-04 19:46:13 +0100125static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
126{
127 if (subs->running) {
Daniel Macke5779992010-03-04 19:46:13 +0100128 snd_iprintf(buffer, " Status: Running\n");
129 snd_iprintf(buffer, " Interface = %d\n", subs->interface);
Clemens Ladische11b4e02010-03-04 19:46:14 +0100130 snd_iprintf(buffer, " Altset = %d\n", subs->altset_idx);
Torstein Heggee6135fe2013-05-16 20:26:17 +0200131 proc_dump_ep_status(subs, subs->data_endpoint, subs->sync_endpoint, buffer);
Daniel Macke5779992010-03-04 19:46:13 +0100132 } else {
133 snd_iprintf(buffer, " Status: Stop\n");
134 }
135}
136
137static void proc_pcm_format_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
138{
139 struct snd_usb_stream *stream = entry->private_data;
140
141 snd_iprintf(buffer, "%s : %s\n", stream->chip->card->longname, stream->pcm->name);
142
143 if (stream->substream[SNDRV_PCM_STREAM_PLAYBACK].num_formats) {
144 snd_iprintf(buffer, "\nPlayback:\n");
145 proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
146 proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
147 }
148 if (stream->substream[SNDRV_PCM_STREAM_CAPTURE].num_formats) {
149 snd_iprintf(buffer, "\nCapture:\n");
150 proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
151 proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
152 }
153}
154
155void snd_usb_proc_pcm_format_add(struct snd_usb_stream *stream)
156{
Daniel Macke5779992010-03-04 19:46:13 +0100157 char name[32];
158 struct snd_card *card = stream->chip->card;
159
160 sprintf(name, "stream%d", stream->pcm_index);
Takashi Iwai74490542019-02-04 16:07:35 +0100161 snd_card_ro_proc_new(card, name, stream, proc_pcm_format_read);
Daniel Macke5779992010-03-04 19:46:13 +0100162}
163