1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __USBAUDIO_CARD_H 3 #define __USBAUDIO_CARD_H 4 5 #include <linux/android_kabi.h> 6 7 #define MAX_NR_RATES 1024 8 #define MAX_PACKS 6 /* per URB */ 9 #define MAX_PACKS_HS (MAX_PACKS * 8) /* in high speed mode */ 10 #define MAX_URBS 12 11 #define SYNC_URBS 4 /* always four urbs for sync */ 12 #define MAX_QUEUE 18 /* try not to exceed this queue length, in ms */ 13 14 struct audioformat { 15 struct list_head list; 16 u64 formats; /* ALSA format bits */ 17 unsigned int channels; /* # channels */ 18 unsigned int fmt_type; /* USB audio format type (1-3) */ 19 unsigned int fmt_bits; /* number of significant bits */ 20 unsigned int frame_size; /* samples per frame for non-audio */ 21 int iface; /* interface number */ 22 unsigned char altsetting; /* corresponding alternate setting */ 23 unsigned char altset_idx; /* array index of altenate setting */ 24 unsigned char attributes; /* corresponding attributes of cs endpoint */ 25 unsigned char endpoint; /* endpoint */ 26 unsigned char ep_attr; /* endpoint attributes */ 27 unsigned char datainterval; /* log_2 of data packet interval */ 28 unsigned char protocol; /* UAC_VERSION_1/2/3 */ 29 unsigned int maxpacksize; /* max. packet size */ 30 unsigned int rates; /* rate bitmasks */ 31 unsigned int rate_min, rate_max; /* min/max rates */ 32 unsigned int nr_rates; /* number of rate table entries */ 33 unsigned int *rate_table; /* rate table */ 34 unsigned char clock; /* associated clock */ 35 struct snd_pcm_chmap_elem *chmap; /* (optional) channel map */ 36 bool dsd_dop; /* add DOP headers in case of DSD samples */ 37 bool dsd_bitrev; /* reverse the bits of each DSD sample */ 38 bool dsd_raw; /* altsetting is raw DSD */ 39 }; 40 41 struct snd_usb_substream; 42 struct snd_usb_endpoint; 43 struct snd_usb_power_domain; 44 45 struct snd_urb_ctx { 46 struct urb *urb; 47 unsigned int buffer_size; /* size of data buffer, if data URB */ 48 struct snd_usb_substream *subs; 49 struct snd_usb_endpoint *ep; 50 int index; /* index for urb array */ 51 int packets; /* number of packets per urb */ 52 int packet_size[MAX_PACKS_HS]; /* size of packets for next submission */ 53 struct list_head ready_list; 54 }; 55 56 struct snd_usb_endpoint { 57 struct snd_usb_audio *chip; 58 59 int use_count; 60 int ep_num; /* the referenced endpoint number */ 61 int type; /* SND_USB_ENDPOINT_TYPE_* */ 62 unsigned long flags; 63 64 void (*prepare_data_urb) (struct snd_usb_substream *subs, 65 struct urb *urb); 66 void (*retire_data_urb) (struct snd_usb_substream *subs, 67 struct urb *urb); 68 69 struct snd_usb_substream *data_subs; 70 struct snd_usb_endpoint *sync_master; 71 struct snd_usb_endpoint *sync_slave; 72 73 struct snd_urb_ctx urb[MAX_URBS]; 74 75 struct snd_usb_packet_info { 76 uint32_t packet_size[MAX_PACKS_HS]; 77 int packets; 78 } next_packet[MAX_URBS]; 79 int next_packet_read_pos, next_packet_write_pos; 80 struct list_head ready_playback_urbs; 81 82 unsigned int nurbs; /* # urbs */ 83 unsigned long active_mask; /* bitmask of active urbs */ 84 unsigned long unlink_mask; /* bitmask of unlinked urbs */ 85 char *syncbuf; /* sync buffer for all sync URBs */ 86 dma_addr_t sync_dma; /* DMA address of syncbuf */ 87 88 unsigned int pipe; /* the data i/o pipe */ 89 unsigned int freqn; /* nominal sampling rate in fs/fps in Q16.16 format */ 90 unsigned int freqm; /* momentary sampling rate in fs/fps in Q16.16 format */ 91 int freqshift; /* how much to shift the feedback value to get Q16.16 */ 92 unsigned int freqmax; /* maximum sampling rate, used for buffer management */ 93 unsigned int phase; /* phase accumulator */ 94 unsigned int maxpacksize; /* max packet size in bytes */ 95 unsigned int maxframesize; /* max packet size in frames */ 96 unsigned int max_urb_frames; /* max URB size in frames */ 97 unsigned int curpacksize; /* current packet size in bytes (for capture) */ 98 unsigned int curframesize; /* current packet size in frames (for capture) */ 99 unsigned int syncmaxsize; /* sync endpoint packet size */ 100 unsigned int fill_max:1; /* fill max packet size always */ 101 unsigned int tenor_fb_quirk:1; /* corrupted feedback data */ 102 unsigned int datainterval; /* log_2 of data packet interval */ 103 unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */ 104 unsigned char silence_value; 105 unsigned int stride; 106 int iface, altsetting; 107 int skip_packets; /* quirks for devices to ignore the first n packets 108 in a stream */ 109 bool is_implicit_feedback; /* This endpoint is used as implicit feedback */ 110 111 spinlock_t lock; 112 struct list_head list; 113 114 ANDROID_KABI_RESERVE(1); 115 ANDROID_KABI_RESERVE(2); 116 ANDROID_KABI_RESERVE(3); 117 ANDROID_KABI_RESERVE(4); 118 }; 119 120 struct media_ctl; 121 122 struct snd_usb_substream { 123 struct snd_usb_stream *stream; 124 struct usb_device *dev; 125 struct snd_pcm_substream *pcm_substream; 126 int direction; /* playback or capture */ 127 int interface; /* current interface */ 128 int endpoint; /* assigned endpoint */ 129 struct audioformat *cur_audiofmt; /* current audioformat pointer (for hw_params callback) */ 130 struct snd_usb_power_domain *str_pd; /* UAC3 Power Domain for streaming path */ 131 snd_pcm_format_t pcm_format; /* current audio format (for hw_params callback) */ 132 unsigned int channels; /* current number of channels (for hw_params callback) */ 133 unsigned int channels_max; /* max channels in the all audiofmts */ 134 unsigned int cur_rate; /* current rate (for hw_params callback) */ 135 unsigned int period_bytes; /* current period bytes (for hw_params callback) */ 136 unsigned int period_frames; /* current frames per period */ 137 unsigned int buffer_periods; /* current periods per buffer */ 138 unsigned int altset_idx; /* USB data format: index of alternate setting */ 139 unsigned int txfr_quirk:1; /* allow sub-frame alignment */ 140 unsigned int tx_length_quirk:1; /* add length specifier to transfers */ 141 unsigned int fmt_type; /* USB audio format type (1-3) */ 142 unsigned int pkt_offset_adj; /* Bytes to drop from beginning of packets (for non-compliant devices) */ 143 144 unsigned int running: 1; /* running status */ 145 146 unsigned int hwptr_done; /* processed byte position in the buffer */ 147 unsigned int transfer_done; /* processed frames since last period update */ 148 unsigned int frame_limit; /* limits number of packets in URB */ 149 150 /* data and sync endpoints for this stream */ 151 unsigned int ep_num; /* the endpoint number */ 152 struct snd_usb_endpoint *data_endpoint; 153 struct snd_usb_endpoint *sync_endpoint; 154 unsigned long flags; 155 bool need_setup_ep; /* (re)configure EP at prepare? */ 156 bool need_setup_fmt; /* (re)configure fmt after resume? */ 157 unsigned int speed; /* USB_SPEED_XXX */ 158 159 u64 formats; /* format bitmasks (all or'ed) */ 160 unsigned int num_formats; /* number of supported audio formats (list) */ 161 struct list_head fmt_list; /* format list */ 162 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */ 163 spinlock_t lock; 164 165 int last_frame_number; /* stored frame number */ 166 int last_delay; /* stored delay */ 167 168 struct { 169 int marker; 170 int channel; 171 int byte_idx; 172 } dsd_dop; 173 174 bool trigger_tstamp_pending_update; /* trigger timestamp being updated from initial estimate */ 175 struct media_ctl *media_ctl; 176 }; 177 178 struct snd_usb_stream { 179 struct snd_usb_audio *chip; 180 struct snd_pcm *pcm; 181 int pcm_index; 182 unsigned int fmt_type; /* USB audio format type (1-3) */ 183 struct snd_usb_substream substream[2]; 184 struct list_head list; 185 }; 186 187 struct snd_usb_substream *find_snd_usb_substream(unsigned int card_num, 188 unsigned int pcm_idx, unsigned int direction, struct snd_usb_audio 189 **uchip, void (*disconnect_cb)(struct snd_usb_audio *chip)); 190 191 int snd_vendor_set_ops(struct snd_usb_audio_vendor_ops *vendor_ops); 192 struct snd_usb_audio_vendor_ops *snd_vendor_get_ops(void); 193 int snd_vendor_set_interface(struct usb_device *udev, 194 struct usb_host_interface *alts, 195 int iface, int alt); 196 int snd_vendor_set_rate(struct usb_interface *intf, int iface, int rate, 197 int alt); 198 int snd_vendor_set_pcm_buf(struct usb_device *udev, int iface); 199 int snd_vendor_set_pcm_intf(struct usb_interface *intf, int iface, int alt, 200 int direction); 201 int snd_vendor_set_pcm_connection(struct usb_device *udev, 202 enum snd_vendor_pcm_open_close onoff, 203 int direction); 204 int snd_vendor_set_pcm_binterval(struct audioformat *fp, 205 struct audioformat *found, 206 int *cur_attr, int *attr); 207 208 #endif /* __USBAUDIO_CARD_H */ 209