soc.h 57 KB

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