soc.h 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554
  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 <sound/core.h>
  21. #include <sound/pcm.h>
  22. #include <sound/compress_driver.h>
  23. #include <sound/control.h>
  24. #include <sound/ac97_codec.h>
  25. /*
  26. * Convenience kcontrol builders
  27. */
  28. #define SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, xmax, xinvert, xautodisable) \
  29. ((unsigned long)&(struct soc_mixer_control) \
  30. {.reg = xreg, .rreg = xreg, .shift = shift_left, \
  31. .rshift = shift_right, .max = xmax, .platform_max = xmax, \
  32. .invert = xinvert, .autodisable = xautodisable})
  33. #define SOC_DOUBLE_S_VALUE(xreg, shift_left, shift_right, xmin, xmax, xsign_bit, xinvert, xautodisable) \
  34. ((unsigned long)&(struct soc_mixer_control) \
  35. {.reg = xreg, .rreg = xreg, .shift = shift_left, \
  36. .rshift = shift_right, .min = xmin, .max = xmax, .platform_max = xmax, \
  37. .sign_bit = xsign_bit, .invert = xinvert, .autodisable = xautodisable})
  38. #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, xautodisable) \
  39. SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert, xautodisable)
  40. #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
  41. ((unsigned long)&(struct soc_mixer_control) \
  42. {.reg = xreg, .max = xmax, .platform_max = xmax, .invert = xinvert})
  43. #define SOC_DOUBLE_R_VALUE(xlreg, xrreg, xshift, xmax, xinvert) \
  44. ((unsigned long)&(struct soc_mixer_control) \
  45. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  46. .max = xmax, .platform_max = xmax, .invert = xinvert})
  47. #define SOC_DOUBLE_R_S_VALUE(xlreg, xrreg, xshift, xmin, xmax, xsign_bit, xinvert) \
  48. ((unsigned long)&(struct soc_mixer_control) \
  49. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  50. .max = xmax, .min = xmin, .platform_max = xmax, .sign_bit = xsign_bit, \
  51. .invert = xinvert})
  52. #define SOC_DOUBLE_R_RANGE_VALUE(xlreg, xrreg, xshift, xmin, xmax, xinvert) \
  53. ((unsigned long)&(struct soc_mixer_control) \
  54. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  55. .min = xmin, .max = xmax, .platform_max = xmax, .invert = xinvert})
  56. #define SOC_SINGLE(xname, reg, shift, max, invert) \
  57. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  58. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  59. .put = snd_soc_put_volsw, \
  60. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  61. #define SOC_SINGLE_RANGE(xname, xreg, xshift, xmin, xmax, xinvert) \
  62. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  63. .info = snd_soc_info_volsw_range, .get = snd_soc_get_volsw_range, \
  64. .put = snd_soc_put_volsw_range, \
  65. .private_value = (unsigned long)&(struct soc_mixer_control) \
  66. {.reg = xreg, .rreg = xreg, .shift = xshift, \
  67. .rshift = xshift, .min = xmin, .max = xmax, \
  68. .platform_max = xmax, .invert = xinvert} }
  69. #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
  70. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  71. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  72. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  73. .tlv.p = (tlv_array), \
  74. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  75. .put = snd_soc_put_volsw, \
  76. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  77. #define SOC_SINGLE_SX_TLV(xname, xreg, xshift, xmin, xmax, tlv_array) \
  78. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  79. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  80. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  81. .tlv.p = (tlv_array),\
  82. .info = snd_soc_info_volsw_sx, \
  83. .get = snd_soc_get_volsw_sx,\
  84. .put = snd_soc_put_volsw_sx, \
  85. .private_value = (unsigned long)&(struct soc_mixer_control) \
  86. {.reg = xreg, .rreg = xreg, \
  87. .shift = xshift, .rshift = xshift, \
  88. .max = xmax, .min = xmin} }
  89. #define SOC_SINGLE_RANGE_TLV(xname, xreg, xshift, xmin, xmax, xinvert, tlv_array) \
  90. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  91. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  92. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  93. .tlv.p = (tlv_array), \
  94. .info = snd_soc_info_volsw_range, \
  95. .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
  96. .private_value = (unsigned long)&(struct soc_mixer_control) \
  97. {.reg = xreg, .rreg = xreg, .shift = xshift, \
  98. .rshift = xshift, .min = xmin, .max = xmax, \
  99. .platform_max = xmax, .invert = xinvert} }
  100. #define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
  101. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  102. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  103. .put = snd_soc_put_volsw, \
  104. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  105. max, invert, 0) }
  106. #define SOC_DOUBLE_STS(xname, reg, shift_left, shift_right, max, invert) \
  107. { \
  108. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  109. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  110. .access = SNDRV_CTL_ELEM_ACCESS_READ | \
  111. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  112. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  113. max, invert, 0) }
  114. #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
  115. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  116. .info = snd_soc_info_volsw, \
  117. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  118. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  119. xmax, xinvert) }
  120. #define SOC_DOUBLE_R_RANGE(xname, reg_left, reg_right, xshift, xmin, \
  121. xmax, xinvert) \
  122. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  123. .info = snd_soc_info_volsw_range, \
  124. .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
  125. .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \
  126. xshift, xmin, xmax, xinvert) }
  127. #define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
  128. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  129. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  130. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  131. .tlv.p = (tlv_array), \
  132. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  133. .put = snd_soc_put_volsw, \
  134. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  135. max, invert, 0) }
  136. #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
  137. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  138. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  139. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  140. .tlv.p = (tlv_array), \
  141. .info = snd_soc_info_volsw, \
  142. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  143. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  144. xmax, xinvert) }
  145. #define SOC_DOUBLE_R_RANGE_TLV(xname, reg_left, reg_right, xshift, xmin, \
  146. xmax, xinvert, tlv_array) \
  147. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  148. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  149. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  150. .tlv.p = (tlv_array), \
  151. .info = snd_soc_info_volsw_range, \
  152. .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
  153. .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \
  154. xshift, xmin, xmax, xinvert) }
  155. #define SOC_DOUBLE_R_SX_TLV(xname, xreg, xrreg, xshift, xmin, xmax, tlv_array) \
  156. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  157. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  158. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  159. .tlv.p = (tlv_array), \
  160. .info = snd_soc_info_volsw_sx, \
  161. .get = snd_soc_get_volsw_sx, \
  162. .put = snd_soc_put_volsw_sx, \
  163. .private_value = (unsigned long)&(struct soc_mixer_control) \
  164. {.reg = xreg, .rreg = xrreg, \
  165. .shift = xshift, .rshift = xshift, \
  166. .max = xmax, .min = xmin} }
  167. #define SOC_DOUBLE_R_S_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \
  168. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  169. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  170. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  171. .tlv.p = (tlv_array), \
  172. .info = snd_soc_info_volsw, \
  173. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  174. .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \
  175. xmin, xmax, xsign_bit, xinvert) }
  176. #define SOC_SINGLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  177. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  178. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  179. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  180. .tlv.p = (tlv_array), \
  181. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  182. .put = snd_soc_put_volsw, \
  183. .private_value = (unsigned long)&(struct soc_mixer_control) \
  184. {.reg = xreg, .rreg = xreg, \
  185. .min = xmin, .max = xmax, .platform_max = xmax, \
  186. .sign_bit = 7,} }
  187. #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  188. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  189. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  190. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  191. .tlv.p = (tlv_array), \
  192. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  193. .put = snd_soc_put_volsw, \
  194. .private_value = SOC_DOUBLE_S_VALUE(xreg, 0, 8, xmin, xmax, 7, 0, 0) }
  195. #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xitems, xtexts) \
  196. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  197. .items = xitems, .texts = xtexts, \
  198. .mask = xitems ? roundup_pow_of_two(xitems) - 1 : 0}
  199. #define SOC_ENUM_SINGLE(xreg, xshift, xitems, xtexts) \
  200. SOC_ENUM_DOUBLE(xreg, xshift, xshift, xitems, xtexts)
  201. #define SOC_ENUM_SINGLE_EXT(xitems, xtexts) \
  202. { .items = xitems, .texts = xtexts }
  203. #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xitems, xtexts, xvalues) \
  204. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  205. .mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues}
  206. #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
  207. SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xitems, xtexts, xvalues)
  208. #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
  209. { .reg = xreg, .shift_l = xshift, .shift_r = xshift, \
  210. .mask = xmask, .items = xitems, .texts = xtexts, \
  211. .values = xvalues, .autodisable = 1}
  212. #define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \
  213. SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts)
  214. #define SOC_ENUM(xname, xenum) \
  215. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  216. .info = snd_soc_info_enum_double, \
  217. .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
  218. .private_value = (unsigned long)&xenum }
  219. #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
  220. xhandler_get, xhandler_put) \
  221. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  222. .info = snd_soc_info_volsw, \
  223. .get = xhandler_get, .put = xhandler_put, \
  224. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) }
  225. #define SOC_DOUBLE_EXT(xname, reg, shift_left, shift_right, max, invert,\
  226. xhandler_get, xhandler_put) \
  227. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  228. .info = snd_soc_info_volsw, \
  229. .get = xhandler_get, .put = xhandler_put, \
  230. .private_value = \
  231. SOC_DOUBLE_VALUE(reg, shift_left, shift_right, max, invert, 0) }
  232. #define SOC_DOUBLE_R_EXT(xname, reg_left, reg_right, xshift, xmax, xinvert,\
  233. xhandler_get, xhandler_put) \
  234. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  235. .info = snd_soc_info_volsw, \
  236. .get = xhandler_get, .put = xhandler_put, \
  237. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  238. xmax, xinvert) }
  239. #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
  240. xhandler_get, xhandler_put, tlv_array) \
  241. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  242. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  243. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  244. .tlv.p = (tlv_array), \
  245. .info = snd_soc_info_volsw, \
  246. .get = xhandler_get, .put = xhandler_put, \
  247. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) }
  248. #define SOC_SINGLE_RANGE_EXT_TLV(xname, xreg, xshift, xmin, xmax, xinvert, \
  249. xhandler_get, xhandler_put, tlv_array) \
  250. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  251. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  252. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  253. .tlv.p = (tlv_array), \
  254. .info = snd_soc_info_volsw_range, \
  255. .get = xhandler_get, .put = xhandler_put, \
  256. .private_value = (unsigned long)&(struct soc_mixer_control) \
  257. {.reg = xreg, .rreg = xreg, .shift = xshift, \
  258. .rshift = xshift, .min = xmin, .max = xmax, \
  259. .platform_max = xmax, .invert = xinvert} }
  260. #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
  261. xhandler_get, xhandler_put, tlv_array) \
  262. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  263. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  264. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  265. .tlv.p = (tlv_array), \
  266. .info = snd_soc_info_volsw, \
  267. .get = xhandler_get, .put = xhandler_put, \
  268. .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
  269. xmax, xinvert, 0) }
  270. #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\
  271. xhandler_get, xhandler_put, tlv_array) \
  272. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  273. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  274. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  275. .tlv.p = (tlv_array), \
  276. .info = snd_soc_info_volsw, \
  277. .get = xhandler_get, .put = xhandler_put, \
  278. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  279. xmax, xinvert) }
  280. #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
  281. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  282. .info = snd_soc_info_bool_ext, \
  283. .get = xhandler_get, .put = xhandler_put, \
  284. .private_value = xdata }
  285. #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
  286. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  287. .info = snd_soc_info_enum_double, \
  288. .get = xhandler_get, .put = xhandler_put, \
  289. .private_value = (unsigned long)&xenum }
  290. #define SOC_VALUE_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
  291. SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put)
  292. #define SND_SOC_BYTES(xname, xbase, xregs) \
  293. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  294. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  295. .put = snd_soc_bytes_put, .private_value = \
  296. ((unsigned long)&(struct soc_bytes) \
  297. {.base = xbase, .num_regs = xregs }) }
  298. #define SND_SOC_BYTES_MASK(xname, xbase, xregs, xmask) \
  299. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  300. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  301. .put = snd_soc_bytes_put, .private_value = \
  302. ((unsigned long)&(struct soc_bytes) \
  303. {.base = xbase, .num_regs = xregs, \
  304. .mask = xmask }) }
  305. /*
  306. * SND_SOC_BYTES_EXT is deprecated, please USE SND_SOC_BYTES_TLV instead
  307. */
  308. #define SND_SOC_BYTES_EXT(xname, xcount, xhandler_get, xhandler_put) \
  309. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  310. .info = snd_soc_bytes_info_ext, \
  311. .get = xhandler_get, .put = xhandler_put, \
  312. .private_value = (unsigned long)&(struct soc_bytes_ext) \
  313. {.max = xcount} }
  314. #define SND_SOC_BYTES_TLV(xname, xcount, xhandler_get, xhandler_put) \
  315. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  316. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE | \
  317. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
  318. .tlv.c = (snd_soc_bytes_tlv_callback), \
  319. .info = snd_soc_bytes_info_ext, \
  320. .private_value = (unsigned long)&(struct soc_bytes_ext) \
  321. {.max = xcount, .get = xhandler_get, .put = xhandler_put, } }
  322. #define SOC_SINGLE_XR_SX(xname, xregbase, xregcount, xnbits, \
  323. xmin, xmax, xinvert) \
  324. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  325. .info = snd_soc_info_xr_sx, .get = snd_soc_get_xr_sx, \
  326. .put = snd_soc_put_xr_sx, \
  327. .private_value = (unsigned long)&(struct soc_mreg_control) \
  328. {.regbase = xregbase, .regcount = xregcount, .nbits = xnbits, \
  329. .invert = xinvert, .min = xmin, .max = xmax} }
  330. #define SOC_SINGLE_STROBE(xname, xreg, xshift, xinvert) \
  331. SOC_SINGLE_EXT(xname, xreg, xshift, 1, xinvert, \
  332. snd_soc_get_strobe, snd_soc_put_strobe)
  333. /*
  334. * Simplified versions of above macros, declaring a struct and calculating
  335. * ARRAY_SIZE internally
  336. */
  337. #define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \
  338. const struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
  339. ARRAY_SIZE(xtexts), xtexts)
  340. #define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \
  341. SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
  342. #define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \
  343. const struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts)
  344. #define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \
  345. const struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \
  346. ARRAY_SIZE(xtexts), xtexts, xvalues)
  347. #define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
  348. SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
  349. #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
  350. const struct soc_enum name = SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, \
  351. xshift, xmask, ARRAY_SIZE(xtexts), xtexts, xvalues)
  352. #define SOC_ENUM_SINGLE_VIRT_DECL(name, xtexts) \
  353. const struct soc_enum name = SOC_ENUM_SINGLE_VIRT(ARRAY_SIZE(xtexts), xtexts)
  354. /*
  355. * Component probe and remove ordering levels for components with runtime
  356. * dependencies.
  357. */
  358. #define SND_SOC_COMP_ORDER_FIRST -2
  359. #define SND_SOC_COMP_ORDER_EARLY -1
  360. #define SND_SOC_COMP_ORDER_NORMAL 0
  361. #define SND_SOC_COMP_ORDER_LATE 1
  362. #define SND_SOC_COMP_ORDER_LAST 2
  363. /*
  364. * Bias levels
  365. *
  366. * @ON: Bias is fully on for audio playback and capture operations.
  367. * @PREPARE: Prepare for audio operations. Called before DAPM switching for
  368. * stream start and stop operations.
  369. * @STANDBY: Low power standby state when no playback/capture operations are
  370. * in progress. NOTE: The transition time between STANDBY and ON
  371. * should be as fast as possible and no longer than 10ms.
  372. * @OFF: Power Off. No restrictions on transition times.
  373. */
  374. enum snd_soc_bias_level {
  375. SND_SOC_BIAS_OFF = 0,
  376. SND_SOC_BIAS_STANDBY = 1,
  377. SND_SOC_BIAS_PREPARE = 2,
  378. SND_SOC_BIAS_ON = 3,
  379. };
  380. struct device_node;
  381. struct snd_jack;
  382. struct snd_soc_card;
  383. struct snd_soc_pcm_stream;
  384. struct snd_soc_ops;
  385. struct snd_soc_pcm_runtime;
  386. struct snd_soc_dai;
  387. struct snd_soc_dai_driver;
  388. struct snd_soc_dai_link;
  389. struct snd_soc_component;
  390. struct snd_soc_component_driver;
  391. struct soc_enum;
  392. struct snd_soc_jack;
  393. struct snd_soc_jack_zone;
  394. struct snd_soc_jack_pin;
  395. #include <sound/soc-dapm.h>
  396. #include <sound/soc-dpcm.h>
  397. #include <sound/soc-topology.h>
  398. struct snd_soc_jack_gpio;
  399. typedef int (*hw_write_t)(void *,const char* ,int);
  400. enum snd_soc_pcm_subclass {
  401. SND_SOC_PCM_CLASS_PCM = 0,
  402. SND_SOC_PCM_CLASS_BE = 1,
  403. };
  404. enum snd_soc_card_subclass {
  405. SND_SOC_CARD_CLASS_INIT = 0,
  406. SND_SOC_CARD_CLASS_RUNTIME = 1,
  407. };
  408. int snd_soc_register_card(struct snd_soc_card *card);
  409. int snd_soc_unregister_card(struct snd_soc_card *card);
  410. int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
  411. #ifdef CONFIG_PM_SLEEP
  412. int snd_soc_suspend(struct device *dev);
  413. int snd_soc_resume(struct device *dev);
  414. #else
  415. static inline int snd_soc_suspend(struct device *dev)
  416. {
  417. return 0;
  418. }
  419. static inline int snd_soc_resume(struct device *dev)
  420. {
  421. return 0;
  422. }
  423. #endif
  424. int snd_soc_poweroff(struct device *dev);
  425. int snd_soc_add_component(struct device *dev,
  426. struct snd_soc_component *component,
  427. const struct snd_soc_component_driver *component_driver,
  428. struct snd_soc_dai_driver *dai_drv,
  429. int num_dai);
  430. int snd_soc_register_component(struct device *dev,
  431. const struct snd_soc_component_driver *component_driver,
  432. struct snd_soc_dai_driver *dai_drv, int num_dai);
  433. int devm_snd_soc_register_component(struct device *dev,
  434. const struct snd_soc_component_driver *component_driver,
  435. struct snd_soc_dai_driver *dai_drv, int num_dai);
  436. void snd_soc_unregister_component(struct device *dev);
  437. struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
  438. const char *driver_name);
  439. int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
  440. #ifdef CONFIG_SND_SOC_COMPRESS
  441. int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num);
  442. #else
  443. static inline int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
  444. {
  445. return 0;
  446. }
  447. #endif
  448. void snd_soc_disconnect_sync(struct device *dev);
  449. struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
  450. const char *dai_link, int stream);
  451. struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
  452. const char *dai_link);
  453. bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd);
  454. void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream);
  455. void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream);
  456. int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
  457. unsigned int dai_fmt);
  458. #ifdef CONFIG_DMI
  459. int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour);
  460. #else
  461. static inline int snd_soc_set_dmi_name(struct snd_soc_card *card,
  462. const char *flavour)
  463. {
  464. return 0;
  465. }
  466. #endif
  467. /* Utility functions to get clock rates from various things */
  468. int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
  469. int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
  470. int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
  471. int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);
  472. /* set runtime hw params */
  473. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  474. const struct snd_pcm_hardware *hw);
  475. int soc_dai_hw_params(struct snd_pcm_substream *substream,
  476. struct snd_pcm_hw_params *params,
  477. struct snd_soc_dai *dai);
  478. /* Jack reporting */
  479. int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
  480. struct snd_soc_jack *jack, struct snd_soc_jack_pin *pins,
  481. unsigned int num_pins);
  482. void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
  483. int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
  484. struct snd_soc_jack_pin *pins);
  485. void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
  486. struct notifier_block *nb);
  487. void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
  488. struct notifier_block *nb);
  489. int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
  490. struct snd_soc_jack_zone *zones);
  491. int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
  492. #ifdef CONFIG_GPIOLIB
  493. int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  494. struct snd_soc_jack_gpio *gpios);
  495. int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
  496. struct snd_soc_jack *jack,
  497. int count, struct snd_soc_jack_gpio *gpios);
  498. void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  499. struct snd_soc_jack_gpio *gpios);
  500. #else
  501. static inline int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  502. struct snd_soc_jack_gpio *gpios)
  503. {
  504. return 0;
  505. }
  506. static inline int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
  507. struct snd_soc_jack *jack,
  508. int count,
  509. struct snd_soc_jack_gpio *gpios)
  510. {
  511. return 0;
  512. }
  513. static inline void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  514. struct snd_soc_jack_gpio *gpios)
  515. {
  516. }
  517. #endif
  518. #ifdef CONFIG_SND_SOC_AC97_BUS
  519. struct snd_ac97 *snd_soc_alloc_ac97_component(struct snd_soc_component *component);
  520. struct snd_ac97 *snd_soc_new_ac97_component(struct snd_soc_component *component,
  521. unsigned int id, unsigned int id_mask);
  522. void snd_soc_free_ac97_component(struct snd_ac97 *ac97);
  523. int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops);
  524. int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
  525. struct platform_device *pdev);
  526. extern struct snd_ac97_bus_ops *soc_ac97_ops;
  527. #else
  528. static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
  529. struct platform_device *pdev)
  530. {
  531. return 0;
  532. }
  533. static inline int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
  534. {
  535. return 0;
  536. }
  537. #endif
  538. /*
  539. *Controls
  540. */
  541. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  542. void *data, const char *long_name,
  543. const char *prefix);
  544. struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
  545. const char *name);
  546. int snd_soc_add_component_controls(struct snd_soc_component *component,
  547. const struct snd_kcontrol_new *controls, unsigned int num_controls);
  548. int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
  549. const struct snd_kcontrol_new *controls, int num_controls);
  550. int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
  551. const struct snd_kcontrol_new *controls, int num_controls);
  552. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  553. struct snd_ctl_elem_info *uinfo);
  554. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  555. struct snd_ctl_elem_value *ucontrol);
  556. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  557. struct snd_ctl_elem_value *ucontrol);
  558. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  559. struct snd_ctl_elem_info *uinfo);
  560. int snd_soc_info_volsw_sx(struct snd_kcontrol *kcontrol,
  561. struct snd_ctl_elem_info *uinfo);
  562. #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
  563. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  564. struct snd_ctl_elem_value *ucontrol);
  565. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  566. struct snd_ctl_elem_value *ucontrol);
  567. #define snd_soc_get_volsw_2r snd_soc_get_volsw
  568. #define snd_soc_put_volsw_2r snd_soc_put_volsw
  569. int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
  570. struct snd_ctl_elem_value *ucontrol);
  571. int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
  572. struct snd_ctl_elem_value *ucontrol);
  573. int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
  574. struct snd_ctl_elem_info *uinfo);
  575. int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
  576. struct snd_ctl_elem_value *ucontrol);
  577. int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
  578. struct snd_ctl_elem_value *ucontrol);
  579. int snd_soc_limit_volume(struct snd_soc_card *card,
  580. const char *name, int max);
  581. int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
  582. struct snd_ctl_elem_info *uinfo);
  583. int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
  584. struct snd_ctl_elem_value *ucontrol);
  585. int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
  586. struct snd_ctl_elem_value *ucontrol);
  587. int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,
  588. struct snd_ctl_elem_info *ucontrol);
  589. int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag,
  590. unsigned int size, unsigned int __user *tlv);
  591. int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
  592. struct snd_ctl_elem_info *uinfo);
  593. int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
  594. struct snd_ctl_elem_value *ucontrol);
  595. int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
  596. struct snd_ctl_elem_value *ucontrol);
  597. int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
  598. struct snd_ctl_elem_value *ucontrol);
  599. int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
  600. struct snd_ctl_elem_value *ucontrol);
  601. /**
  602. * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
  603. *
  604. * @pin: name of the pin to update
  605. * @mask: bits to check for in reported jack status
  606. * @invert: if non-zero then pin is enabled when status is not reported
  607. * @list: internal list entry
  608. */
  609. struct snd_soc_jack_pin {
  610. struct list_head list;
  611. const char *pin;
  612. int mask;
  613. bool invert;
  614. };
  615. /**
  616. * struct snd_soc_jack_zone - Describes voltage zones of jack detection
  617. *
  618. * @min_mv: start voltage in mv
  619. * @max_mv: end voltage in mv
  620. * @jack_type: type of jack that is expected for this voltage
  621. * @debounce_time: debounce_time for jack, codec driver should wait for this
  622. * duration before reading the adc for voltages
  623. * @list: internal list entry
  624. */
  625. struct snd_soc_jack_zone {
  626. unsigned int min_mv;
  627. unsigned int max_mv;
  628. unsigned int jack_type;
  629. unsigned int debounce_time;
  630. struct list_head list;
  631. };
  632. /**
  633. * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
  634. *
  635. * @gpio: legacy gpio number
  636. * @idx: gpio descriptor index within the function of the GPIO
  637. * consumer device
  638. * @gpiod_dev: GPIO consumer device
  639. * @name: gpio name. Also as connection ID for the GPIO consumer
  640. * device function name lookup
  641. * @report: value to report when jack detected
  642. * @invert: report presence in low state
  643. * @debounce_time: debounce time in ms
  644. * @wake: enable as wake source
  645. * @jack_status_check: callback function which overrides the detection
  646. * to provide more complex checks (eg, reading an
  647. * ADC).
  648. */
  649. struct snd_soc_jack_gpio {
  650. unsigned int gpio;
  651. unsigned int idx;
  652. struct device *gpiod_dev;
  653. const char *name;
  654. int report;
  655. int invert;
  656. int debounce_time;
  657. bool wake;
  658. /* private: */
  659. struct snd_soc_jack *jack;
  660. struct delayed_work work;
  661. struct notifier_block pm_notifier;
  662. struct gpio_desc *desc;
  663. void *data;
  664. /* public: */
  665. int (*jack_status_check)(void *data);
  666. };
  667. struct snd_soc_jack {
  668. struct mutex mutex;
  669. struct snd_jack *jack;
  670. struct snd_soc_card *card;
  671. struct list_head pins;
  672. int status;
  673. struct blocking_notifier_head notifier;
  674. struct list_head jack_zones;
  675. };
  676. /* SoC PCM stream information */
  677. struct snd_soc_pcm_stream {
  678. const char *stream_name;
  679. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  680. unsigned int rates; /* SNDRV_PCM_RATE_* */
  681. unsigned int rate_min; /* min rate */
  682. unsigned int rate_max; /* max rate */
  683. unsigned int channels_min; /* min channels */
  684. unsigned int channels_max; /* max channels */
  685. unsigned int sig_bits; /* number of bits of content */
  686. };
  687. /* SoC audio ops */
  688. struct snd_soc_ops {
  689. int (*startup)(struct snd_pcm_substream *);
  690. void (*shutdown)(struct snd_pcm_substream *);
  691. int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
  692. int (*hw_free)(struct snd_pcm_substream *);
  693. int (*prepare)(struct snd_pcm_substream *);
  694. int (*trigger)(struct snd_pcm_substream *, int);
  695. };
  696. struct snd_soc_compr_ops {
  697. int (*startup)(struct snd_compr_stream *);
  698. void (*shutdown)(struct snd_compr_stream *);
  699. int (*set_params)(struct snd_compr_stream *);
  700. int (*trigger)(struct snd_compr_stream *);
  701. };
  702. /* component interface */
  703. struct snd_soc_component_driver {
  704. const char *name;
  705. /* Default control and setup, added after probe() is run */
  706. const struct snd_kcontrol_new *controls;
  707. unsigned int num_controls;
  708. const struct snd_soc_dapm_widget *dapm_widgets;
  709. unsigned int num_dapm_widgets;
  710. const struct snd_soc_dapm_route *dapm_routes;
  711. unsigned int num_dapm_routes;
  712. int (*probe)(struct snd_soc_component *);
  713. void (*remove)(struct snd_soc_component *);
  714. int (*suspend)(struct snd_soc_component *);
  715. int (*resume)(struct snd_soc_component *);
  716. unsigned int (*read)(struct snd_soc_component *, unsigned int);
  717. int (*write)(struct snd_soc_component *, unsigned int, unsigned int);
  718. /* pcm creation and destruction */
  719. int (*pcm_new)(struct snd_soc_pcm_runtime *);
  720. void (*pcm_free)(struct snd_pcm *);
  721. /* component wide operations */
  722. int (*set_sysclk)(struct snd_soc_component *component,
  723. int clk_id, int source, unsigned int freq, int dir);
  724. int (*set_pll)(struct snd_soc_component *component, int pll_id,
  725. int source, unsigned int freq_in, unsigned int freq_out);
  726. int (*set_jack)(struct snd_soc_component *component,
  727. struct snd_soc_jack *jack, void *data);
  728. /* DT */
  729. int (*of_xlate_dai_name)(struct snd_soc_component *component,
  730. struct of_phandle_args *args,
  731. const char **dai_name);
  732. int (*of_xlate_dai_id)(struct snd_soc_component *comment,
  733. struct device_node *endpoint);
  734. void (*seq_notifier)(struct snd_soc_component *, enum snd_soc_dapm_type,
  735. int subseq);
  736. int (*stream_event)(struct snd_soc_component *, int event);
  737. int (*set_bias_level)(struct snd_soc_component *component,
  738. enum snd_soc_bias_level level);
  739. const struct snd_pcm_ops *ops;
  740. const struct snd_compr_ops *compr_ops;
  741. /* probe ordering - for components with runtime dependencies */
  742. int probe_order;
  743. int remove_order;
  744. /* bits */
  745. unsigned int idle_bias_on:1;
  746. unsigned int suspend_bias_off:1;
  747. unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
  748. unsigned int endianness:1;
  749. unsigned int non_legacy_dai_naming:1;
  750. /* this component uses topology and ignore machine driver FEs */
  751. const char *ignore_machine;
  752. const char *topology_name_prefix;
  753. int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
  754. struct snd_pcm_hw_params *params);
  755. bool use_dai_pcm_id; /* use the DAI link PCM ID as PCM device number */
  756. int be_pcm_base; /* base device ID for all BE PCMs */
  757. };
  758. struct snd_soc_component {
  759. const char *name;
  760. int id;
  761. const char *name_prefix;
  762. struct device *dev;
  763. struct snd_soc_card *card;
  764. unsigned int active;
  765. unsigned int suspended:1; /* is in suspend PM state */
  766. struct list_head list;
  767. struct list_head card_aux_list; /* for auxiliary bound components */
  768. struct list_head card_list;
  769. const struct snd_soc_component_driver *driver;
  770. struct list_head dai_list;
  771. int num_dai;
  772. struct regmap *regmap;
  773. int val_bytes;
  774. struct mutex io_mutex;
  775. /* attached dynamic objects */
  776. struct list_head dobj_list;
  777. /*
  778. * DO NOT use any of the fields below in drivers, they are temporary and
  779. * are going to be removed again soon. If you use them in driver code the
  780. * driver will be marked as BROKEN when these fields are removed.
  781. */
  782. /* Don't use these, use snd_soc_component_get_dapm() */
  783. struct snd_soc_dapm_context dapm;
  784. /* machine specific init */
  785. int (*init)(struct snd_soc_component *component);
  786. #ifdef CONFIG_DEBUG_FS
  787. struct dentry *debugfs_root;
  788. const char *debugfs_prefix;
  789. #endif
  790. };
  791. struct snd_soc_rtdcom_list {
  792. struct snd_soc_component *component;
  793. struct list_head list; /* rtd::component_list */
  794. };
  795. struct snd_soc_component*
  796. snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
  797. const char *driver_name);
  798. #define for_each_rtdcom(rtd, rtdcom) \
  799. list_for_each_entry(rtdcom, &(rtd)->component_list, list)
  800. #define for_each_rtdcom_safe(rtd, rtdcom1, rtdcom2) \
  801. list_for_each_entry_safe(rtdcom1, rtdcom2, &(rtd)->component_list, list)
  802. struct snd_soc_dai_link_component {
  803. const char *name;
  804. struct device_node *of_node;
  805. const char *dai_name;
  806. };
  807. struct snd_soc_dai_link {
  808. /* config - must be set by machine driver */
  809. const char *name; /* Codec name */
  810. const char *stream_name; /* Stream name */
  811. /*
  812. * You MAY specify the link's CPU-side device, either by device name,
  813. * or by DT/OF node, but not both. If this information is omitted,
  814. * the CPU-side DAI is matched using .cpu_dai_name only, which hence
  815. * must be globally unique. These fields are currently typically used
  816. * only for codec to codec links, or systems using device tree.
  817. */
  818. const char *cpu_name;
  819. struct device_node *cpu_of_node;
  820. /*
  821. * You MAY specify the DAI name of the CPU DAI. If this information is
  822. * omitted, the CPU-side DAI is matched using .cpu_name/.cpu_of_node
  823. * only, which only works well when that device exposes a single DAI.
  824. */
  825. const char *cpu_dai_name;
  826. /*
  827. * You MUST specify the link's codec, either by device name, or by
  828. * DT/OF node, but not both.
  829. */
  830. const char *codec_name;
  831. struct device_node *codec_of_node;
  832. /* You MUST specify the DAI name within the codec */
  833. const char *codec_dai_name;
  834. struct snd_soc_dai_link_component *codecs;
  835. unsigned int num_codecs;
  836. /*
  837. * You MAY specify the link's platform/PCM/DMA driver, either by
  838. * device name, or by DT/OF node, but not both. Some forms of link
  839. * do not need a platform.
  840. */
  841. const char *platform_name;
  842. struct device_node *platform_of_node;
  843. struct snd_soc_dai_link_component *platform;
  844. int id; /* optional ID for machine driver link identification */
  845. const struct snd_soc_pcm_stream *params;
  846. unsigned int num_params;
  847. unsigned int dai_fmt; /* format to set on init */
  848. enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */
  849. /* codec/machine specific init - e.g. add machine controls */
  850. int (*init)(struct snd_soc_pcm_runtime *rtd);
  851. /* optional hw_params re-writing for BE and FE sync */
  852. int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
  853. struct snd_pcm_hw_params *params);
  854. /* machine stream operations */
  855. const struct snd_soc_ops *ops;
  856. const struct snd_soc_compr_ops *compr_ops;
  857. /* Mark this pcm with non atomic ops */
  858. bool nonatomic;
  859. /* For unidirectional dai links */
  860. unsigned int playback_only:1;
  861. unsigned int capture_only:1;
  862. /* Keep DAI active over suspend */
  863. unsigned int ignore_suspend:1;
  864. /* Symmetry requirements */
  865. unsigned int symmetric_rates:1;
  866. unsigned int symmetric_channels:1;
  867. unsigned int symmetric_samplebits:1;
  868. /* Do not create a PCM for this DAI link (Backend link) */
  869. unsigned int no_pcm:1;
  870. /* This DAI link can route to other DAI links at runtime (Frontend)*/
  871. unsigned int dynamic:1;
  872. /* DPCM capture and Playback support */
  873. unsigned int dpcm_capture:1;
  874. unsigned int dpcm_playback:1;
  875. /* DPCM used FE & BE merged format */
  876. unsigned int dpcm_merged_format:1;
  877. /* DPCM used FE & BE merged channel */
  878. unsigned int dpcm_merged_chan:1;
  879. /* DPCM used FE & BE merged rate */
  880. unsigned int dpcm_merged_rate:1;
  881. /* pmdown_time is ignored at stop */
  882. unsigned int ignore_pmdown_time:1;
  883. /* Do not create a PCM for this DAI link (Backend link) */
  884. unsigned int ignore:1;
  885. struct list_head list; /* DAI link list of the soc card */
  886. struct snd_soc_dobj dobj; /* For topology */
  887. };
  888. #define for_each_link_codecs(link, i, codec) \
  889. for ((i) = 0; \
  890. ((i) < link->num_codecs) && ((codec) = &link->codecs[i]); \
  891. (i)++)
  892. struct snd_soc_codec_conf {
  893. /*
  894. * specify device either by device name, or by
  895. * DT/OF node, but not both.
  896. */
  897. const char *dev_name;
  898. struct device_node *of_node;
  899. /*
  900. * optional map of kcontrol, widget and path name prefixes that are
  901. * associated per device
  902. */
  903. const char *name_prefix;
  904. };
  905. struct snd_soc_aux_dev {
  906. const char *name; /* Codec name */
  907. /*
  908. * specify multi-codec either by device name, or by
  909. * DT/OF node, but not both.
  910. */
  911. const char *codec_name;
  912. struct device_node *codec_of_node;
  913. /* codec/machine specific init - e.g. add machine controls */
  914. int (*init)(struct snd_soc_component *component);
  915. };
  916. /* SoC card */
  917. struct snd_soc_card {
  918. const char *name;
  919. const char *long_name;
  920. const char *driver_name;
  921. char dmi_longname[80];
  922. char topology_shortname[32];
  923. struct device *dev;
  924. struct snd_card *snd_card;
  925. struct module *owner;
  926. struct mutex mutex;
  927. struct mutex dapm_mutex;
  928. bool instantiated;
  929. bool topology_shortname_created;
  930. int (*probe)(struct snd_soc_card *card);
  931. int (*late_probe)(struct snd_soc_card *card);
  932. int (*remove)(struct snd_soc_card *card);
  933. /* the pre and post PM functions are used to do any PM work before and
  934. * after the codec and DAI's do any PM work. */
  935. int (*suspend_pre)(struct snd_soc_card *card);
  936. int (*suspend_post)(struct snd_soc_card *card);
  937. int (*resume_pre)(struct snd_soc_card *card);
  938. int (*resume_post)(struct snd_soc_card *card);
  939. /* callbacks */
  940. int (*set_bias_level)(struct snd_soc_card *,
  941. struct snd_soc_dapm_context *dapm,
  942. enum snd_soc_bias_level level);
  943. int (*set_bias_level_post)(struct snd_soc_card *,
  944. struct snd_soc_dapm_context *dapm,
  945. enum snd_soc_bias_level level);
  946. int (*add_dai_link)(struct snd_soc_card *,
  947. struct snd_soc_dai_link *link);
  948. void (*remove_dai_link)(struct snd_soc_card *,
  949. struct snd_soc_dai_link *link);
  950. long pmdown_time;
  951. /* CPU <--> Codec DAI links */
  952. struct snd_soc_dai_link *dai_link; /* predefined links only */
  953. int num_links; /* predefined links only */
  954. struct list_head dai_link_list; /* all links */
  955. struct list_head rtd_list;
  956. int num_rtd;
  957. /* optional codec specific configuration */
  958. struct snd_soc_codec_conf *codec_conf;
  959. int num_configs;
  960. /*
  961. * optional auxiliary devices such as amplifiers or codecs with DAI
  962. * link unused
  963. */
  964. struct snd_soc_aux_dev *aux_dev;
  965. int num_aux_devs;
  966. struct list_head aux_comp_list;
  967. const struct snd_kcontrol_new *controls;
  968. int num_controls;
  969. /*
  970. * Card-specific routes and widgets.
  971. * Note: of_dapm_xxx for Device Tree; Otherwise for driver build-in.
  972. */
  973. const struct snd_soc_dapm_widget *dapm_widgets;
  974. int num_dapm_widgets;
  975. const struct snd_soc_dapm_route *dapm_routes;
  976. int num_dapm_routes;
  977. const struct snd_soc_dapm_widget *of_dapm_widgets;
  978. int num_of_dapm_widgets;
  979. const struct snd_soc_dapm_route *of_dapm_routes;
  980. int num_of_dapm_routes;
  981. bool fully_routed;
  982. struct work_struct deferred_resume_work;
  983. /* lists of probed devices belonging to this card */
  984. struct list_head component_dev_list;
  985. struct list_head list;
  986. struct list_head widgets;
  987. struct list_head paths;
  988. struct list_head dapm_list;
  989. struct list_head dapm_dirty;
  990. /* attached dynamic objects */
  991. struct list_head dobj_list;
  992. /* Generic DAPM context for the card */
  993. struct snd_soc_dapm_context dapm;
  994. struct snd_soc_dapm_stats dapm_stats;
  995. struct snd_soc_dapm_update *update;
  996. #ifdef CONFIG_DEBUG_FS
  997. struct dentry *debugfs_card_root;
  998. struct dentry *debugfs_pop_time;
  999. #endif
  1000. u32 pop_time;
  1001. void *drvdata;
  1002. };
  1003. #define for_each_card_prelinks(card, i, link) \
  1004. for ((i) = 0; \
  1005. ((i) < (card)->num_links) && ((link) = &(card)->dai_link[i]); \
  1006. (i)++)
  1007. #define for_each_card_links(card, link) \
  1008. list_for_each_entry(dai_link, &(card)->dai_link_list, list)
  1009. #define for_each_card_links_safe(card, link, _link) \
  1010. list_for_each_entry_safe(link, _link, &(card)->dai_link_list, list)
  1011. #define for_each_card_rtds(card, rtd) \
  1012. list_for_each_entry(rtd, &(card)->rtd_list, list)
  1013. #define for_each_card_rtds_safe(card, rtd, _rtd) \
  1014. list_for_each_entry_safe(rtd, _rtd, &(card)->rtd_list, list)
  1015. /* SoC machine DAI configuration, glues a codec and cpu DAI together */
  1016. struct snd_soc_pcm_runtime {
  1017. struct device *dev;
  1018. struct snd_soc_card *card;
  1019. struct snd_soc_dai_link *dai_link;
  1020. struct mutex pcm_mutex;
  1021. enum snd_soc_pcm_subclass pcm_subclass;
  1022. struct snd_pcm_ops ops;
  1023. unsigned int params_select; /* currently selected param for dai link */
  1024. /* Dynamic PCM BE runtime data */
  1025. struct snd_soc_dpcm_runtime dpcm[2];
  1026. int fe_compr;
  1027. long pmdown_time;
  1028. /* runtime devices */
  1029. struct snd_pcm *pcm;
  1030. struct snd_compr *compr;
  1031. struct snd_soc_dai *codec_dai;
  1032. struct snd_soc_dai *cpu_dai;
  1033. struct snd_soc_dai **codec_dais;
  1034. unsigned int num_codecs;
  1035. struct delayed_work delayed_work;
  1036. #ifdef CONFIG_DEBUG_FS
  1037. struct dentry *debugfs_dpcm_root;
  1038. #endif
  1039. unsigned int num; /* 0-based and monotonic increasing */
  1040. struct list_head list; /* rtd list of the soc card */
  1041. struct list_head component_list; /* list of connected components */
  1042. /* bit field */
  1043. unsigned int dev_registered:1;
  1044. unsigned int pop_wait:1;
  1045. };
  1046. #define for_each_rtd_codec_dai(rtd, i, dai)\
  1047. for ((i) = 0; \
  1048. ((i) < rtd->num_codecs) && ((dai) = rtd->codec_dais[i]); \
  1049. (i)++)
  1050. #define for_each_rtd_codec_dai_rollback(rtd, i, dai) \
  1051. for (; ((i--) >= 0) && ((dai) = rtd->codec_dais[i]);)
  1052. /* mixer control */
  1053. struct soc_mixer_control {
  1054. int min, max, platform_max;
  1055. int reg, rreg;
  1056. unsigned int shift, rshift;
  1057. unsigned int sign_bit;
  1058. unsigned int invert:1;
  1059. unsigned int autodisable:1;
  1060. struct snd_soc_dobj dobj;
  1061. };
  1062. struct soc_bytes {
  1063. int base;
  1064. int num_regs;
  1065. u32 mask;
  1066. };
  1067. struct soc_bytes_ext {
  1068. int max;
  1069. struct snd_soc_dobj dobj;
  1070. /* used for TLV byte control */
  1071. int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
  1072. unsigned int size);
  1073. int (*put)(struct snd_kcontrol *kcontrol, const unsigned int __user *bytes,
  1074. unsigned int size);
  1075. };
  1076. /* multi register control */
  1077. struct soc_mreg_control {
  1078. long min, max;
  1079. unsigned int regbase, regcount, nbits, invert;
  1080. };
  1081. /* enumerated kcontrol */
  1082. struct soc_enum {
  1083. int reg;
  1084. unsigned char shift_l;
  1085. unsigned char shift_r;
  1086. unsigned int items;
  1087. unsigned int mask;
  1088. const char * const *texts;
  1089. const unsigned int *values;
  1090. unsigned int autodisable:1;
  1091. struct snd_soc_dobj dobj;
  1092. };
  1093. /**
  1094. * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
  1095. * embedded in
  1096. * @dapm: The DAPM context to cast to the component
  1097. *
  1098. * This function must only be used on DAPM contexts that are known to be part of
  1099. * a component (e.g. in a component driver). Otherwise the behavior is
  1100. * undefined.
  1101. */
  1102. static inline struct snd_soc_component *snd_soc_dapm_to_component(
  1103. struct snd_soc_dapm_context *dapm)
  1104. {
  1105. return container_of(dapm, struct snd_soc_component, dapm);
  1106. }
  1107. /**
  1108. * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
  1109. * component
  1110. * @component: The component for which to get the DAPM context
  1111. */
  1112. static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
  1113. struct snd_soc_component *component)
  1114. {
  1115. return &component->dapm;
  1116. }
  1117. /**
  1118. * snd_soc_component_init_bias_level() - Initialize COMPONENT DAPM bias level
  1119. * @component: The COMPONENT for which to initialize the DAPM bias level
  1120. * @level: The DAPM level to initialize to
  1121. *
  1122. * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level().
  1123. */
  1124. static inline void
  1125. snd_soc_component_init_bias_level(struct snd_soc_component *component,
  1126. enum snd_soc_bias_level level)
  1127. {
  1128. snd_soc_dapm_init_bias_level(
  1129. snd_soc_component_get_dapm(component), level);
  1130. }
  1131. /**
  1132. * snd_soc_component_get_bias_level() - Get current COMPONENT DAPM bias level
  1133. * @component: The COMPONENT for which to get the DAPM bias level
  1134. *
  1135. * Returns: The current DAPM bias level of the COMPONENT.
  1136. */
  1137. static inline enum snd_soc_bias_level
  1138. snd_soc_component_get_bias_level(struct snd_soc_component *component)
  1139. {
  1140. return snd_soc_dapm_get_bias_level(
  1141. snd_soc_component_get_dapm(component));
  1142. }
  1143. /**
  1144. * snd_soc_component_force_bias_level() - Set the COMPONENT DAPM bias level
  1145. * @component: The COMPONENT for which to set the level
  1146. * @level: The level to set to
  1147. *
  1148. * Forces the COMPONENT bias level to a specific state. See
  1149. * snd_soc_dapm_force_bias_level().
  1150. */
  1151. static inline int
  1152. snd_soc_component_force_bias_level(struct snd_soc_component *component,
  1153. enum snd_soc_bias_level level)
  1154. {
  1155. return snd_soc_dapm_force_bias_level(
  1156. snd_soc_component_get_dapm(component),
  1157. level);
  1158. }
  1159. /**
  1160. * snd_soc_dapm_kcontrol_component() - Returns the component associated to a kcontrol
  1161. * @kcontrol: The kcontrol
  1162. *
  1163. * This function must only be used on DAPM contexts that are known to be part of
  1164. * a COMPONENT (e.g. in a COMPONENT driver). Otherwise the behavior is undefined.
  1165. */
  1166. static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
  1167. struct snd_kcontrol *kcontrol)
  1168. {
  1169. return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
  1170. }
  1171. /**
  1172. * snd_soc_component_cache_sync() - Sync the register cache with the hardware
  1173. * @component: COMPONENT to sync
  1174. *
  1175. * Note: This function will call regcache_sync()
  1176. */
  1177. static inline int snd_soc_component_cache_sync(
  1178. struct snd_soc_component *component)
  1179. {
  1180. return regcache_sync(component->regmap);
  1181. }
  1182. /* component IO */
  1183. int snd_soc_component_read(struct snd_soc_component *component,
  1184. unsigned int reg, unsigned int *val);
  1185. unsigned int snd_soc_component_read32(struct snd_soc_component *component,
  1186. unsigned int reg);
  1187. int snd_soc_component_write(struct snd_soc_component *component,
  1188. unsigned int reg, unsigned int val);
  1189. int snd_soc_component_update_bits(struct snd_soc_component *component,
  1190. unsigned int reg, unsigned int mask, unsigned int val);
  1191. int snd_soc_component_update_bits_async(struct snd_soc_component *component,
  1192. unsigned int reg, unsigned int mask, unsigned int val);
  1193. void snd_soc_component_async_complete(struct snd_soc_component *component);
  1194. int snd_soc_component_test_bits(struct snd_soc_component *component,
  1195. unsigned int reg, unsigned int mask, unsigned int value);
  1196. /* component wide operations */
  1197. int snd_soc_component_set_sysclk(struct snd_soc_component *component,
  1198. int clk_id, int source, unsigned int freq, int dir);
  1199. int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
  1200. int source, unsigned int freq_in,
  1201. unsigned int freq_out);
  1202. int snd_soc_component_set_jack(struct snd_soc_component *component,
  1203. struct snd_soc_jack *jack, void *data);
  1204. #ifdef CONFIG_REGMAP
  1205. void snd_soc_component_init_regmap(struct snd_soc_component *component,
  1206. struct regmap *regmap);
  1207. void snd_soc_component_exit_regmap(struct snd_soc_component *component);
  1208. #endif
  1209. /* device driver data */
  1210. static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
  1211. void *data)
  1212. {
  1213. card->drvdata = data;
  1214. }
  1215. static inline void *snd_soc_card_get_drvdata(struct snd_soc_card *card)
  1216. {
  1217. return card->drvdata;
  1218. }
  1219. static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
  1220. void *data)
  1221. {
  1222. dev_set_drvdata(c->dev, data);
  1223. }
  1224. static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
  1225. {
  1226. return dev_get_drvdata(c->dev);
  1227. }
  1228. static inline void snd_soc_initialize_card_lists(struct snd_soc_card *card)
  1229. {
  1230. INIT_LIST_HEAD(&card->widgets);
  1231. INIT_LIST_HEAD(&card->paths);
  1232. INIT_LIST_HEAD(&card->dapm_list);
  1233. INIT_LIST_HEAD(&card->aux_comp_list);
  1234. INIT_LIST_HEAD(&card->component_dev_list);
  1235. INIT_LIST_HEAD(&card->list);
  1236. }
  1237. static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)
  1238. {
  1239. if (mc->reg == mc->rreg && mc->shift == mc->rshift)
  1240. return 0;
  1241. /*
  1242. * mc->reg == mc->rreg && mc->shift != mc->rshift, or
  1243. * mc->reg != mc->rreg means that the control is
  1244. * stereo (bits in one register or in two registers)
  1245. */
  1246. return 1;
  1247. }
  1248. static inline unsigned int snd_soc_enum_val_to_item(struct soc_enum *e,
  1249. unsigned int val)
  1250. {
  1251. unsigned int i;
  1252. if (!e->values)
  1253. return val;
  1254. for (i = 0; i < e->items; i++)
  1255. if (val == e->values[i])
  1256. return i;
  1257. return 0;
  1258. }
  1259. static inline unsigned int snd_soc_enum_item_to_val(struct soc_enum *e,
  1260. unsigned int item)
  1261. {
  1262. if (!e->values)
  1263. return item;
  1264. return e->values[item];
  1265. }
  1266. static inline bool snd_soc_component_is_active(
  1267. struct snd_soc_component *component)
  1268. {
  1269. return component->active != 0;
  1270. }
  1271. /**
  1272. * snd_soc_kcontrol_component() - Returns the component that registered the
  1273. * control
  1274. * @kcontrol: The control for which to get the component
  1275. *
  1276. * Note: This function will work correctly if the control has been registered
  1277. * for a component. With snd_soc_add_codec_controls() or via table based
  1278. * setup for either a CODEC or component driver. Otherwise the behavior is
  1279. * undefined.
  1280. */
  1281. static inline struct snd_soc_component *snd_soc_kcontrol_component(
  1282. struct snd_kcontrol *kcontrol)
  1283. {
  1284. return snd_kcontrol_chip(kcontrol);
  1285. }
  1286. int snd_soc_util_init(void);
  1287. void snd_soc_util_exit(void);
  1288. int snd_soc_of_parse_card_name(struct snd_soc_card *card,
  1289. const char *propname);
  1290. int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
  1291. const char *propname);
  1292. int snd_soc_of_get_slot_mask(struct device_node *np,
  1293. const char *prop_name,
  1294. unsigned int *mask);
  1295. int snd_soc_of_parse_tdm_slot(struct device_node *np,
  1296. unsigned int *tx_mask,
  1297. unsigned int *rx_mask,
  1298. unsigned int *slots,
  1299. unsigned int *slot_width);
  1300. void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
  1301. struct snd_soc_codec_conf *codec_conf,
  1302. struct device_node *of_node,
  1303. const char *propname);
  1304. int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
  1305. const char *propname);
  1306. unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
  1307. const char *prefix,
  1308. struct device_node **bitclkmaster,
  1309. struct device_node **framemaster);
  1310. int snd_soc_get_dai_id(struct device_node *ep);
  1311. int snd_soc_get_dai_name(struct of_phandle_args *args,
  1312. const char **dai_name);
  1313. int snd_soc_of_get_dai_name(struct device_node *of_node,
  1314. const char **dai_name);
  1315. int snd_soc_of_get_dai_link_codecs(struct device *dev,
  1316. struct device_node *of_node,
  1317. struct snd_soc_dai_link *dai_link);
  1318. void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link);
  1319. int snd_soc_add_dai_link(struct snd_soc_card *card,
  1320. struct snd_soc_dai_link *dai_link);
  1321. void snd_soc_remove_dai_link(struct snd_soc_card *card,
  1322. struct snd_soc_dai_link *dai_link);
  1323. struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card,
  1324. int id, const char *name,
  1325. const char *stream_name);
  1326. int snd_soc_register_dai(struct snd_soc_component *component,
  1327. struct snd_soc_dai_driver *dai_drv);
  1328. struct snd_soc_dai *snd_soc_find_dai(
  1329. const struct snd_soc_dai_link_component *dlc);
  1330. #include <sound/soc-dai.h>
  1331. static inline
  1332. struct snd_soc_dai *snd_soc_card_get_codec_dai(struct snd_soc_card *card,
  1333. const char *dai_name)
  1334. {
  1335. struct snd_soc_pcm_runtime *rtd;
  1336. list_for_each_entry(rtd, &card->rtd_list, list) {
  1337. if (!strcmp(rtd->codec_dai->name, dai_name))
  1338. return rtd->codec_dai;
  1339. }
  1340. return NULL;
  1341. }
  1342. #ifdef CONFIG_DEBUG_FS
  1343. extern struct dentry *snd_soc_debugfs_root;
  1344. #endif
  1345. extern const struct dev_pm_ops snd_soc_pm_ops;
  1346. /* Helper functions */
  1347. static inline void snd_soc_dapm_mutex_lock(struct snd_soc_dapm_context *dapm)
  1348. {
  1349. mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
  1350. }
  1351. static inline void snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm)
  1352. {
  1353. mutex_unlock(&dapm->card->dapm_mutex);
  1354. }
  1355. int snd_soc_component_enable_pin(struct snd_soc_component *component,
  1356. const char *pin);
  1357. int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
  1358. const char *pin);
  1359. int snd_soc_component_disable_pin(struct snd_soc_component *component,
  1360. const char *pin);
  1361. int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
  1362. const char *pin);
  1363. int snd_soc_component_nc_pin(struct snd_soc_component *component,
  1364. const char *pin);
  1365. int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
  1366. const char *pin);
  1367. int snd_soc_component_get_pin_status(struct snd_soc_component *component,
  1368. const char *pin);
  1369. int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
  1370. const char *pin);
  1371. int snd_soc_component_force_enable_pin_unlocked(
  1372. struct snd_soc_component *component,
  1373. const char *pin);
  1374. #endif