Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __USBAUDIO_CARD_H
0003 #define __USBAUDIO_CARD_H
0004 
0005 #define MAX_NR_RATES    1024
0006 #define MAX_PACKS   6       /* per URB */
0007 #define MAX_PACKS_HS    (MAX_PACKS * 8) /* in high speed mode */
0008 #define MAX_URBS    12
0009 #define SYNC_URBS   4   /* always four urbs for sync */
0010 #define MAX_QUEUE   18  /* try not to exceed this queue length, in ms */
0011 
0012 struct audioformat {
0013     struct list_head list;
0014     u64 formats;            /* ALSA format bits */
0015     unsigned int channels;      /* # channels */
0016     unsigned int fmt_type;      /* USB audio format type (1-3) */
0017     unsigned int fmt_bits;      /* number of significant bits */
0018     unsigned int frame_size;    /* samples per frame for non-audio */
0019     unsigned char iface;        /* interface number */
0020     unsigned char altsetting;   /* corresponding alternate setting */
0021     unsigned char ep_idx;       /* endpoint array index */
0022     unsigned char altset_idx;   /* array index of alternate setting */
0023     unsigned char attributes;   /* corresponding attributes of cs endpoint */
0024     unsigned char endpoint;     /* endpoint */
0025     unsigned char ep_attr;      /* endpoint attributes */
0026     bool implicit_fb;       /* implicit feedback endpoint */
0027     unsigned char sync_ep;      /* sync endpoint number */
0028     unsigned char sync_iface;   /* sync EP interface */
0029     unsigned char sync_altsetting;  /* sync EP alternate setting */
0030     unsigned char sync_ep_idx;  /* sync EP array index */
0031     unsigned char datainterval; /* log_2 of data packet interval */
0032     unsigned char protocol;     /* UAC_VERSION_1/2/3 */
0033     unsigned int maxpacksize;   /* max. packet size */
0034     unsigned int rates;     /* rate bitmasks */
0035     unsigned int rate_min, rate_max;    /* min/max rates */
0036     unsigned int nr_rates;      /* number of rate table entries */
0037     unsigned int *rate_table;   /* rate table */
0038     unsigned char clock;        /* associated clock */
0039     struct snd_pcm_chmap_elem *chmap; /* (optional) channel map */
0040     bool dsd_dop;           /* add DOP headers in case of DSD samples */
0041     bool dsd_bitrev;        /* reverse the bits of each DSD sample */
0042     bool dsd_raw;           /* altsetting is raw DSD */
0043 };
0044 
0045 struct snd_usb_substream;
0046 struct snd_usb_iface_ref;
0047 struct snd_usb_clock_ref;
0048 struct snd_usb_endpoint;
0049 struct snd_usb_power_domain;
0050 
0051 struct snd_urb_ctx {
0052     struct urb *urb;
0053     unsigned int buffer_size;   /* size of data buffer, if data URB */
0054     struct snd_usb_substream *subs;
0055     struct snd_usb_endpoint *ep;
0056     int index;  /* index for urb array */
0057     int packets;    /* number of packets per urb */
0058     int queued; /* queued data bytes by this urb */
0059     int packet_size[MAX_PACKS_HS]; /* size of packets for next submission */
0060     struct list_head ready_list;
0061 };
0062 
0063 struct snd_usb_endpoint {
0064     struct snd_usb_audio *chip;
0065     struct snd_usb_iface_ref *iface_ref;
0066     struct snd_usb_clock_ref *clock_ref;
0067 
0068     int opened;     /* open refcount; protect with chip->mutex */
0069     atomic_t running;   /* running status */
0070     int ep_num;     /* the referenced endpoint number */
0071     int type;       /* SND_USB_ENDPOINT_TYPE_* */
0072 
0073     unsigned char iface;        /* interface number */
0074     unsigned char altsetting;   /* corresponding alternate setting */
0075     unsigned char ep_idx;       /* endpoint array index */
0076 
0077     atomic_t state;     /* running state */
0078 
0079     int (*prepare_data_urb) (struct snd_usb_substream *subs,
0080                  struct urb *urb,
0081                  bool in_stream_lock);
0082     void (*retire_data_urb) (struct snd_usb_substream *subs,
0083                  struct urb *urb);
0084 
0085     struct snd_usb_substream *data_subs;
0086     struct snd_usb_endpoint *sync_source;
0087     struct snd_usb_endpoint *sync_sink;
0088 
0089     struct snd_urb_ctx urb[MAX_URBS];
0090 
0091     struct snd_usb_packet_info {
0092         uint32_t packet_size[MAX_PACKS_HS];
0093         int packets;
0094     } next_packet[MAX_URBS];
0095     unsigned int next_packet_head;  /* ring buffer offset to read */
0096     unsigned int next_packet_queued; /* queued items in the ring buffer */
0097     struct list_head ready_playback_urbs; /* playback URB FIFO for implicit fb */
0098 
0099     unsigned int nurbs;     /* # urbs */
0100     unsigned long active_mask;  /* bitmask of active urbs */
0101     unsigned long unlink_mask;  /* bitmask of unlinked urbs */
0102     atomic_t submitted_urbs;    /* currently submitted urbs */
0103     char *syncbuf;          /* sync buffer for all sync URBs */
0104     dma_addr_t sync_dma;        /* DMA address of syncbuf */
0105 
0106     unsigned int pipe;      /* the data i/o pipe */
0107     unsigned int packsize[2];   /* small/large packet sizes in samples */
0108     unsigned int sample_rem;    /* remainder from division fs/pps */
0109     unsigned int sample_accum;  /* sample accumulator */
0110     unsigned int pps;       /* packets per second */
0111     unsigned int freqn;     /* nominal sampling rate in fs/fps in Q16.16 format */
0112     unsigned int freqm;     /* momentary sampling rate in fs/fps in Q16.16 format */
0113     int    freqshift;       /* how much to shift the feedback value to get Q16.16 */
0114     unsigned int freqmax;       /* maximum sampling rate, used for buffer management */
0115     unsigned int phase;     /* phase accumulator */
0116     unsigned int maxpacksize;   /* max packet size in bytes */
0117     unsigned int maxframesize;      /* max packet size in frames */
0118     unsigned int max_urb_frames;    /* max URB size in frames */
0119     unsigned int curpacksize;   /* current packet size in bytes (for capture) */
0120     unsigned int curframesize;      /* current packet size in frames (for capture) */
0121     unsigned int syncmaxsize;   /* sync endpoint packet size */
0122     unsigned int fill_max:1;    /* fill max packet size always */
0123     unsigned int tenor_fb_quirk:1;  /* corrupted feedback data */
0124     unsigned int datainterval;      /* log_2 of data packet interval */
0125     unsigned int syncinterval;  /* P for adaptive mode, 0 otherwise */
0126     unsigned char silence_value;
0127     unsigned int stride;
0128     int skip_packets;       /* quirks for devices to ignore the first n packets
0129                        in a stream */
0130     bool implicit_fb_sync;      /* syncs with implicit feedback */
0131     bool lowlatency_playback;   /* low-latency playback mode */
0132     bool need_setup;        /* (re-)need for configure? */
0133 
0134     /* for hw constraints */
0135     const struct audioformat *cur_audiofmt;
0136     unsigned int cur_rate;
0137     snd_pcm_format_t cur_format;
0138     unsigned int cur_channels;
0139     unsigned int cur_frame_bytes;
0140     unsigned int cur_period_frames;
0141     unsigned int cur_period_bytes;
0142     unsigned int cur_buffer_periods;
0143 
0144     spinlock_t lock;
0145     struct list_head list;
0146 };
0147 
0148 struct media_ctl;
0149 
0150 struct snd_usb_substream {
0151     struct snd_usb_stream *stream;
0152     struct usb_device *dev;
0153     struct snd_pcm_substream *pcm_substream;
0154     int direction;  /* playback or capture */
0155     int endpoint;   /* assigned endpoint */
0156     const struct audioformat *cur_audiofmt; /* current audioformat pointer (for hw_params callback) */
0157     struct snd_usb_power_domain *str_pd;    /* UAC3 Power Domain for streaming path */
0158     unsigned int channels_max;  /* max channels in the all audiofmts */
0159     unsigned int txfr_quirk:1;  /* allow sub-frame alignment */
0160     unsigned int tx_length_quirk:1; /* add length specifier to transfers */
0161     unsigned int fmt_type;      /* USB audio format type (1-3) */
0162     unsigned int pkt_offset_adj;    /* Bytes to drop from beginning of packets (for non-compliant devices) */
0163     unsigned int stream_offset_adj; /* Bytes to drop from beginning of stream (for non-compliant devices) */
0164 
0165     unsigned int running: 1;    /* running status */
0166     unsigned int period_elapsed_pending;    /* delay period handling */
0167 
0168     unsigned int buffer_bytes;  /* buffer size in bytes */
0169     unsigned int inflight_bytes;    /* in-flight data bytes on buffer (for playback) */
0170     unsigned int hwptr_done;    /* processed byte position in the buffer */
0171     unsigned int transfer_done; /* processed frames since last period update */
0172     unsigned int frame_limit;   /* limits number of packets in URB */
0173 
0174     /* data and sync endpoints for this stream */
0175     unsigned int ep_num;        /* the endpoint number */
0176     struct snd_usb_endpoint *data_endpoint;
0177     struct snd_usb_endpoint *sync_endpoint;
0178     unsigned long flags;
0179     unsigned int speed;     /* USB_SPEED_XXX */
0180 
0181     u64 formats;            /* format bitmasks (all or'ed) */
0182     unsigned int num_formats;       /* number of supported audio formats (list) */
0183     struct list_head fmt_list;  /* format list */
0184     spinlock_t lock;
0185 
0186     unsigned int last_frame_number; /* stored frame number */
0187 
0188     struct {
0189         int marker;
0190         int channel;
0191         int byte_idx;
0192     } dsd_dop;
0193 
0194     bool trigger_tstamp_pending_update; /* trigger timestamp being updated from initial estimate */
0195     bool lowlatency_playback;   /* low-latency playback mode */
0196     struct media_ctl *media_ctl;
0197 };
0198 
0199 struct snd_usb_stream {
0200     struct snd_usb_audio *chip;
0201     struct snd_pcm *pcm;
0202     int pcm_index;
0203     unsigned int fmt_type;      /* USB audio format type (1-3) */
0204     struct snd_usb_substream substream[2];
0205     struct list_head list;
0206 };
0207 
0208 #endif /* __USBAUDIO_CARD_H */