Linux Audio

Check our new training course

Loading...
v3.1
 
  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
 18#include <linux/init.h>
 19#include <linux/usb.h>
 20
 21#include <sound/core.h>
 22#include <sound/info.h>
 23#include <sound/pcm.h>
 24
 25#include "usbaudio.h"
 26#include "helper.h"
 27#include "card.h"
 
 28#include "proc.h"
 29
 30/* convert our full speed USB rate into sampling rate in Hz */
 31static inline unsigned get_full_speed_hz(unsigned int usb_rate)
 32{
 33	return (usb_rate * 125 + (1 << 12)) >> 13;
 34}
 35
 36/* convert our high speed USB rate into sampling rate in Hz */
 37static inline unsigned get_high_speed_hz(unsigned int usb_rate)
 38{
 39	return (usb_rate * 125 + (1 << 9)) >> 10;
 40}
 41
 42/*
 43 * common proc files to show the usb device info
 44 */
 45static void proc_audio_usbbus_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, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum);
 50}
 51
 52static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
 53{
 54	struct snd_usb_audio *chip = entry->private_data;
 55	if (!chip->shutdown)
 56		snd_iprintf(buffer, "%04x:%04x\n", 
 57			    USB_ID_VENDOR(chip->usb_id),
 58			    USB_ID_PRODUCT(chip->usb_id));
 59}
 60
 61void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
 62{
 63	struct snd_info_entry *entry;
 64	if (!snd_card_proc_new(chip->card, "usbbus", &entry))
 65		snd_info_set_text_ops(entry, chip, proc_audio_usbbus_read);
 66	if (!snd_card_proc_new(chip->card, "usbid", &entry))
 67		snd_info_set_text_ops(entry, chip, proc_audio_usbid_read);
 68}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 69
 70/*
 71 * proc interface for list the supported pcm formats
 72 */
 73static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
 74{
 75	struct list_head *p;
 76	static char *sync_types[4] = {
 77		"NONE", "ASYNC", "ADAPTIVE", "SYNC"
 78	};
 79
 80	list_for_each(p, &subs->fmt_list) {
 81		struct audioformat *fp;
 82		snd_pcm_format_t fmt;
 83		fp = list_entry(p, struct audioformat, list);
 84		snd_iprintf(buffer, "  Interface %d\n", fp->iface);
 85		snd_iprintf(buffer, "    Altset %d\n", fp->altsetting);
 86		snd_iprintf(buffer, "    Format:");
 87		for (fmt = 0; fmt <= SNDRV_PCM_FORMAT_LAST; ++fmt)
 88			if (fp->formats & (1uLL << fmt))
 89				snd_iprintf(buffer, " %s",
 90					    snd_pcm_format_name(fmt));
 91		snd_iprintf(buffer, "\n");
 92		snd_iprintf(buffer, "    Channels: %d\n", fp->channels);
 93		snd_iprintf(buffer, "    Endpoint: %d %s (%s)\n",
 
 94			    fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
 95			    fp->endpoint & USB_DIR_IN ? "IN" : "OUT",
 96			    sync_types[(fp->ep_attr & USB_ENDPOINT_SYNCTYPE) >> 2]);
 97		if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) {
 98			snd_iprintf(buffer, "    Rates: %d - %d (continuous)\n",
 99				    fp->rate_min, fp->rate_max);
100		} else {
101			unsigned int i;
102			snd_iprintf(buffer, "    Rates: ");
103			for (i = 0; i < fp->nr_rates; i++) {
104				if (i > 0)
105					snd_iprintf(buffer, ", ");
106				snd_iprintf(buffer, "%d", fp->rate_table[i]);
107			}
108			snd_iprintf(buffer, "\n");
109		}
110		if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL)
111			snd_iprintf(buffer, "    Data packet interval: %d us\n",
112				    125 * (1 << fp->datainterval));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113		// snd_iprintf(buffer, "    Max Packet Size = %d\n", fp->maxpacksize);
114		// snd_iprintf(buffer, "    EP Attribute = %#x\n", fp->attributes);
115	}
116}
117
118static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119{
 
120	if (subs->running) {
121		unsigned int i;
122		snd_iprintf(buffer, "  Status: Running\n");
123		snd_iprintf(buffer, "    Interface = %d\n", subs->interface);
124		snd_iprintf(buffer, "    Altset = %d\n", subs->altset_idx);
125		snd_iprintf(buffer, "    URBs = %d [ ", subs->nurbs);
126		for (i = 0; i < subs->nurbs; i++)
127			snd_iprintf(buffer, "%d ", subs->dataurb[i].packets);
128		snd_iprintf(buffer, "]\n");
129		snd_iprintf(buffer, "    Packet Size = %d\n", subs->curpacksize);
130		snd_iprintf(buffer, "    Momentary freq = %u Hz (%#x.%04x)\n",
131			    snd_usb_get_speed(subs->dev) == USB_SPEED_FULL
132			    ? get_full_speed_hz(subs->freqm)
133			    : get_high_speed_hz(subs->freqm),
134			    subs->freqm >> 16, subs->freqm & 0xffff);
135		if (subs->freqshift != INT_MIN)
136			snd_iprintf(buffer, "    Feedback Format = %d.%d\n",
137				    (subs->syncmaxsize > 3 ? 32 : 24)
138						- (16 - subs->freqshift),
139				    16 - subs->freqshift);
140	} else {
141		snd_iprintf(buffer, "  Status: Stop\n");
142	}
 
143}
144
145static void proc_pcm_format_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
146{
147	struct snd_usb_stream *stream = entry->private_data;
 
148
149	snd_iprintf(buffer, "%s : %s\n", stream->chip->card->longname, stream->pcm->name);
150
151	if (stream->substream[SNDRV_PCM_STREAM_PLAYBACK].num_formats) {
152		snd_iprintf(buffer, "\nPlayback:\n");
153		proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
154		proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
155	}
156	if (stream->substream[SNDRV_PCM_STREAM_CAPTURE].num_formats) {
157		snd_iprintf(buffer, "\nCapture:\n");
158		proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
159		proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
160	}
161}
162
163void snd_usb_proc_pcm_format_add(struct snd_usb_stream *stream)
164{
165	struct snd_info_entry *entry;
166	char name[32];
167	struct snd_card *card = stream->chip->card;
168
169	sprintf(name, "stream%d", stream->pcm_index);
170	if (!snd_card_proc_new(card, name, &entry))
171		snd_info_set_text_ops(entry, stream, proc_pcm_format_read);
172}
173
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  3 */
  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"
 15#include "endpoint.h"
 16#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;
 36	if (!atomic_read(&chip->shutdown))
 37		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;
 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));
 47}
 48
 49void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
 50{
 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);
 55}
 56
 57static 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
 89/*
 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{
 94	struct audioformat *fp;
 95	static const char * const sync_types[4] = {
 96		"NONE", "ASYNC", "ADAPTIVE", "SYNC"
 97	};
 98
 99	list_for_each_entry(fp, &subs->fmt_list, list) {
 
100		snd_pcm_format_t fmt;
101
102		snd_iprintf(buffer, "  Interface %d\n", fp->iface);
103		snd_iprintf(buffer, "    Altset %d\n", fp->altsetting);
104		snd_iprintf(buffer, "    Format:");
105		pcm_for_each_format(fmt)
106			if (fp->formats & pcm_format_to_bits(fmt))
107				snd_iprintf(buffer, " %s",
108					    snd_pcm_format_name(fmt));
109		snd_iprintf(buffer, "\n");
110		snd_iprintf(buffer, "    Channels: %d\n", fp->channels);
111		snd_iprintf(buffer, "    Endpoint: 0x%02x (%d %s) (%s)\n",
112			    fp->endpoint,
113			    fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
114			    fp->endpoint & USB_DIR_IN ? "IN" : "OUT",
115			    sync_types[(fp->ep_attr & USB_ENDPOINT_SYNCTYPE) >> 2]);
116		if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) {
117			snd_iprintf(buffer, "    Rates: %d - %d (continuous)\n",
118				    fp->rate_min, fp->rate_max);
119		} else {
120			unsigned int i;
121			snd_iprintf(buffer, "    Rates: ");
122			for (i = 0; i < fp->nr_rates; i++) {
123				if (i > 0)
124					snd_iprintf(buffer, ", ");
125				snd_iprintf(buffer, "%d", fp->rate_table[i]);
126			}
127			snd_iprintf(buffer, "\n");
128		}
129		if (subs->speed != USB_SPEED_FULL)
130			snd_iprintf(buffer, "    Data packet interval: %d us\n",
131				    125 * (1 << fp->datainterval));
132		snd_iprintf(buffer, "    Bits: %d\n", fp->fmt_bits);
133
134		if (fp->dsd_raw)
135			snd_iprintf(buffer, "    DSD raw: DOP=%d, bitrev=%d\n",
136				    fp->dsd_dop, fp->dsd_bitrev);
137
138		if (fp->chmap) {
139			const struct snd_pcm_chmap_elem *map = fp->chmap;
140			int c;
141
142			snd_iprintf(buffer, "    Channel map:");
143			for (c = 0; c < map->channels; c++) {
144				if (map->map[c] >= ARRAY_SIZE(channel_labels) ||
145				    !channel_labels[map->map[c]])
146					snd_iprintf(buffer, " --");
147				else
148					snd_iprintf(buffer, " %s",
149						    channel_labels[map->map[c]]);
150			}
151			snd_iprintf(buffer, "\n");
152		}
153
154		if (fp->sync_ep) {
155			snd_iprintf(buffer, "    Sync Endpoint: 0x%02x (%d %s)\n",
156				    fp->sync_ep,
157				    fp->sync_ep & USB_ENDPOINT_NUMBER_MASK,
158				    fp->sync_ep & USB_DIR_IN ? "IN" : "OUT");
159			snd_iprintf(buffer, "    Sync EP Interface: %d\n",
160				    fp->sync_iface);
161			snd_iprintf(buffer, "    Sync EP Altset: %d\n",
162				    fp->sync_altsetting);
163			snd_iprintf(buffer, "    Implicit Feedback Mode: %s\n",
164				    fp->implicit_fb ? "Yes" : "No");
165		}
166
167		// snd_iprintf(buffer, "    Max Packet Size = %d\n", fp->maxpacksize);
168		// snd_iprintf(buffer, "    EP Attribute = %#x\n", fp->attributes);
169	}
170}
171
172static void proc_dump_ep_status(struct snd_usb_substream *subs,
173				struct snd_usb_endpoint *data_ep,
174				struct snd_usb_endpoint *sync_ep,
175				struct snd_info_buffer *buffer)
176{
177	if (!data_ep)
178		return;
179	snd_iprintf(buffer, "    Packet Size = %d\n", data_ep->curpacksize);
180	snd_iprintf(buffer, "    Momentary freq = %u Hz (%#x.%04x)\n",
181		    subs->speed == USB_SPEED_FULL
182		    ? get_full_speed_hz(data_ep->freqm)
183		    : get_high_speed_hz(data_ep->freqm),
184		    data_ep->freqm >> 16, data_ep->freqm & 0xffff);
185	if (sync_ep && data_ep->freqshift != INT_MIN) {
186		int res = 16 - data_ep->freqshift;
187		snd_iprintf(buffer, "    Feedback Format = %d.%d\n",
188			    (sync_ep->syncmaxsize > 3 ? 32 : 24) - res, res);
189	}
190}
191
192static void proc_dump_substream_status(struct snd_usb_audio *chip,
193				       struct snd_usb_substream *subs,
194				       struct snd_info_buffer *buffer)
195{
196	mutex_lock(&chip->mutex);
197	if (subs->running) {
 
198		snd_iprintf(buffer, "  Status: Running\n");
199		if (subs->cur_audiofmt) {
200			snd_iprintf(buffer, "    Interface = %d\n", subs->cur_audiofmt->iface);
201			snd_iprintf(buffer, "    Altset = %d\n", subs->cur_audiofmt->altsetting);
202		}
203		proc_dump_ep_status(subs, subs->data_endpoint, subs->sync_endpoint, buffer);
 
 
 
 
 
 
 
 
 
 
 
 
204	} else {
205		snd_iprintf(buffer, "  Status: Stop\n");
206	}
207	mutex_unlock(&chip->mutex);
208}
209
210static void proc_pcm_format_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
211{
212	struct snd_usb_stream *stream = entry->private_data;
213	struct snd_usb_audio *chip = stream->chip;
214
215	snd_iprintf(buffer, "%s : %s\n", chip->card->longname, stream->pcm->name);
216
217	if (stream->substream[SNDRV_PCM_STREAM_PLAYBACK].num_formats) {
218		snd_iprintf(buffer, "\nPlayback:\n");
219		proc_dump_substream_status(chip, &stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
220		proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
221	}
222	if (stream->substream[SNDRV_PCM_STREAM_CAPTURE].num_formats) {
223		snd_iprintf(buffer, "\nCapture:\n");
224		proc_dump_substream_status(chip, &stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
225		proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
226	}
227}
228
229void snd_usb_proc_pcm_format_add(struct snd_usb_stream *stream)
230{
 
231	char name[32];
232	struct snd_card *card = stream->chip->card;
233
234	sprintf(name, "stream%d", stream->pcm_index);
235	snd_card_ro_proc_new(card, name, stream, proc_pcm_format_read);
 
236}
237