Blame view

sound/usb/proc.c 5.99 KB
e5779998b   Daniel Mack   ALSA: usb-audio: ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  /*
   *   This program is free software; you can redistribute it and/or modify
   *   it under the terms of the GNU General Public License as published by
   *   the Free Software Foundation; either version 2 of the License, or
   *   (at your option) any later version.
   *
   *   This program is distributed in the hope that it will be useful,
   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *   GNU General Public License for more details.
   *
   *   You should have received a copy of the GNU General Public License
   *   along with this program; if not, write to the Free Software
   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   *
   */
  
  #include <linux/init.h>
  #include <linux/usb.h>
  
  #include <sound/core.h>
  #include <sound/info.h>
  #include <sound/pcm.h>
  
  #include "usbaudio.h"
  #include "helper.h"
  #include "card.h"
c89a5d9ca   Daniel Mack   ALSA: snd-usb: re...
28
  #include "endpoint.h"
e5779998b   Daniel Mack   ALSA: usb-audio: ...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  #include "proc.h"
  
  /* convert our full speed USB rate into sampling rate in Hz */
  static inline unsigned get_full_speed_hz(unsigned int usb_rate)
  {
  	return (usb_rate * 125 + (1 << 12)) >> 13;
  }
  
  /* convert our high speed USB rate into sampling rate in Hz */
  static inline unsigned get_high_speed_hz(unsigned int usb_rate)
  {
  	return (usb_rate * 125 + (1 << 9)) >> 10;
  }
  
  /*
   * common proc files to show the usb device info
   */
  static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  {
  	struct snd_usb_audio *chip = entry->private_data;
  	if (!chip->shutdown)
  		snd_iprintf(buffer, "%03d/%03d
  ", chip->dev->bus->busnum, chip->dev->devnum);
  }
  
  static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  {
  	struct snd_usb_audio *chip = entry->private_data;
  	if (!chip->shutdown)
  		snd_iprintf(buffer, "%04x:%04x
  ", 
  			    USB_ID_VENDOR(chip->usb_id),
  			    USB_ID_PRODUCT(chip->usb_id));
  }
  
  void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
  {
  	struct snd_info_entry *entry;
  	if (!snd_card_proc_new(chip->card, "usbbus", &entry))
  		snd_info_set_text_ops(entry, chip, proc_audio_usbbus_read);
  	if (!snd_card_proc_new(chip->card, "usbid", &entry))
  		snd_info_set_text_ops(entry, chip, proc_audio_usbid_read);
  }
  
  /*
   * proc interface for list the supported pcm formats
   */
  static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
  {
88766f04c   Eldad Zack   ALSA: usb-audio: ...
78
  	struct audioformat *fp;
e5779998b   Daniel Mack   ALSA: usb-audio: ...
79
80
81
  	static char *sync_types[4] = {
  		"NONE", "ASYNC", "ADAPTIVE", "SYNC"
  	};
88766f04c   Eldad Zack   ALSA: usb-audio: ...
82
  	list_for_each_entry(fp, &subs->fmt_list, list) {
015eb0b08   Clemens Ladisch   ALSA: usb-audio: ...
83
  		snd_pcm_format_t fmt;
88766f04c   Eldad Zack   ALSA: usb-audio: ...
84

e5779998b   Daniel Mack   ALSA: usb-audio: ...
85
86
87
88
  		snd_iprintf(buffer, "  Interface %d
  ", fp->iface);
  		snd_iprintf(buffer, "    Altset %d
  ", fp->altsetting);
015eb0b08   Clemens Ladisch   ALSA: usb-audio: ...
89
90
  		snd_iprintf(buffer, "    Format:");
  		for (fmt = 0; fmt <= SNDRV_PCM_FORMAT_LAST; ++fmt)
74c34ca1c   Eldad Zack   ALSA: pcm_format_...
91
  			if (fp->formats & pcm_format_to_bits(fmt))
015eb0b08   Clemens Ladisch   ALSA: usb-audio: ...
92
93
94
95
  				snd_iprintf(buffer, " %s",
  					    snd_pcm_format_name(fmt));
  		snd_iprintf(buffer, "
  ");
e5779998b   Daniel Mack   ALSA: usb-audio: ...
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  		snd_iprintf(buffer, "    Channels: %d
  ", fp->channels);
  		snd_iprintf(buffer, "    Endpoint: %d %s (%s)
  ",
  			    fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
  			    fp->endpoint & USB_DIR_IN ? "IN" : "OUT",
  			    sync_types[(fp->ep_attr & USB_ENDPOINT_SYNCTYPE) >> 2]);
  		if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) {
  			snd_iprintf(buffer, "    Rates: %d - %d (continuous)
  ",
  				    fp->rate_min, fp->rate_max);
  		} else {
  			unsigned int i;
  			snd_iprintf(buffer, "    Rates: ");
  			for (i = 0; i < fp->nr_rates; i++) {
  				if (i > 0)
  					snd_iprintf(buffer, ", ");
  				snd_iprintf(buffer, "%d", fp->rate_table[i]);
  			}
  			snd_iprintf(buffer, "
  ");
  		}
978520b75   Takashi Iwai   ALSA: usb-audio: ...
118
  		if (subs->speed != USB_SPEED_FULL)
e5779998b   Daniel Mack   ALSA: usb-audio: ...
119
120
121
122
123
124
125
126
127
  			snd_iprintf(buffer, "    Data packet interval: %d us
  ",
  				    125 * (1 << fp->datainterval));
  		// snd_iprintf(buffer, "    Max Packet Size = %d
  ", fp->maxpacksize);
  		// snd_iprintf(buffer, "    EP Attribute = %#x
  ", fp->attributes);
  	}
  }
22026c1a7   Takashi Iwai   ALSA: usb: Remove...
128
  static void proc_dump_ep_status(struct snd_usb_substream *subs,
e6135fe96   Torstein Hegge   ALSA: usb-audio: ...
129
130
  				struct snd_usb_endpoint *data_ep,
  				struct snd_usb_endpoint *sync_ep,
22026c1a7   Takashi Iwai   ALSA: usb: Remove...
131
132
  				struct snd_info_buffer *buffer)
  {
e6135fe96   Torstein Hegge   ALSA: usb-audio: ...
133
  	if (!data_ep)
22026c1a7   Takashi Iwai   ALSA: usb: Remove...
134
  		return;
e6135fe96   Torstein Hegge   ALSA: usb-audio: ...
135
136
  	snd_iprintf(buffer, "    Packet Size = %d
  ", data_ep->curpacksize);
22026c1a7   Takashi Iwai   ALSA: usb: Remove...
137
138
  	snd_iprintf(buffer, "    Momentary freq = %u Hz (%#x.%04x)
  ",
978520b75   Takashi Iwai   ALSA: usb-audio: ...
139
  		    subs->speed == USB_SPEED_FULL
e6135fe96   Torstein Hegge   ALSA: usb-audio: ...
140
141
142
143
144
  		    ? get_full_speed_hz(data_ep->freqm)
  		    : get_high_speed_hz(data_ep->freqm),
  		    data_ep->freqm >> 16, data_ep->freqm & 0xffff);
  	if (sync_ep && data_ep->freqshift != INT_MIN) {
  		int res = 16 - data_ep->freqshift;
22026c1a7   Takashi Iwai   ALSA: usb: Remove...
145
146
  		snd_iprintf(buffer, "    Feedback Format = %d.%d
  ",
e6135fe96   Torstein Hegge   ALSA: usb-audio: ...
147
  			    (sync_ep->syncmaxsize > 3 ? 32 : 24) - res, res);
22026c1a7   Takashi Iwai   ALSA: usb: Remove...
148
149
  	}
  }
e5779998b   Daniel Mack   ALSA: usb-audio: ...
150
151
152
  static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
  {
  	if (subs->running) {
e5779998b   Daniel Mack   ALSA: usb-audio: ...
153
154
155
156
  		snd_iprintf(buffer, "  Status: Running
  ");
  		snd_iprintf(buffer, "    Interface = %d
  ", subs->interface);
e11b4e0e4   Clemens Ladisch   ALSA: usb-audio: ...
157
158
  		snd_iprintf(buffer, "    Altset = %d
  ", subs->altset_idx);
e6135fe96   Torstein Hegge   ALSA: usb-audio: ...
159
  		proc_dump_ep_status(subs, subs->data_endpoint, subs->sync_endpoint, buffer);
e5779998b   Daniel Mack   ALSA: usb-audio: ...
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
  	} else {
  		snd_iprintf(buffer, "  Status: Stop
  ");
  	}
  }
  
  static void proc_pcm_format_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  {
  	struct snd_usb_stream *stream = entry->private_data;
  
  	snd_iprintf(buffer, "%s : %s
  ", stream->chip->card->longname, stream->pcm->name);
  
  	if (stream->substream[SNDRV_PCM_STREAM_PLAYBACK].num_formats) {
  		snd_iprintf(buffer, "
  Playback:
  ");
  		proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
  		proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
  	}
  	if (stream->substream[SNDRV_PCM_STREAM_CAPTURE].num_formats) {
  		snd_iprintf(buffer, "
  Capture:
  ");
  		proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
  		proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
  	}
  }
  
  void snd_usb_proc_pcm_format_add(struct snd_usb_stream *stream)
  {
  	struct snd_info_entry *entry;
  	char name[32];
  	struct snd_card *card = stream->chip->card;
  
  	sprintf(name, "stream%d", stream->pcm_index);
  	if (!snd_card_proc_new(card, name, &entry))
  		snd_info_set_text_ops(entry, stream, proc_pcm_format_read);
  }