card.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef __USBAUDIO_CARD_H
  2. #define __USBAUDIO_CARD_H
  3. #define MAX_PACKS 20
  4. #define MAX_PACKS_HS (MAX_PACKS * 8) /* in high speed mode */
  5. #define MAX_URBS 8
  6. #define SYNC_URBS 4 /* always four urbs for sync */
  7. #define MAX_QUEUE 24 /* try not to exceed this queue length, in ms */
  8. struct audioformat {
  9. struct list_head list;
  10. u64 formats; /* ALSA format bits */
  11. unsigned int channels; /* # channels */
  12. unsigned int fmt_type; /* USB audio format type (1-3) */
  13. unsigned int frame_size; /* samples per frame for non-audio */
  14. int iface; /* interface number */
  15. unsigned char altsetting; /* corresponding alternate setting */
  16. unsigned char altset_idx; /* array index of altenate setting */
  17. unsigned char attributes; /* corresponding attributes of cs endpoint */
  18. unsigned char endpoint; /* endpoint */
  19. unsigned char ep_attr; /* endpoint attributes */
  20. unsigned char datainterval; /* log_2 of data packet interval */
  21. unsigned int maxpacksize; /* max. packet size */
  22. unsigned int rates; /* rate bitmasks */
  23. unsigned int rate_min, rate_max; /* min/max rates */
  24. unsigned int nr_rates; /* number of rate table entries */
  25. unsigned int *rate_table; /* rate table */
  26. unsigned char clock; /* associated clock */
  27. };
  28. struct snd_usb_substream;
  29. struct snd_urb_ctx {
  30. struct urb *urb;
  31. unsigned int buffer_size; /* size of data buffer, if data URB */
  32. struct snd_usb_substream *subs;
  33. int index; /* index for urb array */
  34. int packets; /* number of packets per urb */
  35. };
  36. struct snd_urb_ops {
  37. int (*prepare)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
  38. int (*retire)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
  39. int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
  40. int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
  41. };
  42. struct snd_usb_substream {
  43. struct snd_usb_stream *stream;
  44. struct usb_device *dev;
  45. struct snd_pcm_substream *pcm_substream;
  46. int direction; /* playback or capture */
  47. int interface; /* current interface */
  48. int endpoint; /* assigned endpoint */
  49. struct audioformat *cur_audiofmt; /* current audioformat pointer (for hw_params callback) */
  50. unsigned int cur_rate; /* current rate (for hw_params callback) */
  51. unsigned int period_bytes; /* current period bytes (for hw_params callback) */
  52. unsigned int altset_idx; /* USB data format: index of alternate setting */
  53. unsigned int datapipe; /* the data i/o pipe */
  54. unsigned int syncpipe; /* 1 - async out or adaptive in */
  55. unsigned int datainterval; /* log_2 of data packet interval */
  56. unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */
  57. unsigned int freqn; /* nominal sampling rate in fs/fps in Q16.16 format */
  58. unsigned int freqm; /* momentary sampling rate in fs/fps in Q16.16 format */
  59. int freqshift; /* how much to shift the feedback value to get Q16.16 */
  60. unsigned int freqmax; /* maximum sampling rate, used for buffer management */
  61. unsigned int phase; /* phase accumulator */
  62. unsigned int maxpacksize; /* max packet size in bytes */
  63. unsigned int maxframesize; /* max packet size in frames */
  64. unsigned int curpacksize; /* current packet size in bytes (for capture) */
  65. unsigned int curframesize; /* current packet size in frames (for capture) */
  66. unsigned int syncmaxsize; /* sync endpoint packet size */
  67. unsigned int fill_max: 1; /* fill max packet size always */
  68. unsigned int txfr_quirk:1; /* allow sub-frame alignment */
  69. unsigned int fmt_type; /* USB audio format type (1-3) */
  70. unsigned int running: 1; /* running status */
  71. unsigned int hwptr_done; /* processed byte position in the buffer */
  72. unsigned int transfer_done; /* processed frames since last period update */
  73. unsigned long active_mask; /* bitmask of active urbs */
  74. unsigned long unlink_mask; /* bitmask of unlinked urbs */
  75. unsigned int nurbs; /* # urbs */
  76. struct snd_urb_ctx dataurb[MAX_URBS]; /* data urb table */
  77. struct snd_urb_ctx syncurb[SYNC_URBS]; /* sync urb table */
  78. char *syncbuf; /* sync buffer for all sync URBs */
  79. dma_addr_t sync_dma; /* DMA address of syncbuf */
  80. u64 formats; /* format bitmasks (all or'ed) */
  81. unsigned int num_formats; /* number of supported audio formats (list) */
  82. struct list_head fmt_list; /* format list */
  83. struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
  84. spinlock_t lock;
  85. struct snd_urb_ops ops; /* callbacks (must be filled at init) */
  86. };
  87. struct snd_usb_stream {
  88. struct snd_usb_audio *chip;
  89. struct snd_pcm *pcm;
  90. int pcm_index;
  91. unsigned int fmt_type; /* USB audio format type (1-3) */
  92. struct snd_usb_substream substream[2];
  93. struct list_head list;
  94. };
  95. #endif /* __USBAUDIO_CARD_H */