pcm.h 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482
  1. #ifndef __SOUND_PCM_H
  2. #define __SOUND_PCM_H
  3. /*
  4. * Digital Audio (PCM) abstract layer
  5. * Copyright (c) by Jaroslav Kysela <[email protected]>
  6. * Abramo Bagnara <[email protected]>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. */
  24. #include <sound/asound.h>
  25. #include <sound/memalloc.h>
  26. #include <sound/minors.h>
  27. #include <linux/poll.h>
  28. #include <linux/mm.h>
  29. #include <linux/bitops.h>
  30. #include <linux/pm_qos.h>
  31. #define snd_pcm_substream_chip(substream) ((substream)->private_data)
  32. #define snd_pcm_chip(pcm) ((pcm)->private_data)
  33. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  34. #include <sound/pcm_oss.h>
  35. #endif
  36. /*
  37. * Hardware (lowlevel) section
  38. */
  39. struct snd_pcm_hardware {
  40. unsigned int info; /* SNDRV_PCM_INFO_* */
  41. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  42. unsigned int rates; /* SNDRV_PCM_RATE_* */
  43. unsigned int rate_min; /* min rate */
  44. unsigned int rate_max; /* max rate */
  45. unsigned int channels_min; /* min channels */
  46. unsigned int channels_max; /* max channels */
  47. size_t buffer_bytes_max; /* max buffer size */
  48. size_t period_bytes_min; /* min period size */
  49. size_t period_bytes_max; /* max period size */
  50. unsigned int periods_min; /* min # of periods */
  51. unsigned int periods_max; /* max # of periods */
  52. size_t fifo_size; /* fifo size in bytes */
  53. };
  54. struct snd_pcm_substream;
  55. struct snd_pcm_audio_tstamp_config; /* definitions further down */
  56. struct snd_pcm_audio_tstamp_report;
  57. struct snd_pcm_ops {
  58. int (*open)(struct snd_pcm_substream *substream);
  59. int (*close)(struct snd_pcm_substream *substream);
  60. int (*ioctl)(struct snd_pcm_substream * substream,
  61. unsigned int cmd, void *arg);
  62. int (*compat_ioctl)(struct snd_pcm_substream *substream,
  63. unsigned int cmd, void *arg);
  64. int (*hw_params)(struct snd_pcm_substream *substream,
  65. struct snd_pcm_hw_params *params);
  66. int (*hw_free)(struct snd_pcm_substream *substream);
  67. int (*prepare)(struct snd_pcm_substream *substream);
  68. int (*trigger)(struct snd_pcm_substream *substream, int cmd);
  69. snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream);
  70. int (*get_time_info)(struct snd_pcm_substream *substream,
  71. struct timespec *system_ts, struct timespec *audio_ts,
  72. struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
  73. struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
  74. int (*delay_blk)(struct snd_pcm_substream *substream);
  75. int (*wall_clock)(struct snd_pcm_substream *substream,
  76. struct timespec *audio_ts);
  77. int (*copy)(struct snd_pcm_substream *substream, int channel,
  78. snd_pcm_uframes_t pos,
  79. void __user *buf, snd_pcm_uframes_t count);
  80. int (*silence)(struct snd_pcm_substream *substream, int channel,
  81. snd_pcm_uframes_t pos, snd_pcm_uframes_t count);
  82. struct page *(*page)(struct snd_pcm_substream *substream,
  83. unsigned long offset);
  84. int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
  85. int (*ack)(struct snd_pcm_substream *substream);
  86. int (*restart)(struct snd_pcm_substream *substream);
  87. };
  88. /*
  89. *
  90. */
  91. #if defined(CONFIG_SND_DYNAMIC_MINORS)
  92. #define SNDRV_PCM_DEVICES (SNDRV_OS_MINORS-2)
  93. #else
  94. #define SNDRV_PCM_DEVICES 8
  95. #endif
  96. #define SNDRV_PCM_IOCTL1_RESET 0
  97. /* 1 is absent slot. */
  98. #define SNDRV_PCM_IOCTL1_CHANNEL_INFO 2
  99. #define SNDRV_PCM_IOCTL1_GSTATE 3
  100. #define SNDRV_PCM_IOCTL1_FIFO_SIZE 4
  101. #define SNDRV_PCM_TRIGGER_STOP 0
  102. #define SNDRV_PCM_TRIGGER_START 1
  103. #define SNDRV_PCM_TRIGGER_PAUSE_PUSH 3
  104. #define SNDRV_PCM_TRIGGER_PAUSE_RELEASE 4
  105. #define SNDRV_PCM_TRIGGER_SUSPEND 5
  106. #define SNDRV_PCM_TRIGGER_RESUME 6
  107. #define SNDRV_PCM_TRIGGER_DRAIN 7
  108. #define SNDRV_PCM_POS_XRUN ((snd_pcm_uframes_t)-1)
  109. #define SNDRV_DMA_MODE (0)
  110. #define SNDRV_NON_DMA_MODE (1 << 0)
  111. #define SNDRV_RENDER_STOPPED (1 << 1)
  112. #define SNDRV_RENDER_RUNNING (1 << 2)
  113. /* If you change this don't forget to change rates[] table in pcm_native.c */
  114. #define SNDRV_PCM_RATE_5512 (1<<0) /* 5512Hz */
  115. #define SNDRV_PCM_RATE_8000 (1<<1) /* 8000Hz */
  116. #define SNDRV_PCM_RATE_11025 (1<<2) /* 11025Hz */
  117. #define SNDRV_PCM_RATE_16000 (1<<3) /* 16000Hz */
  118. #define SNDRV_PCM_RATE_22050 (1<<4) /* 22050Hz */
  119. #define SNDRV_PCM_RATE_32000 (1<<5) /* 32000Hz */
  120. #define SNDRV_PCM_RATE_44100 (1<<6) /* 44100Hz */
  121. #define SNDRV_PCM_RATE_48000 (1<<7) /* 48000Hz */
  122. #define SNDRV_PCM_RATE_64000 (1<<8) /* 64000Hz */
  123. #define SNDRV_PCM_RATE_88200 (1<<9) /* 88200Hz */
  124. #define SNDRV_PCM_RATE_96000 (1<<10) /* 96000Hz */
  125. #define SNDRV_PCM_RATE_176400 (1<<11) /* 176400Hz */
  126. #define SNDRV_PCM_RATE_192000 (1<<12) /* 192000Hz */
  127. #define SNDRV_PCM_RATE_352800 (1<<13) /* 352800Hz */
  128. #define SNDRV_PCM_RATE_384000 (1<<14) /* 384000Hz */
  129. #define SNDRV_PCM_RATE_CONTINUOUS (1<<30) /* continuous range */
  130. #define SNDRV_PCM_RATE_KNOT (1<<31) /* supports more non-continuos rates */
  131. #define SNDRV_PCM_RATE_8000_44100 (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_11025|\
  132. SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_22050|\
  133. SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100)
  134. #define SNDRV_PCM_RATE_8000_48000 (SNDRV_PCM_RATE_8000_44100|SNDRV_PCM_RATE_48000)
  135. #define SNDRV_PCM_RATE_8000_96000 (SNDRV_PCM_RATE_8000_48000|SNDRV_PCM_RATE_64000|\
  136. SNDRV_PCM_RATE_88200|SNDRV_PCM_RATE_96000)
  137. #define SNDRV_PCM_RATE_8000_192000 (SNDRV_PCM_RATE_8000_96000|SNDRV_PCM_RATE_176400|\
  138. SNDRV_PCM_RATE_192000)
  139. #define SNDRV_PCM_RATE_8000_384000 (SNDRV_PCM_RATE_8000_192000|\
  140. SNDRV_PCM_RATE_352800|\
  141. SNDRV_PCM_RATE_384000)
  142. #define _SNDRV_PCM_FMTBIT(fmt) (1ULL << (__force int)SNDRV_PCM_FORMAT_##fmt)
  143. #define SNDRV_PCM_FMTBIT_S8 _SNDRV_PCM_FMTBIT(S8)
  144. #define SNDRV_PCM_FMTBIT_U8 _SNDRV_PCM_FMTBIT(U8)
  145. #define SNDRV_PCM_FMTBIT_S16_LE _SNDRV_PCM_FMTBIT(S16_LE)
  146. #define SNDRV_PCM_FMTBIT_S16_BE _SNDRV_PCM_FMTBIT(S16_BE)
  147. #define SNDRV_PCM_FMTBIT_U16_LE _SNDRV_PCM_FMTBIT(U16_LE)
  148. #define SNDRV_PCM_FMTBIT_U16_BE _SNDRV_PCM_FMTBIT(U16_BE)
  149. #define SNDRV_PCM_FMTBIT_S24_LE _SNDRV_PCM_FMTBIT(S24_LE)
  150. #define SNDRV_PCM_FMTBIT_S24_BE _SNDRV_PCM_FMTBIT(S24_BE)
  151. #define SNDRV_PCM_FMTBIT_U24_LE _SNDRV_PCM_FMTBIT(U24_LE)
  152. #define SNDRV_PCM_FMTBIT_U24_BE _SNDRV_PCM_FMTBIT(U24_BE)
  153. #define SNDRV_PCM_FMTBIT_S32_LE _SNDRV_PCM_FMTBIT(S32_LE)
  154. #define SNDRV_PCM_FMTBIT_S32_BE _SNDRV_PCM_FMTBIT(S32_BE)
  155. #define SNDRV_PCM_FMTBIT_U32_LE _SNDRV_PCM_FMTBIT(U32_LE)
  156. #define SNDRV_PCM_FMTBIT_U32_BE _SNDRV_PCM_FMTBIT(U32_BE)
  157. #define SNDRV_PCM_FMTBIT_FLOAT_LE _SNDRV_PCM_FMTBIT(FLOAT_LE)
  158. #define SNDRV_PCM_FMTBIT_FLOAT_BE _SNDRV_PCM_FMTBIT(FLOAT_BE)
  159. #define SNDRV_PCM_FMTBIT_FLOAT64_LE _SNDRV_PCM_FMTBIT(FLOAT64_LE)
  160. #define SNDRV_PCM_FMTBIT_FLOAT64_BE _SNDRV_PCM_FMTBIT(FLOAT64_BE)
  161. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE _SNDRV_PCM_FMTBIT(IEC958_SUBFRAME_LE)
  162. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE _SNDRV_PCM_FMTBIT(IEC958_SUBFRAME_BE)
  163. #define SNDRV_PCM_FMTBIT_MU_LAW _SNDRV_PCM_FMTBIT(MU_LAW)
  164. #define SNDRV_PCM_FMTBIT_A_LAW _SNDRV_PCM_FMTBIT(A_LAW)
  165. #define SNDRV_PCM_FMTBIT_IMA_ADPCM _SNDRV_PCM_FMTBIT(IMA_ADPCM)
  166. #define SNDRV_PCM_FMTBIT_MPEG _SNDRV_PCM_FMTBIT(MPEG)
  167. #define SNDRV_PCM_FMTBIT_GSM _SNDRV_PCM_FMTBIT(GSM)
  168. #define SNDRV_PCM_FMTBIT_SPECIAL _SNDRV_PCM_FMTBIT(SPECIAL)
  169. #define SNDRV_PCM_FMTBIT_S24_3LE _SNDRV_PCM_FMTBIT(S24_3LE)
  170. #define SNDRV_PCM_FMTBIT_U24_3LE _SNDRV_PCM_FMTBIT(U24_3LE)
  171. #define SNDRV_PCM_FMTBIT_S24_3BE _SNDRV_PCM_FMTBIT(S24_3BE)
  172. #define SNDRV_PCM_FMTBIT_U24_3BE _SNDRV_PCM_FMTBIT(U24_3BE)
  173. #define SNDRV_PCM_FMTBIT_S20_3LE _SNDRV_PCM_FMTBIT(S20_3LE)
  174. #define SNDRV_PCM_FMTBIT_U20_3LE _SNDRV_PCM_FMTBIT(U20_3LE)
  175. #define SNDRV_PCM_FMTBIT_S20_3BE _SNDRV_PCM_FMTBIT(S20_3BE)
  176. #define SNDRV_PCM_FMTBIT_U20_3BE _SNDRV_PCM_FMTBIT(U20_3BE)
  177. #define SNDRV_PCM_FMTBIT_S18_3LE _SNDRV_PCM_FMTBIT(S18_3LE)
  178. #define SNDRV_PCM_FMTBIT_U18_3LE _SNDRV_PCM_FMTBIT(U18_3LE)
  179. #define SNDRV_PCM_FMTBIT_S18_3BE _SNDRV_PCM_FMTBIT(S18_3BE)
  180. #define SNDRV_PCM_FMTBIT_U18_3BE _SNDRV_PCM_FMTBIT(U18_3BE)
  181. #define SNDRV_PCM_FMTBIT_G723_24 _SNDRV_PCM_FMTBIT(G723_24)
  182. #define SNDRV_PCM_FMTBIT_G723_24_1B _SNDRV_PCM_FMTBIT(G723_24_1B)
  183. #define SNDRV_PCM_FMTBIT_G723_40 _SNDRV_PCM_FMTBIT(G723_40)
  184. #define SNDRV_PCM_FMTBIT_G723_40_1B _SNDRV_PCM_FMTBIT(G723_40_1B)
  185. #define SNDRV_PCM_FMTBIT_DSD_U8 _SNDRV_PCM_FMTBIT(DSD_U8)
  186. #define SNDRV_PCM_FMTBIT_DSD_U16_LE _SNDRV_PCM_FMTBIT(DSD_U16_LE)
  187. #define SNDRV_PCM_FMTBIT_DSD_U32_LE _SNDRV_PCM_FMTBIT(DSD_U32_LE)
  188. #define SNDRV_PCM_FMTBIT_DSD_U16_BE _SNDRV_PCM_FMTBIT(DSD_U16_BE)
  189. #define SNDRV_PCM_FMTBIT_DSD_U32_BE _SNDRV_PCM_FMTBIT(DSD_U32_BE)
  190. #ifdef SNDRV_LITTLE_ENDIAN
  191. #define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_LE
  192. #define SNDRV_PCM_FMTBIT_U16 SNDRV_PCM_FMTBIT_U16_LE
  193. #define SNDRV_PCM_FMTBIT_S24 SNDRV_PCM_FMTBIT_S24_LE
  194. #define SNDRV_PCM_FMTBIT_U24 SNDRV_PCM_FMTBIT_U24_LE
  195. #define SNDRV_PCM_FMTBIT_S32 SNDRV_PCM_FMTBIT_S32_LE
  196. #define SNDRV_PCM_FMTBIT_U32 SNDRV_PCM_FMTBIT_U32_LE
  197. #define SNDRV_PCM_FMTBIT_FLOAT SNDRV_PCM_FMTBIT_FLOAT_LE
  198. #define SNDRV_PCM_FMTBIT_FLOAT64 SNDRV_PCM_FMTBIT_FLOAT64_LE
  199. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
  200. #endif
  201. #ifdef SNDRV_BIG_ENDIAN
  202. #define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_BE
  203. #define SNDRV_PCM_FMTBIT_U16 SNDRV_PCM_FMTBIT_U16_BE
  204. #define SNDRV_PCM_FMTBIT_S24 SNDRV_PCM_FMTBIT_S24_BE
  205. #define SNDRV_PCM_FMTBIT_U24 SNDRV_PCM_FMTBIT_U24_BE
  206. #define SNDRV_PCM_FMTBIT_S32 SNDRV_PCM_FMTBIT_S32_BE
  207. #define SNDRV_PCM_FMTBIT_U32 SNDRV_PCM_FMTBIT_U32_BE
  208. #define SNDRV_PCM_FMTBIT_FLOAT SNDRV_PCM_FMTBIT_FLOAT_BE
  209. #define SNDRV_PCM_FMTBIT_FLOAT64 SNDRV_PCM_FMTBIT_FLOAT64_BE
  210. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
  211. #endif
  212. struct snd_pcm_file {
  213. struct snd_pcm_substream *substream;
  214. int no_compat_mmap;
  215. };
  216. struct snd_pcm_hw_rule;
  217. typedef int (*snd_pcm_hw_rule_func_t)(struct snd_pcm_hw_params *params,
  218. struct snd_pcm_hw_rule *rule);
  219. struct snd_pcm_hw_rule {
  220. unsigned int cond;
  221. int var;
  222. int deps[4];
  223. snd_pcm_hw_rule_func_t func;
  224. void *private;
  225. };
  226. struct snd_pcm_hw_constraints {
  227. struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK -
  228. SNDRV_PCM_HW_PARAM_FIRST_MASK + 1];
  229. struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL -
  230. SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1];
  231. unsigned int rules_num;
  232. unsigned int rules_all;
  233. struct snd_pcm_hw_rule *rules;
  234. };
  235. static inline struct snd_mask *constrs_mask(struct snd_pcm_hw_constraints *constrs,
  236. snd_pcm_hw_param_t var)
  237. {
  238. return &constrs->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  239. }
  240. static inline struct snd_interval *constrs_interval(struct snd_pcm_hw_constraints *constrs,
  241. snd_pcm_hw_param_t var)
  242. {
  243. return &constrs->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  244. }
  245. struct snd_ratnum {
  246. unsigned int num;
  247. unsigned int den_min, den_max, den_step;
  248. };
  249. struct snd_ratden {
  250. unsigned int num_min, num_max, num_step;
  251. unsigned int den;
  252. };
  253. struct snd_pcm_hw_constraint_ratnums {
  254. int nrats;
  255. const struct snd_ratnum *rats;
  256. };
  257. struct snd_pcm_hw_constraint_ratdens {
  258. int nrats;
  259. const struct snd_ratden *rats;
  260. };
  261. struct snd_pcm_hw_constraint_list {
  262. const unsigned int *list;
  263. unsigned int count;
  264. unsigned int mask;
  265. };
  266. struct snd_pcm_hw_constraint_ranges {
  267. unsigned int count;
  268. const struct snd_interval *ranges;
  269. unsigned int mask;
  270. };
  271. /*
  272. * userspace-provided audio timestamp config to kernel,
  273. * structure is for internal use only and filled with dedicated unpack routine
  274. */
  275. struct snd_pcm_audio_tstamp_config {
  276. /* 5 of max 16 bits used */
  277. u32 type_requested:4;
  278. u32 report_delay:1; /* add total delay to A/D or D/A */
  279. };
  280. static inline void snd_pcm_unpack_audio_tstamp_config(__u32 data,
  281. struct snd_pcm_audio_tstamp_config *config)
  282. {
  283. config->type_requested = data & 0xF;
  284. config->report_delay = (data >> 4) & 1;
  285. }
  286. /*
  287. * kernel-provided audio timestamp report to user-space
  288. * structure is for internal use only and read by dedicated pack routine
  289. */
  290. struct snd_pcm_audio_tstamp_report {
  291. /* 6 of max 16 bits used for bit-fields */
  292. /* for backwards compatibility */
  293. u32 valid:1;
  294. /* actual type if hardware could not support requested timestamp */
  295. u32 actual_type:4;
  296. /* accuracy represented in ns units */
  297. u32 accuracy_report:1; /* 0 if accuracy unknown, 1 if accuracy field is valid */
  298. u32 accuracy; /* up to 4.29s, will be packed in separate field */
  299. };
  300. static inline void snd_pcm_pack_audio_tstamp_report(__u32 *data, __u32 *accuracy,
  301. const struct snd_pcm_audio_tstamp_report *report)
  302. {
  303. u32 tmp;
  304. tmp = report->accuracy_report;
  305. tmp <<= 4;
  306. tmp |= report->actual_type;
  307. tmp <<= 1;
  308. tmp |= report->valid;
  309. *data &= 0xffff; /* zero-clear MSBs */
  310. *data |= (tmp << 16);
  311. *accuracy = report->accuracy;
  312. }
  313. struct snd_pcm_runtime {
  314. /* -- Status -- */
  315. struct snd_pcm_substream *trigger_master;
  316. struct timespec trigger_tstamp; /* trigger timestamp */
  317. bool trigger_tstamp_latched; /* trigger timestamp latched in low-level driver/hardware */
  318. int overrange;
  319. snd_pcm_uframes_t avail_max;
  320. snd_pcm_uframes_t hw_ptr_base; /* Position at buffer restart */
  321. snd_pcm_uframes_t hw_ptr_interrupt; /* Position at interrupt time */
  322. unsigned long hw_ptr_jiffies; /* Time when hw_ptr is updated */
  323. unsigned long hw_ptr_buffer_jiffies; /* buffer time in jiffies */
  324. snd_pcm_sframes_t delay; /* extra delay; typically FIFO size */
  325. u64 hw_ptr_wrap; /* offset for hw_ptr due to boundary wrap-around */
  326. /* -- HW params -- */
  327. snd_pcm_access_t access; /* access mode */
  328. snd_pcm_format_t format; /* SNDRV_PCM_FORMAT_* */
  329. snd_pcm_subformat_t subformat; /* subformat */
  330. unsigned int rate; /* rate in Hz */
  331. unsigned int channels; /* channels */
  332. snd_pcm_uframes_t period_size; /* period size */
  333. unsigned int periods; /* periods */
  334. snd_pcm_uframes_t buffer_size; /* buffer size */
  335. snd_pcm_uframes_t min_align; /* Min alignment for the format */
  336. size_t byte_align;
  337. unsigned int frame_bits;
  338. unsigned int sample_bits;
  339. unsigned int info;
  340. unsigned int rate_num;
  341. unsigned int rate_den;
  342. unsigned int no_period_wakeup: 1;
  343. unsigned int render_flag;
  344. /* -- SW params -- */
  345. int tstamp_mode; /* mmap timestamp is updated */
  346. unsigned int period_step;
  347. snd_pcm_uframes_t start_threshold;
  348. snd_pcm_uframes_t stop_threshold;
  349. snd_pcm_uframes_t silence_threshold; /* Silence filling happens when
  350. noise is nearest than this */
  351. snd_pcm_uframes_t silence_size; /* Silence filling size */
  352. snd_pcm_uframes_t boundary; /* pointers wrap point */
  353. snd_pcm_uframes_t silence_start; /* starting pointer to silence area */
  354. snd_pcm_uframes_t silence_filled; /* size filled with silence */
  355. union snd_pcm_sync_id sync; /* hardware synchronization ID */
  356. /* -- mmap -- */
  357. struct snd_pcm_mmap_status *status;
  358. struct snd_pcm_mmap_control *control;
  359. /* -- locking / scheduling -- */
  360. snd_pcm_uframes_t twake; /* do transfer (!poll) wakeup if non-zero */
  361. wait_queue_head_t sleep; /* poll sleep */
  362. wait_queue_head_t tsleep; /* transfer sleep */
  363. struct fasync_struct *fasync;
  364. /* -- private section -- */
  365. void *private_data;
  366. void (*private_free)(struct snd_pcm_runtime *runtime);
  367. /* -- hardware description -- */
  368. struct snd_pcm_hardware hw;
  369. struct snd_pcm_hw_constraints hw_constraints;
  370. /* -- timer -- */
  371. unsigned int timer_resolution; /* timer resolution */
  372. int tstamp_type; /* timestamp type */
  373. /* -- DMA -- */
  374. unsigned char *dma_area; /* DMA area */
  375. dma_addr_t dma_addr; /* physical bus address (not accessible from main CPU) */
  376. size_t dma_bytes; /* size of DMA area */
  377. struct snd_dma_buffer *dma_buffer_p; /* allocated buffer */
  378. /* -- audio timestamp config -- */
  379. struct snd_pcm_audio_tstamp_config audio_tstamp_config;
  380. struct snd_pcm_audio_tstamp_report audio_tstamp_report;
  381. struct timespec driver_tstamp;
  382. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  383. /* -- OSS things -- */
  384. struct snd_pcm_oss_runtime oss;
  385. #endif
  386. };
  387. struct snd_pcm_group { /* keep linked substreams */
  388. spinlock_t lock;
  389. struct mutex mutex;
  390. struct list_head substreams;
  391. int count;
  392. };
  393. struct pid;
  394. struct snd_pcm_substream {
  395. struct snd_pcm *pcm;
  396. struct snd_pcm_str *pstr;
  397. void *private_data; /* copied from pcm->private_data */
  398. int number;
  399. char name[32]; /* substream name */
  400. int stream; /* stream (direction) */
  401. struct pm_qos_request latency_pm_qos_req; /* pm_qos request */
  402. size_t buffer_bytes_max; /* limit ring buffer size */
  403. struct snd_dma_buffer dma_buffer;
  404. size_t dma_max;
  405. /* -- hardware operations -- */
  406. const struct snd_pcm_ops *ops;
  407. /* -- runtime information -- */
  408. struct snd_pcm_runtime *runtime;
  409. spinlock_t runtime_lock;
  410. /* -- timer section -- */
  411. struct snd_timer *timer; /* timer */
  412. unsigned timer_running: 1; /* time is running */
  413. /* -- next substream -- */
  414. struct snd_pcm_substream *next;
  415. /* -- linked substreams -- */
  416. struct list_head link_list; /* linked list member */
  417. struct snd_pcm_group self_group; /* fake group for non linked substream (with substream lock inside) */
  418. struct snd_pcm_group *group; /* pointer to current group */
  419. /* -- assigned files -- */
  420. void *file;
  421. int ref_count;
  422. atomic_t mmap_count;
  423. unsigned int f_flags;
  424. void (*pcm_release)(struct snd_pcm_substream *);
  425. struct pid *pid;
  426. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  427. /* -- OSS things -- */
  428. struct snd_pcm_oss_substream oss;
  429. #endif
  430. #ifdef CONFIG_SND_VERBOSE_PROCFS
  431. struct snd_info_entry *proc_root;
  432. struct snd_info_entry *proc_info_entry;
  433. struct snd_info_entry *proc_hw_params_entry;
  434. struct snd_info_entry *proc_sw_params_entry;
  435. struct snd_info_entry *proc_status_entry;
  436. struct snd_info_entry *proc_prealloc_entry;
  437. struct snd_info_entry *proc_prealloc_max_entry;
  438. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  439. struct snd_info_entry *proc_xrun_injection_entry;
  440. #endif
  441. #endif /* CONFIG_SND_VERBOSE_PROCFS */
  442. /* misc flags */
  443. unsigned int hw_opened: 1;
  444. unsigned int hw_no_buffer: 1; /* substream may not have a buffer */
  445. };
  446. #define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
  447. struct snd_pcm_str {
  448. int stream; /* stream (direction) */
  449. struct snd_pcm *pcm;
  450. /* -- substreams -- */
  451. unsigned int substream_count;
  452. unsigned int substream_opened;
  453. struct snd_pcm_substream *substream;
  454. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  455. /* -- OSS things -- */
  456. struct snd_pcm_oss_stream oss;
  457. #endif
  458. #ifdef CONFIG_SND_VERBOSE_PROCFS
  459. struct snd_info_entry *proc_root;
  460. struct snd_info_entry *proc_info_entry;
  461. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  462. unsigned int xrun_debug; /* 0 = disabled, 1 = verbose, 2 = stacktrace */
  463. struct snd_info_entry *proc_xrun_debug_entry;
  464. #endif
  465. #endif
  466. struct snd_kcontrol *chmap_kctl; /* channel-mapping controls */
  467. struct snd_kcontrol *vol_kctl; /* volume controls */
  468. struct snd_kcontrol *usr_kctl; /* user controls */
  469. struct device dev;
  470. };
  471. struct snd_pcm {
  472. struct snd_card *card;
  473. struct list_head list;
  474. int device; /* device number */
  475. unsigned int info_flags;
  476. unsigned short dev_class;
  477. unsigned short dev_subclass;
  478. char id[64];
  479. char name[80];
  480. struct snd_pcm_str streams[2];
  481. struct mutex open_mutex;
  482. wait_queue_head_t open_wait;
  483. void *private_data;
  484. void (*private_free) (struct snd_pcm *pcm);
  485. bool internal; /* pcm is for internal use only */
  486. bool nonatomic; /* whole PCM operations are in non-atomic context */
  487. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  488. struct snd_pcm_oss oss;
  489. #endif
  490. };
  491. struct snd_pcm_notify {
  492. int (*n_register) (struct snd_pcm * pcm);
  493. int (*n_disconnect) (struct snd_pcm * pcm);
  494. int (*n_unregister) (struct snd_pcm * pcm);
  495. struct list_head list;
  496. };
  497. /*
  498. * Registering
  499. */
  500. extern const struct file_operations snd_pcm_f_ops[2];
  501. int snd_pcm_new(struct snd_card *card, const char *id, int device,
  502. int playback_count, int capture_count,
  503. struct snd_pcm **rpcm);
  504. int snd_pcm_new_internal(struct snd_card *card, const char *id, int device,
  505. int playback_count, int capture_count,
  506. struct snd_pcm **rpcm);
  507. int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count);
  508. int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree);
  509. /*
  510. * Native I/O
  511. */
  512. int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info);
  513. int snd_pcm_info_user(struct snd_pcm_substream *substream,
  514. struct snd_pcm_info __user *info);
  515. int snd_pcm_status(struct snd_pcm_substream *substream,
  516. struct snd_pcm_status *status);
  517. int snd_pcm_start(struct snd_pcm_substream *substream);
  518. int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t status);
  519. int snd_pcm_drain_done(struct snd_pcm_substream *substream);
  520. int snd_pcm_stop_xrun(struct snd_pcm_substream *substream);
  521. #ifdef CONFIG_PM
  522. int snd_pcm_suspend(struct snd_pcm_substream *substream);
  523. int snd_pcm_suspend_all(struct snd_pcm *pcm);
  524. #endif
  525. int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
  526. int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file,
  527. struct snd_pcm_substream **rsubstream);
  528. void snd_pcm_release_substream(struct snd_pcm_substream *substream);
  529. int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, struct file *file,
  530. struct snd_pcm_substream **rsubstream);
  531. void snd_pcm_detach_substream(struct snd_pcm_substream *substream);
  532. int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area);
  533. #ifdef CONFIG_SND_DEBUG
  534. void snd_pcm_debug_name(struct snd_pcm_substream *substream,
  535. char *name, size_t len);
  536. #else
  537. static inline void
  538. snd_pcm_debug_name(struct snd_pcm_substream *substream, char *buf, size_t size)
  539. {
  540. *buf = 0;
  541. }
  542. #endif
  543. /*
  544. * PCM library
  545. */
  546. /**
  547. * snd_pcm_stream_linked - Check whether the substream is linked with others
  548. * @substream: substream to check
  549. *
  550. * Returns true if the given substream is being linked with others.
  551. */
  552. static inline int snd_pcm_stream_linked(struct snd_pcm_substream *substream)
  553. {
  554. return substream->group != &substream->self_group;
  555. }
  556. void snd_pcm_stream_lock(struct snd_pcm_substream *substream);
  557. void snd_pcm_stream_unlock(struct snd_pcm_substream *substream);
  558. void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream);
  559. void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream);
  560. unsigned long _snd_pcm_stream_lock_irqsave(struct snd_pcm_substream *substream);
  561. /**
  562. * snd_pcm_stream_lock_irqsave - Lock the PCM stream
  563. * @substream: PCM substream
  564. * @flags: irq flags
  565. *
  566. * This locks the PCM stream like snd_pcm_stream_lock() but with the local
  567. * IRQ (only when nonatomic is false). In nonatomic case, this is identical
  568. * as snd_pcm_stream_lock().
  569. */
  570. #define snd_pcm_stream_lock_irqsave(substream, flags) \
  571. do { \
  572. typecheck(unsigned long, flags); \
  573. flags = _snd_pcm_stream_lock_irqsave(substream); \
  574. } while (0)
  575. void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream,
  576. unsigned long flags);
  577. /**
  578. * snd_pcm_group_for_each_entry - iterate over the linked substreams
  579. * @s: the iterator
  580. * @substream: the substream
  581. *
  582. * Iterate over the all linked substreams to the given @substream.
  583. * When @substream isn't linked with any others, this gives returns @substream
  584. * itself once.
  585. */
  586. #define snd_pcm_group_for_each_entry(s, substream) \
  587. list_for_each_entry(s, &substream->group->substreams, link_list)
  588. /**
  589. * snd_pcm_running - Check whether the substream is in a running state
  590. * @substream: substream to check
  591. *
  592. * Returns true if the given substream is in the state RUNNING, or in the
  593. * state DRAINING for playback.
  594. */
  595. static inline int snd_pcm_running(struct snd_pcm_substream *substream)
  596. {
  597. return (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING ||
  598. (substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
  599. substream->stream == SNDRV_PCM_STREAM_PLAYBACK));
  600. }
  601. /**
  602. * bytes_to_samples - Unit conversion of the size from bytes to samples
  603. * @runtime: PCM runtime instance
  604. * @size: size in bytes
  605. */
  606. static inline ssize_t bytes_to_samples(struct snd_pcm_runtime *runtime, ssize_t size)
  607. {
  608. return size * 8 / runtime->sample_bits;
  609. }
  610. /**
  611. * bytes_to_frames - Unit conversion of the size from bytes to frames
  612. * @runtime: PCM runtime instance
  613. * @size: size in bytes
  614. */
  615. static inline snd_pcm_sframes_t bytes_to_frames(struct snd_pcm_runtime *runtime, ssize_t size)
  616. {
  617. return size * 8 / runtime->frame_bits;
  618. }
  619. /**
  620. * samples_to_bytes - Unit conversion of the size from samples to bytes
  621. * @runtime: PCM runtime instance
  622. * @size: size in samples
  623. */
  624. static inline ssize_t samples_to_bytes(struct snd_pcm_runtime *runtime, ssize_t size)
  625. {
  626. return size * runtime->sample_bits / 8;
  627. }
  628. /**
  629. * frames_to_bytes - Unit conversion of the size from frames to bytes
  630. * @runtime: PCM runtime instance
  631. * @size: size in frames
  632. */
  633. static inline ssize_t frames_to_bytes(struct snd_pcm_runtime *runtime, snd_pcm_sframes_t size)
  634. {
  635. return size * runtime->frame_bits / 8;
  636. }
  637. /**
  638. * frame_aligned - Check whether the byte size is aligned to frames
  639. * @runtime: PCM runtime instance
  640. * @bytes: size in bytes
  641. */
  642. static inline int frame_aligned(struct snd_pcm_runtime *runtime, ssize_t bytes)
  643. {
  644. return bytes % runtime->byte_align == 0;
  645. }
  646. /**
  647. * snd_pcm_lib_buffer_bytes - Get the buffer size of the current PCM in bytes
  648. * @substream: PCM substream
  649. */
  650. static inline size_t snd_pcm_lib_buffer_bytes(struct snd_pcm_substream *substream)
  651. {
  652. struct snd_pcm_runtime *runtime = substream->runtime;
  653. return frames_to_bytes(runtime, runtime->buffer_size);
  654. }
  655. /**
  656. * snd_pcm_lib_period_bytes - Get the period size of the current PCM in bytes
  657. * @substream: PCM substream
  658. */
  659. static inline size_t snd_pcm_lib_period_bytes(struct snd_pcm_substream *substream)
  660. {
  661. struct snd_pcm_runtime *runtime = substream->runtime;
  662. return frames_to_bytes(runtime, runtime->period_size);
  663. }
  664. /**
  665. * snd_pcm_playback_avail - Get the available (writable) space for playback
  666. * @runtime: PCM runtime instance
  667. *
  668. * Result is between 0 ... (boundary - 1)
  669. */
  670. static inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *runtime)
  671. {
  672. snd_pcm_sframes_t avail = runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_ptr;
  673. if (avail < 0)
  674. avail += runtime->boundary;
  675. else if ((snd_pcm_uframes_t) avail >= runtime->boundary)
  676. avail -= runtime->boundary;
  677. return avail;
  678. }
  679. /**
  680. * snd_pcm_playback_avail - Get the available (readable) space for capture
  681. * @runtime: PCM runtime instance
  682. *
  683. * Result is between 0 ... (boundary - 1)
  684. */
  685. static inline snd_pcm_uframes_t snd_pcm_capture_avail(struct snd_pcm_runtime *runtime)
  686. {
  687. snd_pcm_sframes_t avail = runtime->status->hw_ptr - runtime->control->appl_ptr;
  688. if (avail < 0)
  689. avail += runtime->boundary;
  690. return avail;
  691. }
  692. /**
  693. * snd_pcm_playback_hw_avail - Get the queued space for playback
  694. * @runtime: PCM runtime instance
  695. */
  696. static inline snd_pcm_sframes_t snd_pcm_playback_hw_avail(struct snd_pcm_runtime *runtime)
  697. {
  698. return runtime->buffer_size - snd_pcm_playback_avail(runtime);
  699. }
  700. /**
  701. * snd_pcm_capture_hw_avail - Get the free space for capture
  702. * @runtime: PCM runtime instance
  703. */
  704. static inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(struct snd_pcm_runtime *runtime)
  705. {
  706. return runtime->buffer_size - snd_pcm_capture_avail(runtime);
  707. }
  708. /**
  709. * snd_pcm_playback_ready - check whether the playback buffer is available
  710. * @substream: the pcm substream instance
  711. *
  712. * Checks whether enough free space is available on the playback buffer.
  713. *
  714. * Return: Non-zero if available, or zero if not.
  715. */
  716. static inline int snd_pcm_playback_ready(struct snd_pcm_substream *substream)
  717. {
  718. struct snd_pcm_runtime *runtime = substream->runtime;
  719. return snd_pcm_playback_avail(runtime) >= runtime->control->avail_min;
  720. }
  721. /**
  722. * snd_pcm_capture_ready - check whether the capture buffer is available
  723. * @substream: the pcm substream instance
  724. *
  725. * Checks whether enough capture data is available on the capture buffer.
  726. *
  727. * Return: Non-zero if available, or zero if not.
  728. */
  729. static inline int snd_pcm_capture_ready(struct snd_pcm_substream *substream)
  730. {
  731. struct snd_pcm_runtime *runtime = substream->runtime;
  732. return snd_pcm_capture_avail(runtime) >= runtime->control->avail_min;
  733. }
  734. /**
  735. * snd_pcm_playback_data - check whether any data exists on the playback buffer
  736. * @substream: the pcm substream instance
  737. *
  738. * Checks whether any data exists on the playback buffer.
  739. *
  740. * Return: Non-zero if any data exists, or zero if not. If stop_threshold
  741. * is bigger or equal to boundary, then this function returns always non-zero.
  742. */
  743. static inline int snd_pcm_playback_data(struct snd_pcm_substream *substream)
  744. {
  745. struct snd_pcm_runtime *runtime = substream->runtime;
  746. if (runtime->stop_threshold >= runtime->boundary)
  747. return 1;
  748. return snd_pcm_playback_avail(runtime) < runtime->buffer_size;
  749. }
  750. /**
  751. * snd_pcm_playback_empty - check whether the playback buffer is empty
  752. * @substream: the pcm substream instance
  753. *
  754. * Checks whether the playback buffer is empty.
  755. *
  756. * Return: Non-zero if empty, or zero if not.
  757. */
  758. static inline int snd_pcm_playback_empty(struct snd_pcm_substream *substream)
  759. {
  760. struct snd_pcm_runtime *runtime = substream->runtime;
  761. return snd_pcm_playback_avail(runtime) >= runtime->buffer_size;
  762. }
  763. /**
  764. * snd_pcm_capture_empty - check whether the capture buffer is empty
  765. * @substream: the pcm substream instance
  766. *
  767. * Checks whether the capture buffer is empty.
  768. *
  769. * Return: Non-zero if empty, or zero if not.
  770. */
  771. static inline int snd_pcm_capture_empty(struct snd_pcm_substream *substream)
  772. {
  773. struct snd_pcm_runtime *runtime = substream->runtime;
  774. return snd_pcm_capture_avail(runtime) == 0;
  775. }
  776. /**
  777. * snd_pcm_trigger_done - Mark the master substream
  778. * @substream: the pcm substream instance
  779. * @master: the linked master substream
  780. *
  781. * When multiple substreams of the same card are linked and the hardware
  782. * supports the single-shot operation, the driver calls this in the loop
  783. * in snd_pcm_group_for_each_entry() for marking the substream as "done".
  784. * Then most of trigger operations are performed only to the given master
  785. * substream.
  786. *
  787. * The trigger_master mark is cleared at timestamp updates at the end
  788. * of trigger operations.
  789. */
  790. static inline void snd_pcm_trigger_done(struct snd_pcm_substream *substream,
  791. struct snd_pcm_substream *master)
  792. {
  793. substream->runtime->trigger_master = master;
  794. }
  795. static inline int hw_is_mask(int var)
  796. {
  797. return var >= SNDRV_PCM_HW_PARAM_FIRST_MASK &&
  798. var <= SNDRV_PCM_HW_PARAM_LAST_MASK;
  799. }
  800. static inline int hw_is_interval(int var)
  801. {
  802. return var >= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL &&
  803. var <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL;
  804. }
  805. static inline struct snd_mask *hw_param_mask(struct snd_pcm_hw_params *params,
  806. snd_pcm_hw_param_t var)
  807. {
  808. return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  809. }
  810. static inline struct snd_interval *hw_param_interval(struct snd_pcm_hw_params *params,
  811. snd_pcm_hw_param_t var)
  812. {
  813. return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  814. }
  815. static inline const struct snd_mask *hw_param_mask_c(const struct snd_pcm_hw_params *params,
  816. snd_pcm_hw_param_t var)
  817. {
  818. return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  819. }
  820. static inline const struct snd_interval *hw_param_interval_c(const struct snd_pcm_hw_params *params,
  821. snd_pcm_hw_param_t var)
  822. {
  823. return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  824. }
  825. /**
  826. * params_channels - Get the number of channels from the hw params
  827. * @p: hw params
  828. */
  829. static inline unsigned int params_channels(const struct snd_pcm_hw_params *p)
  830. {
  831. return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_CHANNELS)->min;
  832. }
  833. /**
  834. * params_rate - Get the sample rate from the hw params
  835. * @p: hw params
  836. */
  837. static inline unsigned int params_rate(const struct snd_pcm_hw_params *p)
  838. {
  839. return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_RATE)->min;
  840. }
  841. /**
  842. * params_period_size - Get the period size (in frames) from the hw params
  843. * @p: hw params
  844. */
  845. static inline unsigned int params_period_size(const struct snd_pcm_hw_params *p)
  846. {
  847. return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min;
  848. }
  849. /**
  850. * params_periods - Get the number of periods from the hw params
  851. * @p: hw params
  852. */
  853. static inline unsigned int params_periods(const struct snd_pcm_hw_params *p)
  854. {
  855. return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_PERIODS)->min;
  856. }
  857. /**
  858. * params_buffer_size - Get the buffer size (in frames) from the hw params
  859. * @p: hw params
  860. */
  861. static inline unsigned int params_buffer_size(const struct snd_pcm_hw_params *p)
  862. {
  863. return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min;
  864. }
  865. /**
  866. * params_buffer_bytes - Get the buffer size (in bytes) from the hw params
  867. * @p: hw params
  868. */
  869. static inline unsigned int params_buffer_bytes(const struct snd_pcm_hw_params *p)
  870. {
  871. return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min;
  872. }
  873. int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v);
  874. void snd_interval_mul(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c);
  875. void snd_interval_div(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c);
  876. void snd_interval_muldivk(const struct snd_interval *a, const struct snd_interval *b,
  877. unsigned int k, struct snd_interval *c);
  878. void snd_interval_mulkdiv(const struct snd_interval *a, unsigned int k,
  879. const struct snd_interval *b, struct snd_interval *c);
  880. int snd_interval_list(struct snd_interval *i, unsigned int count,
  881. const unsigned int *list, unsigned int mask);
  882. int snd_interval_ranges(struct snd_interval *i, unsigned int count,
  883. const struct snd_interval *list, unsigned int mask);
  884. int snd_interval_ratnum(struct snd_interval *i,
  885. unsigned int rats_count, const struct snd_ratnum *rats,
  886. unsigned int *nump, unsigned int *denp);
  887. void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params);
  888. void _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var);
  889. int snd_pcm_hw_params_choose(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
  890. int snd_pcm_hw_refine(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
  891. int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream);
  892. int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream);
  893. int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  894. u_int32_t mask);
  895. int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  896. u_int64_t mask);
  897. int snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  898. unsigned int min, unsigned int max);
  899. int snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var);
  900. int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime,
  901. unsigned int cond,
  902. snd_pcm_hw_param_t var,
  903. const struct snd_pcm_hw_constraint_list *l);
  904. int snd_pcm_hw_constraint_ranges(struct snd_pcm_runtime *runtime,
  905. unsigned int cond,
  906. snd_pcm_hw_param_t var,
  907. const struct snd_pcm_hw_constraint_ranges *r);
  908. int snd_pcm_hw_constraint_ratnums(struct snd_pcm_runtime *runtime,
  909. unsigned int cond,
  910. snd_pcm_hw_param_t var,
  911. const struct snd_pcm_hw_constraint_ratnums *r);
  912. int snd_pcm_hw_constraint_ratdens(struct snd_pcm_runtime *runtime,
  913. unsigned int cond,
  914. snd_pcm_hw_param_t var,
  915. const struct snd_pcm_hw_constraint_ratdens *r);
  916. int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime,
  917. unsigned int cond,
  918. unsigned int width,
  919. unsigned int msbits);
  920. int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
  921. unsigned int cond,
  922. snd_pcm_hw_param_t var,
  923. unsigned long step);
  924. int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
  925. unsigned int cond,
  926. snd_pcm_hw_param_t var);
  927. int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
  928. unsigned int base_rate);
  929. int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime,
  930. unsigned int cond,
  931. int var,
  932. snd_pcm_hw_rule_func_t func, void *private,
  933. int dep, ...);
  934. /**
  935. * snd_pcm_hw_constraint_single() - Constrain parameter to a single value
  936. * @runtime: PCM runtime instance
  937. * @var: The hw_params variable to constrain
  938. * @val: The value to constrain to
  939. *
  940. * Return: Positive if the value is changed, zero if it's not changed, or a
  941. * negative error code.
  942. */
  943. static inline int snd_pcm_hw_constraint_single(
  944. struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  945. unsigned int val)
  946. {
  947. return snd_pcm_hw_constraint_minmax(runtime, var, val, val);
  948. }
  949. int snd_pcm_format_signed(snd_pcm_format_t format);
  950. int snd_pcm_format_unsigned(snd_pcm_format_t format);
  951. int snd_pcm_format_linear(snd_pcm_format_t format);
  952. int snd_pcm_format_little_endian(snd_pcm_format_t format);
  953. int snd_pcm_format_big_endian(snd_pcm_format_t format);
  954. #if 0 /* just for DocBook */
  955. /**
  956. * snd_pcm_format_cpu_endian - Check the PCM format is CPU-endian
  957. * @format: the format to check
  958. *
  959. * Return: 1 if the given PCM format is CPU-endian, 0 if
  960. * opposite, or a negative error code if endian not specified.
  961. */
  962. int snd_pcm_format_cpu_endian(snd_pcm_format_t format);
  963. #endif /* DocBook */
  964. #ifdef SNDRV_LITTLE_ENDIAN
  965. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_little_endian(format)
  966. #else
  967. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_big_endian(format)
  968. #endif
  969. int snd_pcm_format_width(snd_pcm_format_t format); /* in bits */
  970. int snd_pcm_format_physical_width(snd_pcm_format_t format); /* in bits */
  971. ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
  972. const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format);
  973. int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
  974. void snd_pcm_set_ops(struct snd_pcm * pcm, int direction,
  975. const struct snd_pcm_ops *ops);
  976. void snd_pcm_set_sync(struct snd_pcm_substream *substream);
  977. int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  978. unsigned int cmd, void *arg);
  979. int snd_pcm_update_state(struct snd_pcm_substream *substream,
  980. struct snd_pcm_runtime *runtime);
  981. int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream);
  982. void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_uframes_t new_hw_ptr);
  983. void snd_pcm_period_elapsed(struct snd_pcm_substream *substream);
  984. snd_pcm_sframes_t snd_pcm_lib_write(struct snd_pcm_substream *substream,
  985. const void __user *buf,
  986. snd_pcm_uframes_t frames);
  987. snd_pcm_sframes_t snd_pcm_lib_read(struct snd_pcm_substream *substream,
  988. void __user *buf, snd_pcm_uframes_t frames);
  989. snd_pcm_sframes_t snd_pcm_lib_writev(struct snd_pcm_substream *substream,
  990. void __user **bufs, snd_pcm_uframes_t frames);
  991. snd_pcm_sframes_t snd_pcm_lib_readv(struct snd_pcm_substream *substream,
  992. void __user **bufs, snd_pcm_uframes_t frames);
  993. extern const struct snd_pcm_hw_constraint_list snd_pcm_known_rates;
  994. int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime);
  995. unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate);
  996. unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit);
  997. unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
  998. unsigned int rates_b);
  999. unsigned int snd_pcm_rate_range_to_bits(unsigned int rate_min,
  1000. unsigned int rate_max);
  1001. /**
  1002. * snd_pcm_set_runtime_buffer - Set the PCM runtime buffer
  1003. * @substream: PCM substream to set
  1004. * @bufp: the buffer information, NULL to clear
  1005. *
  1006. * Copy the buffer information to runtime->dma_buffer when @bufp is non-NULL.
  1007. * Otherwise it clears the current buffer information.
  1008. */
  1009. static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substream,
  1010. struct snd_dma_buffer *bufp)
  1011. {
  1012. struct snd_pcm_runtime *runtime = substream->runtime;
  1013. if (bufp) {
  1014. runtime->dma_buffer_p = bufp;
  1015. runtime->dma_area = bufp->area;
  1016. runtime->dma_addr = bufp->addr;
  1017. runtime->dma_bytes = bufp->bytes;
  1018. } else {
  1019. runtime->dma_buffer_p = NULL;
  1020. runtime->dma_area = NULL;
  1021. runtime->dma_addr = 0;
  1022. runtime->dma_bytes = 0;
  1023. }
  1024. }
  1025. /*
  1026. * Timer interface
  1027. */
  1028. #ifdef CONFIG_SND_PCM_TIMER
  1029. void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream);
  1030. void snd_pcm_timer_init(struct snd_pcm_substream *substream);
  1031. void snd_pcm_timer_done(struct snd_pcm_substream *substream);
  1032. #else
  1033. static inline void
  1034. snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream) {}
  1035. static inline void snd_pcm_timer_init(struct snd_pcm_substream *substream) {}
  1036. static inline void snd_pcm_timer_done(struct snd_pcm_substream *substream) {}
  1037. #endif
  1038. /**
  1039. * snd_pcm_gettime - Fill the timespec depending on the timestamp mode
  1040. * @runtime: PCM runtime instance
  1041. * @tv: timespec to fill
  1042. */
  1043. static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
  1044. struct timespec *tv)
  1045. {
  1046. switch (runtime->tstamp_type) {
  1047. case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC:
  1048. ktime_get_ts(tv);
  1049. break;
  1050. case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
  1051. getrawmonotonic(tv);
  1052. break;
  1053. default:
  1054. getnstimeofday(tv);
  1055. break;
  1056. }
  1057. }
  1058. /*
  1059. * Memory
  1060. */
  1061. int snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream);
  1062. int snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm);
  1063. int snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
  1064. int type, struct device *data,
  1065. size_t size, size_t max);
  1066. int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
  1067. int type, void *data,
  1068. size_t size, size_t max);
  1069. int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size);
  1070. int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream);
  1071. int _snd_pcm_lib_alloc_vmalloc_buffer(struct snd_pcm_substream *substream,
  1072. size_t size, gfp_t gfp_flags);
  1073. int snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream);
  1074. struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream,
  1075. unsigned long offset);
  1076. /**
  1077. * snd_pcm_lib_alloc_vmalloc_buffer - allocate virtual DMA buffer
  1078. * @substream: the substream to allocate the buffer to
  1079. * @size: the requested buffer size, in bytes
  1080. *
  1081. * Allocates the PCM substream buffer using vmalloc(), i.e., the memory is
  1082. * contiguous in kernel virtual space, but not in physical memory. Use this
  1083. * if the buffer is accessed by kernel code but not by device DMA.
  1084. *
  1085. * Return: 1 if the buffer was changed, 0 if not changed, or a negative error
  1086. * code.
  1087. */
  1088. static inline int snd_pcm_lib_alloc_vmalloc_buffer
  1089. (struct snd_pcm_substream *substream, size_t size)
  1090. {
  1091. return _snd_pcm_lib_alloc_vmalloc_buffer(substream, size,
  1092. GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
  1093. }
  1094. /**
  1095. * snd_pcm_lib_alloc_vmalloc_32_buffer - allocate 32-bit-addressable buffer
  1096. * @substream: the substream to allocate the buffer to
  1097. * @size: the requested buffer size, in bytes
  1098. *
  1099. * This function works like snd_pcm_lib_alloc_vmalloc_buffer(), but uses
  1100. * vmalloc_32(), i.e., the pages are allocated from 32-bit-addressable memory.
  1101. *
  1102. * Return: 1 if the buffer was changed, 0 if not changed, or a negative error
  1103. * code.
  1104. */
  1105. static inline int snd_pcm_lib_alloc_vmalloc_32_buffer
  1106. (struct snd_pcm_substream *substream, size_t size)
  1107. {
  1108. return _snd_pcm_lib_alloc_vmalloc_buffer(substream, size,
  1109. GFP_KERNEL | GFP_DMA32 | __GFP_ZERO);
  1110. }
  1111. #define snd_pcm_get_dma_buf(substream) ((substream)->runtime->dma_buffer_p)
  1112. #ifdef CONFIG_SND_DMA_SGBUF
  1113. /*
  1114. * SG-buffer handling
  1115. */
  1116. #define snd_pcm_substream_sgbuf(substream) \
  1117. snd_pcm_get_dma_buf(substream)->private_data
  1118. struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream,
  1119. unsigned long offset);
  1120. #else /* !SND_DMA_SGBUF */
  1121. /*
  1122. * fake using a continuous buffer
  1123. */
  1124. #define snd_pcm_sgbuf_ops_page NULL
  1125. #endif /* SND_DMA_SGBUF */
  1126. /**
  1127. * snd_pcm_sgbuf_get_addr - Get the DMA address at the corresponding offset
  1128. * @substream: PCM substream
  1129. * @ofs: byte offset
  1130. */
  1131. static inline dma_addr_t
  1132. snd_pcm_sgbuf_get_addr(struct snd_pcm_substream *substream, unsigned int ofs)
  1133. {
  1134. return snd_sgbuf_get_addr(snd_pcm_get_dma_buf(substream), ofs);
  1135. }
  1136. /**
  1137. * snd_pcm_sgbuf_get_ptr - Get the virtual address at the corresponding offset
  1138. * @substream: PCM substream
  1139. * @ofs: byte offset
  1140. */
  1141. static inline void *
  1142. snd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs)
  1143. {
  1144. return snd_sgbuf_get_ptr(snd_pcm_get_dma_buf(substream), ofs);
  1145. }
  1146. /**
  1147. * snd_pcm_sgbuf_chunk_size - Compute the max size that fits within the contig.
  1148. * page from the given size
  1149. * @substream: PCM substream
  1150. * @ofs: byte offset
  1151. * @size: byte size to examine
  1152. */
  1153. static inline unsigned int
  1154. snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream,
  1155. unsigned int ofs, unsigned int size)
  1156. {
  1157. return snd_sgbuf_get_chunk_size(snd_pcm_get_dma_buf(substream), ofs, size);
  1158. }
  1159. /**
  1160. * snd_pcm_mmap_data_open - increase the mmap counter
  1161. * @area: VMA
  1162. *
  1163. * PCM mmap callback should handle this counter properly
  1164. */
  1165. static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area)
  1166. {
  1167. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  1168. atomic_inc(&substream->mmap_count);
  1169. }
  1170. /**
  1171. * snd_pcm_mmap_data_close - decrease the mmap counter
  1172. * @area: VMA
  1173. *
  1174. * PCM mmap callback should handle this counter properly
  1175. */
  1176. static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area)
  1177. {
  1178. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  1179. atomic_dec(&substream->mmap_count);
  1180. }
  1181. int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
  1182. struct vm_area_struct *area);
  1183. /* mmap for io-memory area */
  1184. #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
  1185. #define SNDRV_PCM_INFO_MMAP_IOMEM SNDRV_PCM_INFO_MMAP
  1186. int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, struct vm_area_struct *area);
  1187. #else
  1188. #define SNDRV_PCM_INFO_MMAP_IOMEM 0
  1189. #define snd_pcm_lib_mmap_iomem NULL
  1190. #endif
  1191. #define snd_pcm_lib_mmap_vmalloc NULL
  1192. /**
  1193. * snd_pcm_limit_isa_dma_size - Get the max size fitting with ISA DMA transfer
  1194. * @dma: DMA number
  1195. * @max: pointer to store the max size
  1196. */
  1197. static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
  1198. {
  1199. *max = dma < 4 ? 64 * 1024 : 128 * 1024;
  1200. }
  1201. /*
  1202. * Misc
  1203. */
  1204. #define SNDRV_PCM_DEFAULT_CON_SPDIF (IEC958_AES0_CON_EMPHASIS_NONE|\
  1205. (IEC958_AES1_CON_ORIGINAL<<8)|\
  1206. (IEC958_AES1_CON_PCM_CODER<<8)|\
  1207. (IEC958_AES3_CON_FS_48000<<24))
  1208. #define PCM_RUNTIME_CHECK(sub) snd_BUG_ON(!(sub) || !(sub)->runtime)
  1209. const char *snd_pcm_format_name(snd_pcm_format_t format);
  1210. /**
  1211. * snd_pcm_stream_str - Get a string naming the direction of a stream
  1212. * @substream: the pcm substream instance
  1213. *
  1214. * Return: A string naming the direction of the stream.
  1215. */
  1216. static inline const char *snd_pcm_stream_str(struct snd_pcm_substream *substream)
  1217. {
  1218. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  1219. return "Playback";
  1220. else
  1221. return "Capture";
  1222. }
  1223. /*
  1224. * PCM channel-mapping control API
  1225. */
  1226. /* array element of channel maps */
  1227. struct snd_pcm_chmap_elem {
  1228. unsigned char channels;
  1229. unsigned char map[15];
  1230. };
  1231. /* channel map information; retrieved via snd_kcontrol_chip() */
  1232. struct snd_pcm_chmap {
  1233. struct snd_pcm *pcm; /* assigned PCM instance */
  1234. int stream; /* PLAYBACK or CAPTURE */
  1235. struct snd_kcontrol *kctl;
  1236. const struct snd_pcm_chmap_elem *chmap;
  1237. unsigned int max_channels;
  1238. unsigned int channel_mask; /* optional: active channels bitmask */
  1239. void *private_data; /* optional: private data pointer */
  1240. };
  1241. /**
  1242. * snd_pcm_chmap_substream - get the PCM substream assigned to the given chmap info
  1243. * @info: chmap information
  1244. * @idx: the substream number index
  1245. */
  1246. static inline struct snd_pcm_substream *
  1247. snd_pcm_chmap_substream(struct snd_pcm_chmap *info, unsigned int idx)
  1248. {
  1249. struct snd_pcm_substream *s;
  1250. for (s = info->pcm->streams[info->stream].substream; s; s = s->next)
  1251. if (s->number == idx)
  1252. return s;
  1253. return NULL;
  1254. }
  1255. /* ALSA-standard channel maps (RL/RR prior to C/LFE) */
  1256. extern const struct snd_pcm_chmap_elem snd_pcm_std_chmaps[];
  1257. /* Other world's standard channel maps (C/LFE prior to RL/RR) */
  1258. extern const struct snd_pcm_chmap_elem snd_pcm_alt_chmaps[];
  1259. /* bit masks to be passed to snd_pcm_chmap.channel_mask field */
  1260. #define SND_PCM_CHMAP_MASK_24 ((1U << 2) | (1U << 4))
  1261. #define SND_PCM_CHMAP_MASK_246 (SND_PCM_CHMAP_MASK_24 | (1U << 6))
  1262. #define SND_PCM_CHMAP_MASK_2468 (SND_PCM_CHMAP_MASK_246 | (1U << 8))
  1263. int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
  1264. const struct snd_pcm_chmap_elem *chmap,
  1265. int max_channels,
  1266. unsigned long private_value,
  1267. struct snd_pcm_chmap **info_ret);
  1268. /**
  1269. * pcm_format_to_bits - Strong-typed conversion of pcm_format to bitwise
  1270. * @pcm_format: PCM format
  1271. */
  1272. static inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format)
  1273. {
  1274. return 1ULL << (__force int) pcm_format;
  1275. }
  1276. /*
  1277. * PCM Volume control API
  1278. */
  1279. /* array element of volume */
  1280. struct snd_pcm_volume_elem {
  1281. int volume;
  1282. };
  1283. /* pp information; retrieved via snd_kcontrol_chip() */
  1284. struct snd_pcm_volume {
  1285. struct snd_pcm *pcm; /* assigned PCM instance */
  1286. int stream; /* PLAYBACK or CAPTURE */
  1287. struct snd_kcontrol *kctl;
  1288. const struct snd_pcm_volume_elem *volume;
  1289. int max_length;
  1290. void *private_data; /* optional: private data pointer */
  1291. };
  1292. int snd_pcm_add_volume_ctls(struct snd_pcm *pcm, int stream,
  1293. const struct snd_pcm_volume_elem *volume,
  1294. int max_length,
  1295. unsigned long private_value,
  1296. struct snd_pcm_volume **info_ret);
  1297. /*
  1298. * PCM User control API
  1299. */
  1300. /* array element of usr elem */
  1301. struct snd_pcm_usr_elem {
  1302. int val[128];
  1303. };
  1304. /* pp information; retrieved via snd_kcontrol_chip() */
  1305. struct snd_pcm_usr {
  1306. struct snd_pcm *pcm; /* assigned PCM instance */
  1307. int stream; /* PLAYBACK or CAPTURE */
  1308. struct snd_kcontrol *kctl;
  1309. const struct snd_pcm_usr_elem *usr;
  1310. int max_length;
  1311. void *private_data; /* optional: private data pointer */
  1312. };
  1313. int snd_pcm_add_usr_ctls(struct snd_pcm *pcm, int stream,
  1314. const struct snd_pcm_usr_elem *usr,
  1315. int max_length, int max_control_str_len,
  1316. unsigned long private_value,
  1317. struct snd_pcm_usr **info_ret);
  1318. /* printk helpers */
  1319. #define pcm_err(pcm, fmt, args...) \
  1320. dev_err((pcm)->card->dev, fmt, ##args)
  1321. #define pcm_warn(pcm, fmt, args...) \
  1322. dev_warn((pcm)->card->dev, fmt, ##args)
  1323. #define pcm_dbg(pcm, fmt, args...) \
  1324. dev_dbg((pcm)->card->dev, fmt, ##args)
  1325. #endif /* __SOUND_PCM_H */