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