soc.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * linux/sound/soc.h -- ALSA SoC Layer
  4. *
  5. * Author: Liam Girdwood
  6. * Created: Aug 11th 2005
  7. * Copyright: Wolfson Microelectronics. PLC.
  8. */
  9. #ifndef __LINUX_SND_SOC_H
  10. #define __LINUX_SND_SOC_H
  11. #include <linux/of.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/types.h>
  14. #include <linux/notifier.h>
  15. #include <linux/workqueue.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/kernel.h>
  18. #include <linux/regmap.h>
  19. #include <linux/log2.h>
  20. #include <linux/android_kabi.h>
  21. #include <sound/core.h>
  22. #include <sound/pcm.h>
  23. #include <sound/compress_driver.h>
  24. #include <sound/control.h>
  25. #include <sound/ac97_codec.h>
  26. /*
  27. * Convenience kcontrol builders
  28. */
  29. #define SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, xmax, xinvert, xautodisable) \
  30. ((unsigned long)&(struct soc_mixer_control) \
  31. {.reg = xreg, .rreg = xreg, .shift = shift_left, \
  32. .rshift = shift_right, .max = xmax, \
  33. .invert = xinvert, .autodisable = xautodisable})
  34. #define SOC_DOUBLE_S_VALUE(xreg, shift_left, shift_right, xmin, xmax, xsign_bit, xinvert, xautodisable) \
  35. ((unsigned long)&(struct soc_mixer_control) \
  36. {.reg = xreg, .rreg = xreg, .shift = shift_left, \
  37. .rshift = shift_right, .min = xmin, .max = xmax, \
  38. .sign_bit = xsign_bit, .invert = xinvert, .autodisable = xautodisable})
  39. #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, xautodisable) \
  40. SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert, xautodisable)
  41. #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
  42. ((unsigned long)&(struct soc_mixer_control) \
  43. {.reg = xreg, .max = xmax, .invert = xinvert})
  44. #define SOC_DOUBLE_R_VALUE(xlreg, xrreg, xshift, xmax, xinvert) \
  45. ((unsigned long)&(struct soc_mixer_control) \
  46. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  47. .max = xmax, .invert = xinvert})
  48. #define SOC_DOUBLE_R_S_VALUE(xlreg, xrreg, xshift, xmin, xmax, xsign_bit, xinvert) \
  49. ((unsigned long)&(struct soc_mixer_control) \
  50. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  51. .max = xmax, .min = xmin, .sign_bit = xsign_bit, \
  52. .invert = xinvert})
  53. #define SOC_DOUBLE_R_RANGE_VALUE(xlreg, xrreg, xshift, xmin, xmax, xinvert) \
  54. ((unsigned long)&(struct soc_mixer_control) \
  55. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  56. .min = xmin, .max = xmax, .invert = xinvert})
  57. #define SOC_SINGLE(xname, reg, shift, max, invert) \
  58. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  59. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  60. .put = snd_soc_put_volsw, \
  61. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  62. #define SOC_SINGLE_RANGE(xname, xreg, xshift, xmin, xmax, xinvert) \
  63. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  64. .info = snd_soc_info_volsw_range, .get = snd_soc_get_volsw_range, \
  65. .put = snd_soc_put_volsw_range, \
  66. .private_value = (unsigned long)&(struct soc_mixer_control) \
  67. {.reg = xreg, .rreg = xreg, .shift = xshift, \
  68. .rshift = xshift, .min = xmin, .max = xmax, \
  69. .invert = xinvert} }
  70. #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
  71. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  72. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  73. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  74. .tlv.p = (tlv_array), \
  75. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  76. .put = snd_soc_put_volsw, \
  77. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  78. #define SOC_SINGLE_SX_TLV(xname, xreg, xshift, xmin, xmax, tlv_array) \
  79. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  80. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  81. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  82. .tlv.p = (tlv_array),\
  83. .info = snd_soc_info_volsw_sx, \
  84. .get = snd_soc_get_volsw_sx,\
  85. .put = snd_soc_put_volsw_sx, \
  86. .private_value = (unsigned long)&(struct soc_mixer_control) \
  87. {.reg = xreg, .rreg = xreg, \
  88. .shift = xshift, .rshift = xshift, \
  89. .max = xmax, .min = xmin} }
  90. #define SOC_SINGLE_RANGE_TLV(xname, xreg, xshift, xmin, xmax, xinvert, tlv_array) \
  91. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  92. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  93. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  94. .tlv.p = (tlv_array), \
  95. .info = snd_soc_info_volsw_range, \
  96. .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
  97. .private_value = (unsigned long)&(struct soc_mixer_control) \
  98. {.reg = xreg, .rreg = xreg, .shift = xshift, \
  99. .rshift = xshift, .min = xmin, .max = xmax, \
  100. .invert = xinvert} }
  101. #define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
  102. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  103. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  104. .put = snd_soc_put_volsw, \
  105. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  106. max, invert, 0) }
  107. #define SOC_DOUBLE_STS(xname, reg, shift_left, shift_right, max, invert) \
  108. { \
  109. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  110. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  111. .access = SNDRV_CTL_ELEM_ACCESS_READ | \
  112. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  113. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  114. max, invert, 0) }
  115. #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
  116. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  117. .info = snd_soc_info_volsw, \
  118. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  119. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  120. xmax, xinvert) }
  121. #define SOC_DOUBLE_R_RANGE(xname, reg_left, reg_right, xshift, xmin, \
  122. xmax, xinvert) \
  123. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  124. .info = snd_soc_info_volsw_range, \
  125. .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
  126. .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \
  127. xshift, xmin, xmax, xinvert) }
  128. #define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
  129. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  130. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  131. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  132. .tlv.p = (tlv_array), \
  133. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  134. .put = snd_soc_put_volsw, \
  135. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  136. max, invert, 0) }
  137. #define SOC_DOUBLE_SX_TLV(xname, xreg, shift_left, shift_right, xmin, xmax, tlv_array) \
  138. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  139. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  140. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  141. .tlv.p = (tlv_array), \
  142. .info = snd_soc_info_volsw_sx, \
  143. .get = snd_soc_get_volsw_sx, \
  144. .put = snd_soc_put_volsw_sx, \
  145. .private_value = (unsigned long)&(struct soc_mixer_control) \
  146. {.reg = xreg, .rreg = xreg, \
  147. .shift = shift_left, .rshift = shift_right, \
  148. .max = xmax, .min = xmin} }
  149. #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
  150. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  151. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  152. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  153. .tlv.p = (tlv_array), \
  154. .info = snd_soc_info_volsw, \
  155. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  156. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  157. xmax, xinvert) }
  158. #define SOC_DOUBLE_R_RANGE_TLV(xname, reg_left, reg_right, xshift, xmin, \
  159. xmax, xinvert, tlv_array) \
  160. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  161. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  162. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  163. .tlv.p = (tlv_array), \
  164. .info = snd_soc_info_volsw_range, \
  165. .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
  166. .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \
  167. xshift, xmin, xmax, xinvert) }
  168. #define SOC_DOUBLE_R_SX_TLV(xname, xreg, xrreg, xshift, xmin, xmax, tlv_array) \
  169. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  170. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  171. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  172. .tlv.p = (tlv_array), \
  173. .info = snd_soc_info_volsw_sx, \
  174. .get = snd_soc_get_volsw_sx, \
  175. .put = snd_soc_put_volsw_sx, \
  176. .private_value = (unsigned long)&(struct soc_mixer_control) \
  177. {.reg = xreg, .rreg = xrreg, \
  178. .shift = xshift, .rshift = xshift, \
  179. .max = xmax, .min = xmin} }
  180. #define SOC_DOUBLE_R_S_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \
  181. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  182. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  183. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  184. .tlv.p = (tlv_array), \
  185. .info = snd_soc_info_volsw, \
  186. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  187. .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \
  188. xmin, xmax, xsign_bit, xinvert) }
  189. #define SOC_SINGLE_S_TLV(xname, xreg, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \
  190. SOC_DOUBLE_R_S_TLV(xname, xreg, xreg, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array)
  191. #define SOC_SINGLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  192. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  193. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  194. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  195. .tlv.p = (tlv_array), \
  196. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  197. .put = snd_soc_put_volsw, \
  198. .private_value = (unsigned long)&(struct soc_mixer_control) \
  199. {.reg = xreg, .rreg = xreg, \
  200. .min = xmin, .max = xmax, \
  201. .sign_bit = 7,} }
  202. #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  203. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  204. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  205. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  206. .tlv.p = (tlv_array), \
  207. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  208. .put = snd_soc_put_volsw, \
  209. .private_value = SOC_DOUBLE_S_VALUE(xreg, 0, 8, xmin, xmax, 7, 0, 0) }
  210. #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xitems, xtexts) \
  211. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  212. .items = xitems, .texts = xtexts, \
  213. .mask = xitems ? roundup_pow_of_two(xitems) - 1 : 0}
  214. #define SOC_ENUM_SINGLE(xreg, xshift, xitems, xtexts) \
  215. SOC_ENUM_DOUBLE(xreg, xshift, xshift, xitems, xtexts)
  216. #define SOC_ENUM_SINGLE_EXT(xitems, xtexts) \
  217. { .items = xitems, .texts = xtexts }
  218. #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xitems, xtexts, xvalues) \
  219. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  220. .mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues}
  221. #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
  222. SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xitems, xtexts, xvalues)
  223. #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
  224. { .reg = xreg, .shift_l = xshift, .shift_r = xshift, \
  225. .mask = xmask, .items = xitems, .texts = xtexts, \
  226. .values = xvalues, .autodisable = 1}
  227. #define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \
  228. SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts)
  229. #define SOC_ENUM(xname, xenum) \
  230. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  231. .info = snd_soc_info_enum_double, \
  232. .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
  233. .private_value = (unsigned long)&xenum }
  234. #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
  235. xhandler_get, xhandler_put) \
  236. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  237. .info = snd_soc_info_volsw, \
  238. .get = xhandler_get, .put = xhandler_put, \
  239. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) }
  240. #define SOC_DOUBLE_EXT(xname, reg, shift_left, shift_right, max, invert,\
  241. xhandler_get, xhandler_put) \
  242. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  243. .info = snd_soc_info_volsw, \
  244. .get = xhandler_get, .put = xhandler_put, \
  245. .private_value = \
  246. SOC_DOUBLE_VALUE(reg, shift_left, shift_right, max, invert, 0) }
  247. #define SOC_DOUBLE_R_EXT(xname, reg_left, reg_right, xshift, xmax, xinvert,\
  248. xhandler_get, xhandler_put) \
  249. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  250. .info = snd_soc_info_volsw, \
  251. .get = xhandler_get, .put = xhandler_put, \
  252. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  253. xmax, xinvert) }
  254. #define SOC_SINGLE_MULTI_EXT(xname, xreg, xshift, xmax, xinvert, xcount,\
  255. xhandler_get, xhandler_put) \
  256. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  257. .info = snd_soc_info_multi_ext, \
  258. .get = xhandler_get, .put = xhandler_put, \
  259. .private_value = (unsigned long)&(struct soc_multi_mixer_control) \
  260. {.reg = xreg, .shift = xshift, .rshift = xshift, .max = xmax, \
  261. .count = xcount, .platform_max = xmax, .invert = xinvert} }
  262. #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
  263. xhandler_get, xhandler_put, tlv_array) \
  264. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  265. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  266. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  267. .tlv.p = (tlv_array), \
  268. .info = snd_soc_info_volsw, \
  269. .get = xhandler_get, .put = xhandler_put, \
  270. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) }
  271. #define SOC_SINGLE_RANGE_EXT_TLV(xname, xreg, xshift, xmin, xmax, xinvert, \
  272. xhandler_get, xhandler_put, tlv_array) \
  273. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  274. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  275. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  276. .tlv.p = (tlv_array), \
  277. .info = snd_soc_info_volsw_range, \
  278. .get = xhandler_get, .put = xhandler_put, \
  279. .private_value = (unsigned long)&(struct soc_mixer_control) \
  280. {.reg = xreg, .rreg = xreg, .shift = xshift, \
  281. .rshift = xshift, .min = xmin, .max = xmax, \
  282. .invert = xinvert} }
  283. #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
  284. xhandler_get, xhandler_put, tlv_array) \
  285. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  286. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  287. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  288. .tlv.p = (tlv_array), \
  289. .info = snd_soc_info_volsw, \
  290. .get = xhandler_get, .put = xhandler_put, \
  291. .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
  292. xmax, xinvert, 0) }
  293. #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\
  294. xhandler_get, xhandler_put, tlv_array) \
  295. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  296. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  297. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  298. .tlv.p = (tlv_array), \
  299. .info = snd_soc_info_volsw, \
  300. .get = xhandler_get, .put = xhandler_put, \
  301. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  302. xmax, xinvert) }
  303. #define SOC_DOUBLE_R_S_EXT_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, \
  304. xsign_bit, xinvert, xhandler_get, xhandler_put, \
  305. tlv_array) \
  306. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  307. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  308. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  309. .tlv.p = (tlv_array), \
  310. .info = snd_soc_info_volsw, \
  311. .get = xhandler_get, .put = xhandler_put, \
  312. .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \
  313. xmin, xmax, xsign_bit, xinvert) }
  314. #define SOC_SINGLE_S_EXT_TLV(xname, xreg, xshift, xmin, xmax, \
  315. xsign_bit, xinvert, xhandler_get, xhandler_put, \
  316. tlv_array) \
  317. SOC_DOUBLE_R_S_EXT_TLV(xname, xreg, xreg, xshift, xmin, xmax, \
  318. xsign_bit, xinvert, xhandler_get, xhandler_put, \
  319. tlv_array)
  320. #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
  321. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  322. .info = snd_soc_info_bool_ext, \
  323. .get = xhandler_get, .put = xhandler_put, \
  324. .private_value = xdata }
  325. #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
  326. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  327. .info = snd_soc_info_enum_double, \
  328. .get = xhandler_get, .put = xhandler_put, \
  329. .private_value = (unsigned long)&xenum }
  330. #define SOC_VALUE_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
  331. SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put)
  332. #define SND_SOC_BYTES(xname, xbase, xregs) \
  333. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  334. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  335. .put = snd_soc_bytes_put, .private_value = \
  336. ((unsigned long)&(struct soc_bytes) \
  337. {.base = xbase, .num_regs = xregs }) }
  338. #define SND_SOC_BYTES_E(xname, xbase, xregs, xhandler_get, xhandler_put) \
  339. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  340. .info = snd_soc_bytes_info, .get = xhandler_get, \
  341. .put = xhandler_put, .private_value = \
  342. ((unsigned long)&(struct soc_bytes) \
  343. {.base = xbase, .num_regs = xregs }) }
  344. #define SND_SOC_BYTES_MASK(xname, xbase, xregs, xmask) \
  345. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  346. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  347. .put = snd_soc_bytes_put, .private_value = \
  348. ((unsigned long)&(struct soc_bytes) \
  349. {.base = xbase, .num_regs = xregs, \
  350. .mask = xmask }) }
  351. /*
  352. * SND_SOC_BYTES_EXT is deprecated, please USE SND_SOC_BYTES_TLV instead
  353. */
  354. #define SND_SOC_BYTES_EXT(xname, xcount, xhandler_get, xhandler_put) \
  355. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  356. .info = snd_soc_bytes_info_ext, \
  357. .get = xhandler_get, .put = xhandler_put, \
  358. .private_value = (unsigned long)&(struct soc_bytes_ext) \
  359. {.max = xcount} }
  360. #define SND_SOC_BYTES_TLV(xname, xcount, xhandler_get, xhandler_put) \
  361. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  362. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE | \
  363. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
  364. .tlv.c = (snd_soc_bytes_tlv_callback), \
  365. .info = snd_soc_bytes_info_ext, \
  366. .private_value = (unsigned long)&(struct soc_bytes_ext) \
  367. {.max = xcount, .get = xhandler_get, .put = xhandler_put, } }
  368. #define SOC_SINGLE_XR_SX(xname, xregbase, xregcount, xnbits, \
  369. xmin, xmax, xinvert) \
  370. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  371. .info = snd_soc_info_xr_sx, .get = snd_soc_get_xr_sx, \
  372. .put = snd_soc_put_xr_sx, \
  373. .private_value = (unsigned long)&(struct soc_mreg_control) \
  374. {.regbase = xregbase, .regcount = xregcount, .nbits = xnbits, \
  375. .invert = xinvert, .min = xmin, .max = xmax} }
  376. #define SOC_SINGLE_STROBE(xname, xreg, xshift, xinvert) \
  377. SOC_SINGLE_EXT(xname, xreg, xshift, 1, xinvert, \
  378. snd_soc_get_strobe, snd_soc_put_strobe)
  379. /*
  380. * Simplified versions of above macros, declaring a struct and calculating
  381. * ARRAY_SIZE internally
  382. */
  383. #define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \
  384. const struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
  385. ARRAY_SIZE(xtexts), xtexts)
  386. #define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \
  387. SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
  388. #define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \
  389. const struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts)
  390. #define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \
  391. const struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \
  392. ARRAY_SIZE(xtexts), xtexts, xvalues)
  393. #define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
  394. SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
  395. #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
  396. const struct soc_enum name = SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, \
  397. xshift, xmask, ARRAY_SIZE(xtexts), xtexts, xvalues)
  398. #define SOC_ENUM_SINGLE_VIRT_DECL(name, xtexts) \
  399. const struct soc_enum name = SOC_ENUM_SINGLE_VIRT(ARRAY_SIZE(xtexts), xtexts)
  400. struct device_node;
  401. struct snd_jack;
  402. struct snd_soc_card;
  403. struct snd_soc_pcm_stream;
  404. struct snd_soc_ops;
  405. struct snd_soc_pcm_runtime;
  406. struct snd_soc_dai;
  407. struct snd_soc_dai_driver;
  408. struct snd_soc_dai_link;
  409. struct snd_soc_component;
  410. struct snd_soc_component_driver;
  411. struct soc_enum;
  412. struct snd_soc_jack;
  413. struct snd_soc_jack_zone;
  414. struct snd_soc_jack_pin;
  415. #include <sound/soc-dapm.h>
  416. #include <sound/soc-dpcm.h>
  417. #include <sound/soc-topology.h>
  418. struct snd_soc_jack_gpio;
  419. enum snd_soc_pcm_subclass {
  420. SND_SOC_PCM_CLASS_PCM = 0,
  421. SND_SOC_PCM_CLASS_BE = 1,
  422. };
  423. int snd_soc_register_card(struct snd_soc_card *card);
  424. void snd_soc_unregister_card(struct snd_soc_card *card);
  425. int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
  426. #ifdef CONFIG_PM_SLEEP
  427. int snd_soc_suspend(struct device *dev);
  428. int snd_soc_resume(struct device *dev);
  429. #else
  430. static inline int snd_soc_suspend(struct device *dev)
  431. {
  432. return 0;
  433. }
  434. static inline int snd_soc_resume(struct device *dev)
  435. {
  436. return 0;
  437. }
  438. #endif
  439. int snd_soc_poweroff(struct device *dev);
  440. int snd_soc_component_initialize(struct snd_soc_component *component,
  441. const struct snd_soc_component_driver *driver,
  442. struct device *dev);
  443. int snd_soc_add_component(struct snd_soc_component *component,
  444. struct snd_soc_dai_driver *dai_drv,
  445. int num_dai);
  446. int snd_soc_register_component(struct device *dev,
  447. const struct snd_soc_component_driver *component_driver,
  448. struct snd_soc_dai_driver *dai_drv, int num_dai);
  449. int devm_snd_soc_register_component(struct device *dev,
  450. const struct snd_soc_component_driver *component_driver,
  451. struct snd_soc_dai_driver *dai_drv, int num_dai);
  452. void snd_soc_unregister_component(struct device *dev);
  453. void snd_soc_unregister_component_by_driver(struct device *dev,
  454. const struct snd_soc_component_driver *component_driver);
  455. struct snd_soc_component *snd_soc_lookup_component_nolocked(struct device *dev,
  456. const char *driver_name);
  457. struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
  458. const char *driver_name);
  459. int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
  460. #ifdef CONFIG_SND_SOC_COMPRESS
  461. int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num);
  462. #else
  463. static inline int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
  464. {
  465. return 0;
  466. }
  467. #endif
  468. void snd_soc_disconnect_sync(struct device *dev);
  469. struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
  470. struct snd_soc_dai_link *dai_link);
  471. bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd);
  472. void snd_soc_runtime_action(struct snd_soc_pcm_runtime *rtd,
  473. int stream, int action);
  474. static inline void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd,
  475. int stream)
  476. {
  477. snd_soc_runtime_action(rtd, stream, 1);
  478. }
  479. static inline void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd,
  480. int stream)
  481. {
  482. snd_soc_runtime_action(rtd, stream, -1);
  483. }
  484. int snd_soc_runtime_calc_hw(struct snd_soc_pcm_runtime *rtd,
  485. struct snd_pcm_hardware *hw, int stream);
  486. int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
  487. unsigned int dai_fmt);
  488. #ifdef CONFIG_DMI
  489. int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour);
  490. #else
  491. static inline int snd_soc_set_dmi_name(struct snd_soc_card *card,
  492. const char *flavour)
  493. {
  494. return 0;
  495. }
  496. #endif
  497. /* Utility functions to get clock rates from various things */
  498. int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
  499. int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
  500. int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
  501. int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);
  502. int snd_soc_tdm_params_to_bclk(struct snd_pcm_hw_params *params,
  503. int tdm_width, int tdm_slots, int slot_multiple);
  504. /* set runtime hw params */
  505. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  506. const struct snd_pcm_hardware *hw);
  507. struct snd_ac97 *snd_soc_alloc_ac97_component(struct snd_soc_component *component);
  508. struct snd_ac97 *snd_soc_new_ac97_component(struct snd_soc_component *component,
  509. unsigned int id, unsigned int id_mask);
  510. void snd_soc_free_ac97_component(struct snd_ac97 *ac97);
  511. #ifdef CONFIG_SND_SOC_AC97_BUS
  512. int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops);
  513. int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
  514. struct platform_device *pdev);
  515. extern struct snd_ac97_bus_ops *soc_ac97_ops;
  516. #else
  517. static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
  518. struct platform_device *pdev)
  519. {
  520. return 0;
  521. }
  522. static inline int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
  523. {
  524. return 0;
  525. }
  526. #endif
  527. /*
  528. *Controls
  529. */
  530. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  531. void *data, const char *long_name,
  532. const char *prefix);
  533. int snd_soc_add_component_controls(struct snd_soc_component *component,
  534. const struct snd_kcontrol_new *controls, unsigned int num_controls);
  535. int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
  536. const struct snd_kcontrol_new *controls, int num_controls);
  537. int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
  538. const struct snd_kcontrol_new *controls, int num_controls);
  539. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  540. struct snd_ctl_elem_info *uinfo);
  541. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  542. struct snd_ctl_elem_value *ucontrol);
  543. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  544. struct snd_ctl_elem_value *ucontrol);
  545. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  546. struct snd_ctl_elem_info *uinfo);
  547. int snd_soc_info_volsw_sx(struct snd_kcontrol *kcontrol,
  548. struct snd_ctl_elem_info *uinfo);
  549. #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
  550. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  551. struct snd_ctl_elem_value *ucontrol);
  552. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  553. struct snd_ctl_elem_value *ucontrol);
  554. #define snd_soc_get_volsw_2r snd_soc_get_volsw
  555. #define snd_soc_put_volsw_2r snd_soc_put_volsw
  556. int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
  557. struct snd_ctl_elem_value *ucontrol);
  558. int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
  559. struct snd_ctl_elem_value *ucontrol);
  560. int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
  561. struct snd_ctl_elem_info *uinfo);
  562. int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
  563. struct snd_ctl_elem_value *ucontrol);
  564. int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
  565. struct snd_ctl_elem_value *ucontrol);
  566. int snd_soc_limit_volume(struct snd_soc_card *card,
  567. const char *name, int max);
  568. int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
  569. struct snd_ctl_elem_info *uinfo);
  570. int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
  571. struct snd_ctl_elem_value *ucontrol);
  572. int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
  573. struct snd_ctl_elem_value *ucontrol);
  574. int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,
  575. struct snd_ctl_elem_info *ucontrol);
  576. int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag,
  577. unsigned int size, unsigned int __user *tlv);
  578. int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
  579. struct snd_ctl_elem_info *uinfo);
  580. int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
  581. struct snd_ctl_elem_value *ucontrol);
  582. int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
  583. struct snd_ctl_elem_value *ucontrol);
  584. int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
  585. struct snd_ctl_elem_value *ucontrol);
  586. int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
  587. struct snd_ctl_elem_value *ucontrol);
  588. int snd_soc_info_multi_ext(struct snd_kcontrol *kcontrol,
  589. struct snd_ctl_elem_info *uinfo);
  590. /* SoC PCM stream information */
  591. struct snd_soc_pcm_stream {
  592. const char *stream_name;
  593. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  594. unsigned int rates; /* SNDRV_PCM_RATE_* */
  595. unsigned int rate_min; /* min rate */
  596. unsigned int rate_max; /* max rate */
  597. unsigned int channels_min; /* min channels */
  598. unsigned int channels_max; /* max channels */
  599. unsigned int sig_bits; /* number of bits of content */
  600. };
  601. /* SoC audio ops */
  602. struct snd_soc_ops {
  603. int (*startup)(struct snd_pcm_substream *);
  604. void (*shutdown)(struct snd_pcm_substream *);
  605. int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
  606. int (*hw_free)(struct snd_pcm_substream *);
  607. int (*prepare)(struct snd_pcm_substream *);
  608. int (*trigger)(struct snd_pcm_substream *, int);
  609. };
  610. struct snd_soc_compr_ops {
  611. int (*startup)(struct snd_compr_stream *);
  612. void (*shutdown)(struct snd_compr_stream *);
  613. int (*set_params)(struct snd_compr_stream *);
  614. int (*trigger)(struct snd_compr_stream *);
  615. };
  616. struct snd_soc_component*
  617. snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
  618. const char *driver_name);
  619. struct snd_soc_dai_link_component {
  620. const char *name;
  621. struct device_node *of_node;
  622. const char *dai_name;
  623. };
  624. struct snd_soc_dai_link {
  625. /* config - must be set by machine driver */
  626. const char *name; /* Codec name */
  627. const char *stream_name; /* Stream name */
  628. /*
  629. * You MAY specify the link's CPU-side device, either by device name,
  630. * or by DT/OF node, but not both. If this information is omitted,
  631. * the CPU-side DAI is matched using .cpu_dai_name only, which hence
  632. * must be globally unique. These fields are currently typically used
  633. * only for codec to codec links, or systems using device tree.
  634. */
  635. /*
  636. * You MAY specify the DAI name of the CPU DAI. If this information is
  637. * omitted, the CPU-side DAI is matched using .cpu_name/.cpu_of_node
  638. * only, which only works well when that device exposes a single DAI.
  639. */
  640. struct snd_soc_dai_link_component *cpus;
  641. unsigned int num_cpus;
  642. /*
  643. * You MUST specify the link's codec, either by device name, or by
  644. * DT/OF node, but not both.
  645. */
  646. /* You MUST specify the DAI name within the codec */
  647. struct snd_soc_dai_link_component *codecs;
  648. unsigned int num_codecs;
  649. /*
  650. * You MAY specify the link's platform/PCM/DMA driver, either by
  651. * device name, or by DT/OF node, but not both. Some forms of link
  652. * do not need a platform. In such case, platforms are not mandatory.
  653. */
  654. struct snd_soc_dai_link_component *platforms;
  655. unsigned int num_platforms;
  656. int id; /* optional ID for machine driver link identification */
  657. const struct snd_soc_pcm_stream *params;
  658. unsigned int num_params;
  659. unsigned int dai_fmt; /* format to set on init */
  660. enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */
  661. /* codec/machine specific init - e.g. add machine controls */
  662. int (*init)(struct snd_soc_pcm_runtime *rtd);
  663. /* codec/machine specific exit - dual of init() */
  664. void (*exit)(struct snd_soc_pcm_runtime *rtd);
  665. /* optional hw_params re-writing for BE and FE sync */
  666. int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
  667. struct snd_pcm_hw_params *params);
  668. /* machine stream operations */
  669. const struct snd_soc_ops *ops;
  670. const struct snd_soc_compr_ops *compr_ops;
  671. /* Mark this pcm with non atomic ops */
  672. unsigned int nonatomic:1;
  673. /* For unidirectional dai links */
  674. unsigned int playback_only:1;
  675. unsigned int capture_only:1;
  676. /* Keep DAI active over suspend */
  677. unsigned int ignore_suspend:1;
  678. /* Symmetry requirements */
  679. unsigned int symmetric_rate:1;
  680. unsigned int symmetric_channels:1;
  681. unsigned int symmetric_sample_bits:1;
  682. /* Do not create a PCM for this DAI link (Backend link) */
  683. unsigned int no_pcm:1;
  684. /* This DAI link can route to other DAI links at runtime (Frontend)*/
  685. unsigned int dynamic:1;
  686. /* DPCM capture and Playback support */
  687. unsigned int dpcm_capture:1;
  688. unsigned int dpcm_playback:1;
  689. /* DPCM used FE & BE merged format */
  690. unsigned int dpcm_merged_format:1;
  691. /* DPCM used FE & BE merged channel */
  692. unsigned int dpcm_merged_chan:1;
  693. /* DPCM used FE & BE merged rate */
  694. unsigned int dpcm_merged_rate:1;
  695. /* pmdown_time is ignored at stop */
  696. unsigned int ignore_pmdown_time:1;
  697. /* Do not create a PCM for this DAI link (Backend link) */
  698. unsigned int ignore:1;
  699. /* This flag will reorder stop sequence. By enabling this flag
  700. * DMA controller stop sequence will be invoked first followed by
  701. * CPU DAI driver stop sequence
  702. */
  703. unsigned int stop_dma_first:1;
  704. #ifdef CONFIG_SND_SOC_TOPOLOGY
  705. struct snd_soc_dobj dobj; /* For topology */
  706. #endif
  707. ANDROID_KABI_RESERVE(1);
  708. };
  709. static inline struct snd_soc_dai_link_component*
  710. asoc_link_to_cpu(struct snd_soc_dai_link *link, int n) {
  711. return &(link)->cpus[n];
  712. }
  713. static inline struct snd_soc_dai_link_component*
  714. asoc_link_to_codec(struct snd_soc_dai_link *link, int n) {
  715. return &(link)->codecs[n];
  716. }
  717. static inline struct snd_soc_dai_link_component*
  718. asoc_link_to_platform(struct snd_soc_dai_link *link, int n) {
  719. return &(link)->platforms[n];
  720. }
  721. #define for_each_link_codecs(link, i, codec) \
  722. for ((i) = 0; \
  723. ((i) < link->num_codecs) && \
  724. ((codec) = asoc_link_to_codec(link, i)); \
  725. (i)++)
  726. #define for_each_link_platforms(link, i, platform) \
  727. for ((i) = 0; \
  728. ((i) < link->num_platforms) && \
  729. ((platform) = asoc_link_to_platform(link, i)); \
  730. (i)++)
  731. #define for_each_link_cpus(link, i, cpu) \
  732. for ((i) = 0; \
  733. ((i) < link->num_cpus) && \
  734. ((cpu) = asoc_link_to_cpu(link, i)); \
  735. (i)++)
  736. /*
  737. * Sample 1 : Single CPU/Codec/Platform
  738. *
  739. * SND_SOC_DAILINK_DEFS(test,
  740. * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai")),
  741. * DAILINK_COMP_ARRAY(COMP_CODEC("codec", "codec_dai")),
  742. * DAILINK_COMP_ARRAY(COMP_PLATFORM("platform")));
  743. *
  744. * struct snd_soc_dai_link link = {
  745. * ...
  746. * SND_SOC_DAILINK_REG(test),
  747. * };
  748. *
  749. * Sample 2 : Multi CPU/Codec, no Platform
  750. *
  751. * SND_SOC_DAILINK_DEFS(test,
  752. * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai1"),
  753. * COMP_CPU("cpu_dai2")),
  754. * DAILINK_COMP_ARRAY(COMP_CODEC("codec1", "codec_dai1"),
  755. * COMP_CODEC("codec2", "codec_dai2")));
  756. *
  757. * struct snd_soc_dai_link link = {
  758. * ...
  759. * SND_SOC_DAILINK_REG(test),
  760. * };
  761. *
  762. * Sample 3 : Define each CPU/Codec/Platform manually
  763. *
  764. * SND_SOC_DAILINK_DEF(test_cpu,
  765. * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai1"),
  766. * COMP_CPU("cpu_dai2")));
  767. * SND_SOC_DAILINK_DEF(test_codec,
  768. * DAILINK_COMP_ARRAY(COMP_CODEC("codec1", "codec_dai1"),
  769. * COMP_CODEC("codec2", "codec_dai2")));
  770. * SND_SOC_DAILINK_DEF(test_platform,
  771. * DAILINK_COMP_ARRAY(COMP_PLATFORM("platform")));
  772. *
  773. * struct snd_soc_dai_link link = {
  774. * ...
  775. * SND_SOC_DAILINK_REG(test_cpu,
  776. * test_codec,
  777. * test_platform),
  778. * };
  779. *
  780. * Sample 4 : Sample3 without platform
  781. *
  782. * struct snd_soc_dai_link link = {
  783. * ...
  784. * SND_SOC_DAILINK_REG(test_cpu,
  785. * test_codec);
  786. * };
  787. */
  788. #define SND_SOC_DAILINK_REG1(name) SND_SOC_DAILINK_REG3(name##_cpus, name##_codecs, name##_platforms)
  789. #define SND_SOC_DAILINK_REG2(cpu, codec) SND_SOC_DAILINK_REG3(cpu, codec, null_dailink_component)
  790. #define SND_SOC_DAILINK_REG3(cpu, codec, platform) \
  791. .cpus = cpu, \
  792. .num_cpus = ARRAY_SIZE(cpu), \
  793. .codecs = codec, \
  794. .num_codecs = ARRAY_SIZE(codec), \
  795. .platforms = platform, \
  796. .num_platforms = ARRAY_SIZE(platform)
  797. #define SND_SOC_DAILINK_REGx(_1, _2, _3, func, ...) func
  798. #define SND_SOC_DAILINK_REG(...) \
  799. SND_SOC_DAILINK_REGx(__VA_ARGS__, \
  800. SND_SOC_DAILINK_REG3, \
  801. SND_SOC_DAILINK_REG2, \
  802. SND_SOC_DAILINK_REG1)(__VA_ARGS__)
  803. #define SND_SOC_DAILINK_DEF(name, def...) \
  804. static struct snd_soc_dai_link_component name[] = { def }
  805. #define SND_SOC_DAILINK_DEFS(name, cpu, codec, platform...) \
  806. SND_SOC_DAILINK_DEF(name##_cpus, cpu); \
  807. SND_SOC_DAILINK_DEF(name##_codecs, codec); \
  808. SND_SOC_DAILINK_DEF(name##_platforms, platform)
  809. #define DAILINK_COMP_ARRAY(param...) param
  810. #define COMP_EMPTY() { }
  811. #define COMP_CPU(_dai) { .dai_name = _dai, }
  812. #define COMP_CODEC(_name, _dai) { .name = _name, .dai_name = _dai, }
  813. #define COMP_PLATFORM(_name) { .name = _name }
  814. #define COMP_AUX(_name) { .name = _name }
  815. #define COMP_CODEC_CONF(_name) { .name = _name }
  816. #define COMP_DUMMY() { .name = "snd-soc-dummy", .dai_name = "snd-soc-dummy-dai", }
  817. extern struct snd_soc_dai_link_component null_dailink_component[0];
  818. struct snd_soc_codec_conf {
  819. /*
  820. * specify device either by device name, or by
  821. * DT/OF node, but not both.
  822. */
  823. struct snd_soc_dai_link_component dlc;
  824. /*
  825. * optional map of kcontrol, widget and path name prefixes that are
  826. * associated per device
  827. */
  828. const char *name_prefix;
  829. };
  830. struct snd_soc_aux_dev {
  831. /*
  832. * specify multi-codec either by device name, or by
  833. * DT/OF node, but not both.
  834. */
  835. struct snd_soc_dai_link_component dlc;
  836. /* codec/machine specific init - e.g. add machine controls */
  837. int (*init)(struct snd_soc_component *component);
  838. };
  839. /* SoC card */
  840. struct snd_soc_card {
  841. const char *name;
  842. const char *long_name;
  843. const char *driver_name;
  844. const char *components;
  845. #ifdef CONFIG_DMI
  846. char dmi_longname[80];
  847. #endif /* CONFIG_DMI */
  848. char topology_shortname[32];
  849. struct device *dev;
  850. struct snd_card *snd_card;
  851. struct module *owner;
  852. struct mutex mutex;
  853. struct mutex dapm_mutex;
  854. /* Mutex for PCM operations */
  855. struct mutex pcm_mutex;
  856. enum snd_soc_pcm_subclass pcm_subclass;
  857. int (*probe)(struct snd_soc_card *card);
  858. int (*late_probe)(struct snd_soc_card *card);
  859. void (*fixup_controls)(struct snd_soc_card *card);
  860. int (*remove)(struct snd_soc_card *card);
  861. /* the pre and post PM functions are used to do any PM work before and
  862. * after the codec and DAI's do any PM work. */
  863. int (*suspend_pre)(struct snd_soc_card *card);
  864. int (*suspend_post)(struct snd_soc_card *card);
  865. int (*resume_pre)(struct snd_soc_card *card);
  866. int (*resume_post)(struct snd_soc_card *card);
  867. /* callbacks */
  868. int (*set_bias_level)(struct snd_soc_card *,
  869. struct snd_soc_dapm_context *dapm,
  870. enum snd_soc_bias_level level);
  871. int (*set_bias_level_post)(struct snd_soc_card *,
  872. struct snd_soc_dapm_context *dapm,
  873. enum snd_soc_bias_level level);
  874. int (*add_dai_link)(struct snd_soc_card *,
  875. struct snd_soc_dai_link *link);
  876. void (*remove_dai_link)(struct snd_soc_card *,
  877. struct snd_soc_dai_link *link);
  878. long pmdown_time;
  879. /* CPU <--> Codec DAI links */
  880. struct snd_soc_dai_link *dai_link; /* predefined links only */
  881. int num_links; /* predefined links only */
  882. struct list_head rtd_list;
  883. int num_rtd;
  884. /* optional codec specific configuration */
  885. struct snd_soc_codec_conf *codec_conf;
  886. int num_configs;
  887. /*
  888. * optional auxiliary devices such as amplifiers or codecs with DAI
  889. * link unused
  890. */
  891. struct snd_soc_aux_dev *aux_dev;
  892. int num_aux_devs;
  893. struct list_head aux_comp_list;
  894. const struct snd_kcontrol_new *controls;
  895. int num_controls;
  896. /*
  897. * Card-specific routes and widgets.
  898. * Note: of_dapm_xxx for Device Tree; Otherwise for driver build-in.
  899. */
  900. const struct snd_soc_dapm_widget *dapm_widgets;
  901. int num_dapm_widgets;
  902. const struct snd_soc_dapm_route *dapm_routes;
  903. int num_dapm_routes;
  904. const struct snd_soc_dapm_widget *of_dapm_widgets;
  905. int num_of_dapm_widgets;
  906. const struct snd_soc_dapm_route *of_dapm_routes;
  907. int num_of_dapm_routes;
  908. /* lists of probed devices belonging to this card */
  909. struct list_head component_dev_list;
  910. struct list_head list;
  911. struct list_head widgets;
  912. struct list_head paths;
  913. struct list_head dapm_list;
  914. struct list_head dapm_dirty;
  915. /* attached dynamic objects */
  916. struct list_head dobj_list;
  917. /* Generic DAPM context for the card */
  918. struct snd_soc_dapm_context dapm;
  919. struct snd_soc_dapm_stats dapm_stats;
  920. struct snd_soc_dapm_update *update;
  921. #ifdef CONFIG_DEBUG_FS
  922. struct dentry *debugfs_card_root;
  923. #endif
  924. #ifdef CONFIG_PM_SLEEP
  925. struct work_struct deferred_resume_work;
  926. #endif
  927. u32 pop_time;
  928. /* bit field */
  929. unsigned int instantiated:1;
  930. unsigned int topology_shortname_created:1;
  931. unsigned int fully_routed:1;
  932. unsigned int disable_route_checks:1;
  933. unsigned int probed:1;
  934. unsigned int component_chaining:1;
  935. void *drvdata;
  936. ANDROID_KABI_RESERVE(1);
  937. ANDROID_KABI_RESERVE(2);
  938. ANDROID_KABI_RESERVE(3);
  939. ANDROID_KABI_RESERVE(4);
  940. };
  941. #define for_each_card_prelinks(card, i, link) \
  942. for ((i) = 0; \
  943. ((i) < (card)->num_links) && ((link) = &(card)->dai_link[i]); \
  944. (i)++)
  945. #define for_each_card_pre_auxs(card, i, aux) \
  946. for ((i) = 0; \
  947. ((i) < (card)->num_aux_devs) && ((aux) = &(card)->aux_dev[i]); \
  948. (i)++)
  949. #define for_each_card_rtds(card, rtd) \
  950. list_for_each_entry(rtd, &(card)->rtd_list, list)
  951. #define for_each_card_rtds_safe(card, rtd, _rtd) \
  952. list_for_each_entry_safe(rtd, _rtd, &(card)->rtd_list, list)
  953. #define for_each_card_auxs(card, component) \
  954. list_for_each_entry(component, &card->aux_comp_list, card_aux_list)
  955. #define for_each_card_auxs_safe(card, component, _comp) \
  956. list_for_each_entry_safe(component, _comp, \
  957. &card->aux_comp_list, card_aux_list)
  958. #define for_each_card_components(card, component) \
  959. list_for_each_entry(component, &(card)->component_dev_list, card_list)
  960. #define for_each_card_dapms(card, dapm) \
  961. list_for_each_entry(dapm, &card->dapm_list, list)
  962. #define for_each_card_widgets(card, w)\
  963. list_for_each_entry(w, &card->widgets, list)
  964. #define for_each_card_widgets_safe(card, w, _w) \
  965. list_for_each_entry_safe(w, _w, &card->widgets, list)
  966. /* SoC machine DAI configuration, glues a codec and cpu DAI together */
  967. struct snd_soc_pcm_runtime {
  968. struct device *dev;
  969. struct snd_soc_card *card;
  970. struct snd_soc_dai_link *dai_link;
  971. struct snd_pcm_ops ops;
  972. unsigned int params_select; /* currently selected param for dai link */
  973. /* Dynamic PCM BE runtime data */
  974. struct snd_soc_dpcm_runtime dpcm[SNDRV_PCM_STREAM_LAST + 1];
  975. struct snd_soc_dapm_widget *c2c_widget[SNDRV_PCM_STREAM_LAST + 1];
  976. long pmdown_time;
  977. /* runtime devices */
  978. struct snd_pcm *pcm;
  979. struct snd_compr *compr;
  980. /*
  981. * dais = cpu_dai + codec_dai
  982. * see
  983. * soc_new_pcm_runtime()
  984. * asoc_rtd_to_cpu()
  985. * asoc_rtd_to_codec()
  986. */
  987. struct snd_soc_dai **dais;
  988. struct delayed_work delayed_work;
  989. void (*close_delayed_work_func)(struct snd_soc_pcm_runtime *rtd);
  990. #ifdef CONFIG_DEBUG_FS
  991. struct dentry *debugfs_dpcm_root;
  992. #endif
  993. unsigned int num; /* 0-based and monotonic increasing */
  994. struct list_head list; /* rtd list of the soc card */
  995. /* function mark */
  996. struct snd_pcm_substream *mark_startup;
  997. struct snd_pcm_substream *mark_hw_params;
  998. struct snd_pcm_substream *mark_trigger;
  999. struct snd_compr_stream *mark_compr_startup;
  1000. /* bit field */
  1001. unsigned int pop_wait:1;
  1002. unsigned int fe_compr:1; /* for Dynamic PCM */
  1003. int num_components;
  1004. ANDROID_KABI_RESERVE(1);
  1005. struct snd_soc_component *components[]; /* CPU/Codec/Platform */
  1006. };
  1007. /* see soc_new_pcm_runtime() */
  1008. #define asoc_rtd_to_cpu(rtd, n) (rtd)->dais[n]
  1009. #define asoc_rtd_to_codec(rtd, n) (rtd)->dais[n + (rtd)->dai_link->num_cpus]
  1010. #define asoc_substream_to_rtd(substream) \
  1011. (struct snd_soc_pcm_runtime *)snd_pcm_substream_chip(substream)
  1012. #define for_each_rtd_components(rtd, i, component) \
  1013. for ((i) = 0, component = NULL; \
  1014. ((i) < rtd->num_components) && ((component) = rtd->components[i]);\
  1015. (i)++)
  1016. #define for_each_rtd_cpu_dais(rtd, i, dai) \
  1017. for ((i) = 0; \
  1018. ((i) < rtd->dai_link->num_cpus) && ((dai) = asoc_rtd_to_cpu(rtd, i)); \
  1019. (i)++)
  1020. #define for_each_rtd_codec_dais(rtd, i, dai) \
  1021. for ((i) = 0; \
  1022. ((i) < rtd->dai_link->num_codecs) && ((dai) = asoc_rtd_to_codec(rtd, i)); \
  1023. (i)++)
  1024. #define for_each_rtd_dais(rtd, i, dai) \
  1025. for ((i) = 0; \
  1026. ((i) < (rtd)->dai_link->num_cpus + (rtd)->dai_link->num_codecs) && \
  1027. ((dai) = (rtd)->dais[i]); \
  1028. (i)++)
  1029. void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd);
  1030. /* mixer control */
  1031. struct soc_mixer_control {
  1032. int min, max, platform_max;
  1033. int reg, rreg;
  1034. unsigned int shift, rshift;
  1035. unsigned int sign_bit;
  1036. unsigned int invert:1;
  1037. unsigned int autodisable:1;
  1038. #ifdef CONFIG_SND_SOC_TOPOLOGY
  1039. struct snd_soc_dobj dobj;
  1040. #endif
  1041. ANDROID_KABI_RESERVE(1);
  1042. };
  1043. struct soc_bytes {
  1044. int base;
  1045. int num_regs;
  1046. u32 mask;
  1047. };
  1048. struct soc_bytes_ext {
  1049. int max;
  1050. #ifdef CONFIG_SND_SOC_TOPOLOGY
  1051. struct snd_soc_dobj dobj;
  1052. #endif
  1053. /* used for TLV byte control */
  1054. int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
  1055. unsigned int size);
  1056. int (*put)(struct snd_kcontrol *kcontrol, const unsigned int __user *bytes,
  1057. unsigned int size);
  1058. };
  1059. /* multi register control */
  1060. struct soc_mreg_control {
  1061. long min, max;
  1062. unsigned int regbase, regcount, nbits, invert;
  1063. };
  1064. struct soc_multi_mixer_control {
  1065. int min, max, platform_max, count;
  1066. unsigned int reg, rreg, shift, rshift, invert;
  1067. };
  1068. /* enumerated kcontrol */
  1069. struct soc_enum {
  1070. int reg;
  1071. unsigned char shift_l;
  1072. unsigned char shift_r;
  1073. unsigned int items;
  1074. unsigned int mask;
  1075. const char * const *texts;
  1076. const unsigned int *values;
  1077. unsigned int autodisable:1;
  1078. #ifdef CONFIG_SND_SOC_TOPOLOGY
  1079. struct snd_soc_dobj dobj;
  1080. #endif
  1081. ANDROID_KABI_RESERVE(1);
  1082. };
  1083. static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)
  1084. {
  1085. if (mc->reg == mc->rreg && mc->shift == mc->rshift)
  1086. return false;
  1087. /*
  1088. * mc->reg == mc->rreg && mc->shift != mc->rshift, or
  1089. * mc->reg != mc->rreg means that the control is
  1090. * stereo (bits in one register or in two registers)
  1091. */
  1092. return true;
  1093. }
  1094. static inline unsigned int snd_soc_enum_val_to_item(struct soc_enum *e,
  1095. unsigned int val)
  1096. {
  1097. unsigned int i;
  1098. if (!e->values)
  1099. return val;
  1100. for (i = 0; i < e->items; i++)
  1101. if (val == e->values[i])
  1102. return i;
  1103. return 0;
  1104. }
  1105. static inline unsigned int snd_soc_enum_item_to_val(struct soc_enum *e,
  1106. unsigned int item)
  1107. {
  1108. if (!e->values)
  1109. return item;
  1110. return e->values[item];
  1111. }
  1112. /**
  1113. * snd_soc_kcontrol_component() - Returns the component that registered the
  1114. * control
  1115. * @kcontrol: The control for which to get the component
  1116. *
  1117. * Note: This function will work correctly if the control has been registered
  1118. * for a component. With snd_soc_add_codec_controls() or via table based
  1119. * setup for either a CODEC or component driver. Otherwise the behavior is
  1120. * undefined.
  1121. */
  1122. static inline struct snd_soc_component *snd_soc_kcontrol_component(
  1123. struct snd_kcontrol *kcontrol)
  1124. {
  1125. return snd_kcontrol_chip(kcontrol);
  1126. }
  1127. int snd_soc_util_init(void);
  1128. void snd_soc_util_exit(void);
  1129. int snd_soc_of_parse_card_name(struct snd_soc_card *card,
  1130. const char *propname);
  1131. int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
  1132. const char *propname);
  1133. int snd_soc_of_parse_pin_switches(struct snd_soc_card *card, const char *prop);
  1134. int snd_soc_of_get_slot_mask(struct device_node *np,
  1135. const char *prop_name,
  1136. unsigned int *mask);
  1137. int snd_soc_of_parse_tdm_slot(struct device_node *np,
  1138. unsigned int *tx_mask,
  1139. unsigned int *rx_mask,
  1140. unsigned int *slots,
  1141. unsigned int *slot_width);
  1142. void snd_soc_of_parse_node_prefix(struct device_node *np,
  1143. struct snd_soc_codec_conf *codec_conf,
  1144. struct device_node *of_node,
  1145. const char *propname);
  1146. static inline
  1147. void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
  1148. struct snd_soc_codec_conf *codec_conf,
  1149. struct device_node *of_node,
  1150. const char *propname)
  1151. {
  1152. snd_soc_of_parse_node_prefix(card->dev->of_node,
  1153. codec_conf, of_node, propname);
  1154. }
  1155. int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
  1156. const char *propname);
  1157. int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname);
  1158. unsigned int snd_soc_daifmt_clock_provider_flipped(unsigned int dai_fmt);
  1159. unsigned int snd_soc_daifmt_clock_provider_from_bitmap(unsigned int bit_frame);
  1160. unsigned int snd_soc_daifmt_parse_format(struct device_node *np, const char *prefix);
  1161. unsigned int snd_soc_daifmt_parse_clock_provider_raw(struct device_node *np,
  1162. const char *prefix,
  1163. struct device_node **bitclkmaster,
  1164. struct device_node **framemaster);
  1165. #define snd_soc_daifmt_parse_clock_provider_as_bitmap(np, prefix) \
  1166. snd_soc_daifmt_parse_clock_provider_raw(np, prefix, NULL, NULL)
  1167. #define snd_soc_daifmt_parse_clock_provider_as_phandle \
  1168. snd_soc_daifmt_parse_clock_provider_raw
  1169. #define snd_soc_daifmt_parse_clock_provider_as_flag(np, prefix) \
  1170. snd_soc_daifmt_clock_provider_from_bitmap( \
  1171. snd_soc_daifmt_parse_clock_provider_as_bitmap(np, prefix))
  1172. int snd_soc_get_dai_id(struct device_node *ep);
  1173. int snd_soc_get_dai_name(const struct of_phandle_args *args,
  1174. const char **dai_name);
  1175. int snd_soc_of_get_dai_name(struct device_node *of_node,
  1176. const char **dai_name);
  1177. int snd_soc_of_get_dai_link_codecs(struct device *dev,
  1178. struct device_node *of_node,
  1179. struct snd_soc_dai_link *dai_link);
  1180. void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link);
  1181. int snd_soc_of_get_dai_link_cpus(struct device *dev,
  1182. struct device_node *of_node,
  1183. struct snd_soc_dai_link *dai_link);
  1184. void snd_soc_of_put_dai_link_cpus(struct snd_soc_dai_link *dai_link);
  1185. int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
  1186. struct snd_soc_dai_link *dai_link);
  1187. void snd_soc_remove_pcm_runtime(struct snd_soc_card *card,
  1188. struct snd_soc_pcm_runtime *rtd);
  1189. struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
  1190. struct snd_soc_dai_driver *dai_drv,
  1191. bool legacy_dai_naming);
  1192. struct snd_soc_dai *devm_snd_soc_register_dai(struct device *dev,
  1193. struct snd_soc_component *component,
  1194. struct snd_soc_dai_driver *dai_drv,
  1195. bool legacy_dai_naming);
  1196. void snd_soc_unregister_dai(struct snd_soc_dai *dai);
  1197. struct snd_soc_dai *snd_soc_find_dai(
  1198. const struct snd_soc_dai_link_component *dlc);
  1199. struct snd_soc_dai *snd_soc_find_dai_with_mutex(
  1200. const struct snd_soc_dai_link_component *dlc);
  1201. #include <sound/soc-dai.h>
  1202. static inline
  1203. int snd_soc_fixup_dai_links_platform_name(struct snd_soc_card *card,
  1204. const char *platform_name)
  1205. {
  1206. struct snd_soc_dai_link *dai_link;
  1207. const char *name;
  1208. int i;
  1209. if (!platform_name) /* nothing to do */
  1210. return 0;
  1211. /* set platform name for each dailink */
  1212. for_each_card_prelinks(card, i, dai_link) {
  1213. /* only single platform is supported for now */
  1214. if (dai_link->num_platforms != 1)
  1215. return -EINVAL;
  1216. if (!dai_link->platforms)
  1217. return -EINVAL;
  1218. name = devm_kstrdup(card->dev, platform_name, GFP_KERNEL);
  1219. if (!name)
  1220. return -ENOMEM;
  1221. /* only single platform is supported for now */
  1222. dai_link->platforms->name = name;
  1223. }
  1224. return 0;
  1225. }
  1226. #ifdef CONFIG_DEBUG_FS
  1227. extern struct dentry *snd_soc_debugfs_root;
  1228. #endif
  1229. extern const struct dev_pm_ops snd_soc_pm_ops;
  1230. /*
  1231. * DAPM helper functions
  1232. */
  1233. enum snd_soc_dapm_subclass {
  1234. SND_SOC_DAPM_CLASS_ROOT = 0,
  1235. SND_SOC_DAPM_CLASS_RUNTIME = 1,
  1236. };
  1237. static inline void _snd_soc_dapm_mutex_lock_root_c(struct snd_soc_card *card)
  1238. {
  1239. mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_ROOT);
  1240. }
  1241. static inline void _snd_soc_dapm_mutex_lock_c(struct snd_soc_card *card)
  1242. {
  1243. mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
  1244. }
  1245. static inline void _snd_soc_dapm_mutex_unlock_c(struct snd_soc_card *card)
  1246. {
  1247. mutex_unlock(&card->dapm_mutex);
  1248. }
  1249. static inline void _snd_soc_dapm_mutex_assert_held_c(struct snd_soc_card *card)
  1250. {
  1251. lockdep_assert_held(&card->dapm_mutex);
  1252. }
  1253. static inline void _snd_soc_dapm_mutex_lock_root_d(struct snd_soc_dapm_context *dapm)
  1254. {
  1255. _snd_soc_dapm_mutex_lock_root_c(dapm->card);
  1256. }
  1257. static inline void _snd_soc_dapm_mutex_lock_d(struct snd_soc_dapm_context *dapm)
  1258. {
  1259. _snd_soc_dapm_mutex_lock_c(dapm->card);
  1260. }
  1261. static inline void _snd_soc_dapm_mutex_unlock_d(struct snd_soc_dapm_context *dapm)
  1262. {
  1263. _snd_soc_dapm_mutex_unlock_c(dapm->card);
  1264. }
  1265. static inline void _snd_soc_dapm_mutex_assert_held_d(struct snd_soc_dapm_context *dapm)
  1266. {
  1267. _snd_soc_dapm_mutex_assert_held_c(dapm->card);
  1268. }
  1269. #define snd_soc_dapm_mutex_lock_root(x) _Generic((x), \
  1270. struct snd_soc_card * : _snd_soc_dapm_mutex_lock_root_c, \
  1271. struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_lock_root_d)(x)
  1272. #define snd_soc_dapm_mutex_lock(x) _Generic((x), \
  1273. struct snd_soc_card * : _snd_soc_dapm_mutex_lock_c, \
  1274. struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_lock_d)(x)
  1275. #define snd_soc_dapm_mutex_unlock(x) _Generic((x), \
  1276. struct snd_soc_card * : _snd_soc_dapm_mutex_unlock_c, \
  1277. struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_unlock_d)(x)
  1278. #define snd_soc_dapm_mutex_assert_held(x) _Generic((x), \
  1279. struct snd_soc_card * : _snd_soc_dapm_mutex_assert_held_c, \
  1280. struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_assert_held_d)(x)
  1281. /*
  1282. * PCM helper functions
  1283. */
  1284. static inline void _snd_soc_dpcm_mutex_lock_c(struct snd_soc_card *card)
  1285. {
  1286. mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass);
  1287. }
  1288. static inline void _snd_soc_dpcm_mutex_unlock_c(struct snd_soc_card *card)
  1289. {
  1290. mutex_unlock(&card->pcm_mutex);
  1291. }
  1292. static inline void _snd_soc_dpcm_mutex_assert_held_c(struct snd_soc_card *card)
  1293. {
  1294. lockdep_assert_held(&card->pcm_mutex);
  1295. }
  1296. static inline void _snd_soc_dpcm_mutex_lock_r(struct snd_soc_pcm_runtime *rtd)
  1297. {
  1298. _snd_soc_dpcm_mutex_lock_c(rtd->card);
  1299. }
  1300. static inline void _snd_soc_dpcm_mutex_unlock_r(struct snd_soc_pcm_runtime *rtd)
  1301. {
  1302. _snd_soc_dpcm_mutex_unlock_c(rtd->card);
  1303. }
  1304. static inline void _snd_soc_dpcm_mutex_assert_held_r(struct snd_soc_pcm_runtime *rtd)
  1305. {
  1306. _snd_soc_dpcm_mutex_assert_held_c(rtd->card);
  1307. }
  1308. #define snd_soc_dpcm_mutex_lock(x) _Generic((x), \
  1309. struct snd_soc_card * : _snd_soc_dpcm_mutex_lock_c, \
  1310. struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_lock_r)(x)
  1311. #define snd_soc_dpcm_mutex_unlock(x) _Generic((x), \
  1312. struct snd_soc_card * : _snd_soc_dpcm_mutex_unlock_c, \
  1313. struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_unlock_r)(x)
  1314. #define snd_soc_dpcm_mutex_assert_held(x) _Generic((x), \
  1315. struct snd_soc_card * : _snd_soc_dpcm_mutex_assert_held_c, \
  1316. struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_assert_held_r)(x)
  1317. #include <sound/soc-component.h>
  1318. #include <sound/soc-card.h>
  1319. #include <sound/soc-jack.h>
  1320. #endif