Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 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" |
Daniel Mack | c89a5d9 | 2012-04-21 13:52:12 +0200 | [diff] [blame] | 28 | #include "endpoint.h" |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 29 | #include "proc.h" |
| 30 | |
| 31 | /* convert our full speed USB rate into sampling rate in Hz */ |
| 32 | static inline unsigned get_full_speed_hz(unsigned int usb_rate) |
| 33 | { |
| 34 | return (usb_rate * 125 + (1 << 12)) >> 13; |
| 35 | } |
| 36 | |
| 37 | /* convert our high speed USB rate into sampling rate in Hz */ |
| 38 | static inline unsigned get_high_speed_hz(unsigned int usb_rate) |
| 39 | { |
| 40 | return (usb_rate * 125 + (1 << 9)) >> 10; |
| 41 | } |
| 42 | |
| 43 | /* |
| 44 | * common proc files to show the usb device info |
| 45 | */ |
| 46 | static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) |
| 47 | { |
| 48 | struct snd_usb_audio *chip = entry->private_data; |
Takashi Iwai | 47ab154 | 2015-08-25 16:09:00 +0200 | [diff] [blame] | 49 | if (!atomic_read(&chip->shutdown)) |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 50 | snd_iprintf(buffer, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum); |
| 51 | } |
| 52 | |
| 53 | static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) |
| 54 | { |
| 55 | struct snd_usb_audio *chip = entry->private_data; |
Takashi Iwai | 47ab154 | 2015-08-25 16:09:00 +0200 | [diff] [blame] | 56 | if (!atomic_read(&chip->shutdown)) |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 57 | snd_iprintf(buffer, "%04x:%04x\n", |
| 58 | USB_ID_VENDOR(chip->usb_id), |
| 59 | USB_ID_PRODUCT(chip->usb_id)); |
| 60 | } |
| 61 | |
| 62 | void snd_usb_audio_create_proc(struct snd_usb_audio *chip) |
| 63 | { |
| 64 | struct snd_info_entry *entry; |
| 65 | if (!snd_card_proc_new(chip->card, "usbbus", &entry)) |
| 66 | snd_info_set_text_ops(entry, chip, proc_audio_usbbus_read); |
| 67 | if (!snd_card_proc_new(chip->card, "usbid", &entry)) |
| 68 | snd_info_set_text_ops(entry, chip, proc_audio_usbid_read); |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * proc interface for list the supported pcm formats |
| 73 | */ |
| 74 | static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct snd_info_buffer *buffer) |
| 75 | { |
Eldad Zack | 88766f0 | 2013-04-03 23:18:49 +0200 | [diff] [blame] | 76 | struct audioformat *fp; |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 77 | static char *sync_types[4] = { |
| 78 | "NONE", "ASYNC", "ADAPTIVE", "SYNC" |
| 79 | }; |
| 80 | |
Eldad Zack | 88766f0 | 2013-04-03 23:18:49 +0200 | [diff] [blame] | 81 | list_for_each_entry(fp, &subs->fmt_list, list) { |
Clemens Ladisch | 015eb0b | 2010-03-04 19:46:15 +0100 | [diff] [blame] | 82 | snd_pcm_format_t fmt; |
Eldad Zack | 88766f0 | 2013-04-03 23:18:49 +0200 | [diff] [blame] | 83 | |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 84 | snd_iprintf(buffer, " Interface %d\n", fp->iface); |
| 85 | snd_iprintf(buffer, " Altset %d\n", fp->altsetting); |
Clemens Ladisch | 015eb0b | 2010-03-04 19:46:15 +0100 | [diff] [blame] | 86 | snd_iprintf(buffer, " Format:"); |
| 87 | for (fmt = 0; fmt <= SNDRV_PCM_FORMAT_LAST; ++fmt) |
Eldad Zack | 74c34ca | 2013-04-23 01:00:41 +0200 | [diff] [blame] | 88 | if (fp->formats & pcm_format_to_bits(fmt)) |
Clemens Ladisch | 015eb0b | 2010-03-04 19:46:15 +0100 | [diff] [blame] | 89 | snd_iprintf(buffer, " %s", |
| 90 | snd_pcm_format_name(fmt)); |
| 91 | snd_iprintf(buffer, "\n"); |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 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 | } |
Takashi Iwai | 978520b | 2012-10-12 15:12:55 +0200 | [diff] [blame] | 110 | if (subs->speed != USB_SPEED_FULL) |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 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 | |
Takashi Iwai | 22026c1 | 2012-04-13 12:57:39 +0200 | [diff] [blame] | 118 | static void proc_dump_ep_status(struct snd_usb_substream *subs, |
Torstein Hegge | e6135fe | 2013-05-16 20:26:17 +0200 | [diff] [blame] | 119 | struct snd_usb_endpoint *data_ep, |
| 120 | struct snd_usb_endpoint *sync_ep, |
Takashi Iwai | 22026c1 | 2012-04-13 12:57:39 +0200 | [diff] [blame] | 121 | struct snd_info_buffer *buffer) |
| 122 | { |
Torstein Hegge | e6135fe | 2013-05-16 20:26:17 +0200 | [diff] [blame] | 123 | if (!data_ep) |
Takashi Iwai | 22026c1 | 2012-04-13 12:57:39 +0200 | [diff] [blame] | 124 | return; |
Torstein Hegge | e6135fe | 2013-05-16 20:26:17 +0200 | [diff] [blame] | 125 | snd_iprintf(buffer, " Packet Size = %d\n", data_ep->curpacksize); |
Takashi Iwai | 22026c1 | 2012-04-13 12:57:39 +0200 | [diff] [blame] | 126 | snd_iprintf(buffer, " Momentary freq = %u Hz (%#x.%04x)\n", |
Takashi Iwai | 978520b | 2012-10-12 15:12:55 +0200 | [diff] [blame] | 127 | subs->speed == USB_SPEED_FULL |
Torstein Hegge | e6135fe | 2013-05-16 20:26:17 +0200 | [diff] [blame] | 128 | ? get_full_speed_hz(data_ep->freqm) |
| 129 | : get_high_speed_hz(data_ep->freqm), |
| 130 | data_ep->freqm >> 16, data_ep->freqm & 0xffff); |
| 131 | if (sync_ep && data_ep->freqshift != INT_MIN) { |
| 132 | int res = 16 - data_ep->freqshift; |
Takashi Iwai | 22026c1 | 2012-04-13 12:57:39 +0200 | [diff] [blame] | 133 | snd_iprintf(buffer, " Feedback Format = %d.%d\n", |
Torstein Hegge | e6135fe | 2013-05-16 20:26:17 +0200 | [diff] [blame] | 134 | (sync_ep->syncmaxsize > 3 ? 32 : 24) - res, res); |
Takashi Iwai | 22026c1 | 2012-04-13 12:57:39 +0200 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 138 | static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer) |
| 139 | { |
| 140 | if (subs->running) { |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 141 | snd_iprintf(buffer, " Status: Running\n"); |
| 142 | snd_iprintf(buffer, " Interface = %d\n", subs->interface); |
Clemens Ladisch | e11b4e0 | 2010-03-04 19:46:14 +0100 | [diff] [blame] | 143 | snd_iprintf(buffer, " Altset = %d\n", subs->altset_idx); |
Torstein Hegge | e6135fe | 2013-05-16 20:26:17 +0200 | [diff] [blame] | 144 | proc_dump_ep_status(subs, subs->data_endpoint, subs->sync_endpoint, buffer); |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 145 | } else { |
| 146 | snd_iprintf(buffer, " Status: Stop\n"); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | static void proc_pcm_format_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) |
| 151 | { |
| 152 | struct snd_usb_stream *stream = entry->private_data; |
| 153 | |
| 154 | snd_iprintf(buffer, "%s : %s\n", stream->chip->card->longname, stream->pcm->name); |
| 155 | |
| 156 | if (stream->substream[SNDRV_PCM_STREAM_PLAYBACK].num_formats) { |
| 157 | snd_iprintf(buffer, "\nPlayback:\n"); |
| 158 | proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer); |
| 159 | proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer); |
| 160 | } |
| 161 | if (stream->substream[SNDRV_PCM_STREAM_CAPTURE].num_formats) { |
| 162 | snd_iprintf(buffer, "\nCapture:\n"); |
| 163 | proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer); |
| 164 | proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | void snd_usb_proc_pcm_format_add(struct snd_usb_stream *stream) |
| 169 | { |
| 170 | struct snd_info_entry *entry; |
| 171 | char name[32]; |
| 172 | struct snd_card *card = stream->chip->card; |
| 173 | |
| 174 | sprintf(name, "stream%d", stream->pcm_index); |
| 175 | if (!snd_card_proc_new(card, name, &entry)) |
| 176 | snd_info_set_text_ops(entry, stream, proc_pcm_format_read); |
| 177 | } |
| 178 | |