blob: 889c550c9f297f8043c72964d212ad63c21fcf2d [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
Takashi Iwai093b8492020-04-19 23:21:34 +020057static const char * const channel_labels[] = {
58 [SNDRV_CHMAP_NA] = "N/A",
59 [SNDRV_CHMAP_MONO] = "MONO",
60 [SNDRV_CHMAP_FL] = "FL",
61 [SNDRV_CHMAP_FR] = "FR",
62 [SNDRV_CHMAP_FC] = "FC",
63 [SNDRV_CHMAP_LFE] = "LFE",
64 [SNDRV_CHMAP_RL] = "RL",
65 [SNDRV_CHMAP_RR] = "RR",
66 [SNDRV_CHMAP_FLC] = "FLC",
67 [SNDRV_CHMAP_FRC] = "FRC",
68 [SNDRV_CHMAP_RC] = "RC",
69 [SNDRV_CHMAP_SL] = "SL",
70 [SNDRV_CHMAP_SR] = "SR",
71 [SNDRV_CHMAP_TC] = "TC",
72 [SNDRV_CHMAP_TFL] = "TFL",
73 [SNDRV_CHMAP_TFC] = "TFC",
74 [SNDRV_CHMAP_TFR] = "TFR",
75 [SNDRV_CHMAP_TRL] = "TRL",
76 [SNDRV_CHMAP_TRC] = "TRC",
77 [SNDRV_CHMAP_TRR] = "TRR",
78 [SNDRV_CHMAP_TFLC] = "TFLC",
79 [SNDRV_CHMAP_TFRC] = "TFRC",
80 [SNDRV_CHMAP_LLFE] = "LLFE",
81 [SNDRV_CHMAP_RLFE] = "RLFE",
82 [SNDRV_CHMAP_TSL] = "TSL",
83 [SNDRV_CHMAP_TSR] = "TSR",
84 [SNDRV_CHMAP_BC] = "BC",
85 [SNDRV_CHMAP_RLC] = "RLC",
86 [SNDRV_CHMAP_RRC] = "RRC",
87};
88
Daniel Macke5779992010-03-04 19:46:13 +010089/*
90 * proc interface for list the supported pcm formats
91 */
92static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
93{
Eldad Zack88766f02013-04-03 23:18:49 +020094 struct audioformat *fp;
Takashi Iwaia01df922020-01-05 15:47:26 +010095 static const char * const sync_types[4] = {
Daniel Macke5779992010-03-04 19:46:13 +010096 "NONE", "ASYNC", "ADAPTIVE", "SYNC"
97 };
98
Eldad Zack88766f02013-04-03 23:18:49 +020099 list_for_each_entry(fp, &subs->fmt_list, list) {
Clemens Ladisch015eb0b2010-03-04 19:46:15 +0100100 snd_pcm_format_t fmt;
Eldad Zack88766f02013-04-03 23:18:49 +0200101
Daniel Macke5779992010-03-04 19:46:13 +0100102 snd_iprintf(buffer, " Interface %d\n", fp->iface);
103 snd_iprintf(buffer, " Altset %d\n", fp->altsetting);
Clemens Ladisch015eb0b2010-03-04 19:46:15 +0100104 snd_iprintf(buffer, " Format:");
Takashi Iwai5b29f0532020-02-06 17:39:40 +0100105 pcm_for_each_format(fmt)
Eldad Zack74c34ca2013-04-23 01:00:41 +0200106 if (fp->formats & pcm_format_to_bits(fmt))
Clemens Ladisch015eb0b2010-03-04 19:46:15 +0100107 snd_iprintf(buffer, " %s",
108 snd_pcm_format_name(fmt));
109 snd_iprintf(buffer, "\n");
Daniel Macke5779992010-03-04 19:46:13 +0100110 snd_iprintf(buffer, " Channels: %d\n", fp->channels);
111 snd_iprintf(buffer, " Endpoint: %d %s (%s)\n",
112 fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
113 fp->endpoint & USB_DIR_IN ? "IN" : "OUT",
114 sync_types[(fp->ep_attr & USB_ENDPOINT_SYNCTYPE) >> 2]);
115 if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) {
116 snd_iprintf(buffer, " Rates: %d - %d (continuous)\n",
117 fp->rate_min, fp->rate_max);
118 } else {
119 unsigned int i;
120 snd_iprintf(buffer, " Rates: ");
121 for (i = 0; i < fp->nr_rates; i++) {
122 if (i > 0)
123 snd_iprintf(buffer, ", ");
124 snd_iprintf(buffer, "%d", fp->rate_table[i]);
125 }
126 snd_iprintf(buffer, "\n");
127 }
Takashi Iwai978520b2012-10-12 15:12:55 +0200128 if (subs->speed != USB_SPEED_FULL)
Daniel Macke5779992010-03-04 19:46:13 +0100129 snd_iprintf(buffer, " Data packet interval: %d us\n",
130 125 * (1 << fp->datainterval));
Jussi Laakoc7a13262019-02-18 00:17:21 +0200131 snd_iprintf(buffer, " Bits: %d\n", fp->fmt_bits);
Takashi Iwai093b8492020-04-19 23:21:34 +0200132
133 if (fp->dsd_raw)
134 snd_iprintf(buffer, " DSD raw: DOP=%d, bitrev=%d\n",
135 fp->dsd_dop, fp->dsd_bitrev);
136
137 if (fp->chmap) {
138 const struct snd_pcm_chmap_elem *map = fp->chmap;
139 int c;
140
141 snd_iprintf(buffer, " Channel map:");
142 for (c = 0; c < map->channels; c++) {
Dan Carpenter8137d272020-04-22 12:22:55 +0300143 if (map->map[c] >= ARRAY_SIZE(channel_labels) ||
Takashi Iwai093b8492020-04-19 23:21:34 +0200144 !channel_labels[map->map[c]])
145 snd_iprintf(buffer, " --");
146 else
147 snd_iprintf(buffer, " %s",
148 channel_labels[map->map[c]]);
149 }
150 snd_iprintf(buffer, "\n");
151 }
152
Daniel Macke5779992010-03-04 19:46:13 +0100153 // snd_iprintf(buffer, " Max Packet Size = %d\n", fp->maxpacksize);
154 // snd_iprintf(buffer, " EP Attribute = %#x\n", fp->attributes);
155 }
156}
157
Takashi Iwai22026c12012-04-13 12:57:39 +0200158static void proc_dump_ep_status(struct snd_usb_substream *subs,
Torstein Heggee6135fe2013-05-16 20:26:17 +0200159 struct snd_usb_endpoint *data_ep,
160 struct snd_usb_endpoint *sync_ep,
Takashi Iwai22026c12012-04-13 12:57:39 +0200161 struct snd_info_buffer *buffer)
162{
Torstein Heggee6135fe2013-05-16 20:26:17 +0200163 if (!data_ep)
Takashi Iwai22026c12012-04-13 12:57:39 +0200164 return;
Torstein Heggee6135fe2013-05-16 20:26:17 +0200165 snd_iprintf(buffer, " Packet Size = %d\n", data_ep->curpacksize);
Takashi Iwai22026c12012-04-13 12:57:39 +0200166 snd_iprintf(buffer, " Momentary freq = %u Hz (%#x.%04x)\n",
Takashi Iwai978520b2012-10-12 15:12:55 +0200167 subs->speed == USB_SPEED_FULL
Torstein Heggee6135fe2013-05-16 20:26:17 +0200168 ? get_full_speed_hz(data_ep->freqm)
169 : get_high_speed_hz(data_ep->freqm),
170 data_ep->freqm >> 16, data_ep->freqm & 0xffff);
171 if (sync_ep && data_ep->freqshift != INT_MIN) {
172 int res = 16 - data_ep->freqshift;
Takashi Iwai22026c12012-04-13 12:57:39 +0200173 snd_iprintf(buffer, " Feedback Format = %d.%d\n",
Torstein Heggee6135fe2013-05-16 20:26:17 +0200174 (sync_ep->syncmaxsize > 3 ? 32 : 24) - res, res);
Takashi Iwai22026c12012-04-13 12:57:39 +0200175 }
176}
177
Daniel Macke5779992010-03-04 19:46:13 +0100178static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
179{
180 if (subs->running) {
Daniel Macke5779992010-03-04 19:46:13 +0100181 snd_iprintf(buffer, " Status: Running\n");
182 snd_iprintf(buffer, " Interface = %d\n", subs->interface);
Clemens Ladische11b4e02010-03-04 19:46:14 +0100183 snd_iprintf(buffer, " Altset = %d\n", subs->altset_idx);
Torstein Heggee6135fe2013-05-16 20:26:17 +0200184 proc_dump_ep_status(subs, subs->data_endpoint, subs->sync_endpoint, buffer);
Daniel Macke5779992010-03-04 19:46:13 +0100185 } else {
186 snd_iprintf(buffer, " Status: Stop\n");
187 }
188}
189
190static void proc_pcm_format_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
191{
192 struct snd_usb_stream *stream = entry->private_data;
193
194 snd_iprintf(buffer, "%s : %s\n", stream->chip->card->longname, stream->pcm->name);
195
196 if (stream->substream[SNDRV_PCM_STREAM_PLAYBACK].num_formats) {
197 snd_iprintf(buffer, "\nPlayback:\n");
198 proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
199 proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
200 }
201 if (stream->substream[SNDRV_PCM_STREAM_CAPTURE].num_formats) {
202 snd_iprintf(buffer, "\nCapture:\n");
203 proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
204 proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
205 }
206}
207
208void snd_usb_proc_pcm_format_add(struct snd_usb_stream *stream)
209{
Daniel Macke5779992010-03-04 19:46:13 +0100210 char name[32];
211 struct snd_card *card = stream->chip->card;
212
213 sprintf(name, "stream%d", stream->pcm_index);
Takashi Iwai74490542019-02-04 16:07:35 +0100214 snd_card_ro_proc_new(card, name, stream, proc_pcm_format_read);
Daniel Macke5779992010-03-04 19:46:13 +0100215}
216