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