1 // SPDX-License-Identifier: GPL-2.0-or-later
5 #include <linux/init.h>
8 #include <sound/core.h>
9 #include <sound/info.h>
10 #include <sound/pcm.h>
18 /* convert our full speed USB rate into sampling rate in Hz */
19 static inline unsigned get_full_speed_hz(unsigned int usb_rate
)
21 return (usb_rate
* 125 + (1 << 12)) >> 13;
24 /* convert our high speed USB rate into sampling rate in Hz */
25 static inline unsigned get_high_speed_hz(unsigned int usb_rate
)
27 return (usb_rate
* 125 + (1 << 9)) >> 10;
31 * common proc files to show the usb device info
33 static void proc_audio_usbbus_read(struct snd_info_entry
*entry
, struct snd_info_buffer
*buffer
)
35 struct snd_usb_audio
*chip
= entry
->private_data
;
36 if (!atomic_read(&chip
->shutdown
))
37 snd_iprintf(buffer
, "%03d/%03d\n", chip
->dev
->bus
->busnum
, chip
->dev
->devnum
);
40 static void proc_audio_usbid_read(struct snd_info_entry
*entry
, struct snd_info_buffer
*buffer
)
42 struct snd_usb_audio
*chip
= entry
->private_data
;
43 if (!atomic_read(&chip
->shutdown
))
44 snd_iprintf(buffer
, "%04x:%04x\n",
45 USB_ID_VENDOR(chip
->usb_id
),
46 USB_ID_PRODUCT(chip
->usb_id
));
49 void snd_usb_audio_create_proc(struct snd_usb_audio
*chip
)
51 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
);
58 * proc interface for list the supported pcm formats
60 static void proc_dump_substream_formats(struct snd_usb_substream
*subs
, struct snd_info_buffer
*buffer
)
62 struct audioformat
*fp
;
63 static const char * const sync_types
[4] = {
64 "NONE", "ASYNC", "ADAPTIVE", "SYNC"
67 list_for_each_entry(fp
, &subs
->fmt_list
, list
) {
70 snd_iprintf(buffer
, " Interface %d\n", fp
->iface
);
71 snd_iprintf(buffer
, " Altset %d\n", fp
->altsetting
);
72 snd_iprintf(buffer
, " Format:");
73 pcm_for_each_format(fmt
)
74 if (fp
->formats
& pcm_format_to_bits(fmt
))
75 snd_iprintf(buffer
, " %s",
76 snd_pcm_format_name(fmt
));
77 snd_iprintf(buffer
, "\n");
78 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
);
88 snd_iprintf(buffer
, " Rates: ");
89 for (i
= 0; i
< fp
->nr_rates
; i
++) {
91 snd_iprintf(buffer
, ", ");
92 snd_iprintf(buffer
, "%d", fp
->rate_table
[i
]);
94 snd_iprintf(buffer
, "\n");
96 if (subs
->speed
!= USB_SPEED_FULL
)
97 snd_iprintf(buffer
, " Data packet interval: %d us\n",
98 125 * (1 << fp
->datainterval
));
99 snd_iprintf(buffer
, " Bits: %d\n", fp
->fmt_bits
);
100 // snd_iprintf(buffer, " Max Packet Size = %d\n", fp->maxpacksize);
101 // snd_iprintf(buffer, " EP Attribute = %#x\n", fp->attributes);
105 static void proc_dump_ep_status(struct snd_usb_substream
*subs
,
106 struct snd_usb_endpoint
*data_ep
,
107 struct snd_usb_endpoint
*sync_ep
,
108 struct snd_info_buffer
*buffer
)
112 snd_iprintf(buffer
, " Packet Size = %d\n", data_ep
->curpacksize
);
113 snd_iprintf(buffer
, " Momentary freq = %u Hz (%#x.%04x)\n",
114 subs
->speed
== USB_SPEED_FULL
115 ? 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
;
120 snd_iprintf(buffer
, " Feedback Format = %d.%d\n",
121 (sync_ep
->syncmaxsize
> 3 ? 32 : 24) - res
, res
);
125 static void proc_dump_substream_status(struct snd_usb_substream
*subs
, struct snd_info_buffer
*buffer
)
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
);
133 snd_iprintf(buffer
, " Status: Stop\n");
137 static void proc_pcm_format_read(struct snd_info_entry
*entry
, struct snd_info_buffer
*buffer
)
139 struct snd_usb_stream
*stream
= entry
->private_data
;
141 snd_iprintf(buffer
, "%s : %s\n", stream
->chip
->card
->longname
, stream
->pcm
->name
);
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
);
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
);
155 void snd_usb_proc_pcm_format_add(struct snd_usb_stream
*stream
)
158 struct snd_card
*card
= stream
->chip
->card
;
160 sprintf(name
, "stream%d", stream
->pcm_index
);
161 snd_card_ro_proc_new(card
, name
, stream
, proc_pcm_format_read
);