soc.h 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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_SINGLE_VALUE(xreg, xshift, xmax, xinvert, xautodisable) \
  37. SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert, xautodisable)
  38. #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
  39. ((unsigned long)&(struct soc_mixer_control) \
  40. {.reg = xreg, .max = xmax, .platform_max = xmax, .invert = xinvert})
  41. #define SOC_DOUBLE_R_VALUE(xlreg, xrreg, xshift, xmax, xinvert) \
  42. ((unsigned long)&(struct soc_mixer_control) \
  43. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  44. .max = xmax, .platform_max = xmax, .invert = xinvert})
  45. #define SOC_DOUBLE_R_S_VALUE(xlreg, xrreg, xshift, xmin, xmax, xsign_bit, xinvert) \
  46. ((unsigned long)&(struct soc_mixer_control) \
  47. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  48. .max = xmax, .min = xmin, .platform_max = xmax, .sign_bit = xsign_bit, \
  49. .invert = xinvert})
  50. #define SOC_DOUBLE_R_RANGE_VALUE(xlreg, xrreg, xshift, xmin, xmax, xinvert) \
  51. ((unsigned long)&(struct soc_mixer_control) \
  52. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  53. .min = xmin, .max = xmax, .platform_max = xmax, .invert = xinvert})
  54. #define SOC_SINGLE(xname, reg, shift, max, invert) \
  55. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  56. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  57. .put = snd_soc_put_volsw, \
  58. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  59. #define SOC_SINGLE_RANGE(xname, xreg, xshift, xmin, xmax, xinvert) \
  60. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  61. .info = snd_soc_info_volsw_range, .get = snd_soc_get_volsw_range, \
  62. .put = snd_soc_put_volsw_range, \
  63. .private_value = (unsigned long)&(struct soc_mixer_control) \
  64. {.reg = xreg, .rreg = xreg, .shift = xshift, \
  65. .rshift = xshift, .min = xmin, .max = xmax, \
  66. .platform_max = xmax, .invert = xinvert} }
  67. #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
  68. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  69. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  70. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  71. .tlv.p = (tlv_array), \
  72. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  73. .put = snd_soc_put_volsw, \
  74. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  75. #define SOC_SINGLE_SX_TLV(xname, xreg, xshift, xmin, xmax, tlv_array) \
  76. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  77. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  78. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  79. .tlv.p = (tlv_array),\
  80. .info = snd_soc_info_volsw, \
  81. .get = snd_soc_get_volsw_sx,\
  82. .put = snd_soc_put_volsw_sx, \
  83. .private_value = (unsigned long)&(struct soc_mixer_control) \
  84. {.reg = xreg, .rreg = xreg, \
  85. .shift = xshift, .rshift = xshift, \
  86. .max = xmax, .min = xmin} }
  87. #define SOC_SINGLE_RANGE_TLV(xname, xreg, xshift, xmin, xmax, xinvert, tlv_array) \
  88. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  89. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  90. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  91. .tlv.p = (tlv_array), \
  92. .info = snd_soc_info_volsw_range, \
  93. .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
  94. .private_value = (unsigned long)&(struct soc_mixer_control) \
  95. {.reg = xreg, .rreg = xreg, .shift = xshift, \
  96. .rshift = xshift, .min = xmin, .max = xmax, \
  97. .platform_max = xmax, .invert = xinvert} }
  98. #define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
  99. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  100. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  101. .put = snd_soc_put_volsw, \
  102. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  103. max, invert, 0) }
  104. #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
  105. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  106. .info = snd_soc_info_volsw, \
  107. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  108. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  109. xmax, xinvert) }
  110. #define SOC_DOUBLE_R_RANGE(xname, reg_left, reg_right, xshift, xmin, \
  111. xmax, xinvert) \
  112. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  113. .info = snd_soc_info_volsw_range, \
  114. .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
  115. .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \
  116. xshift, xmin, xmax, xinvert) }
  117. #define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
  118. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  119. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  120. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  121. .tlv.p = (tlv_array), \
  122. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  123. .put = snd_soc_put_volsw, \
  124. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  125. max, invert, 0) }
  126. #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
  127. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  128. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  129. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  130. .tlv.p = (tlv_array), \
  131. .info = snd_soc_info_volsw, \
  132. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  133. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  134. xmax, xinvert) }
  135. #define SOC_DOUBLE_R_RANGE_TLV(xname, reg_left, reg_right, xshift, xmin, \
  136. 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_range, \
  142. .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
  143. .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \
  144. xshift, xmin, xmax, xinvert) }
  145. #define SOC_DOUBLE_R_SX_TLV(xname, xreg, xrreg, xshift, xmin, xmax, tlv_array) \
  146. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  147. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  148. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  149. .tlv.p = (tlv_array), \
  150. .info = snd_soc_info_volsw, \
  151. .get = snd_soc_get_volsw_sx, \
  152. .put = snd_soc_put_volsw_sx, \
  153. .private_value = (unsigned long)&(struct soc_mixer_control) \
  154. {.reg = xreg, .rreg = xrreg, \
  155. .shift = xshift, .rshift = xshift, \
  156. .max = xmax, .min = xmin} }
  157. #define SOC_DOUBLE_R_S_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \
  158. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  159. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  160. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  161. .tlv.p = (tlv_array), \
  162. .info = snd_soc_info_volsw, \
  163. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  164. .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \
  165. xmin, xmax, xsign_bit, xinvert) }
  166. #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  167. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  168. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  169. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  170. .tlv.p = (tlv_array), \
  171. .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
  172. .put = snd_soc_put_volsw_s8, \
  173. .private_value = (unsigned long)&(struct soc_mixer_control) \
  174. {.reg = xreg, .min = xmin, .max = xmax, \
  175. .platform_max = xmax} }
  176. #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xitems, xtexts) \
  177. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  178. .items = xitems, .texts = xtexts, \
  179. .mask = xitems ? roundup_pow_of_two(xitems) - 1 : 0}
  180. #define SOC_ENUM_SINGLE(xreg, xshift, xitems, xtexts) \
  181. SOC_ENUM_DOUBLE(xreg, xshift, xshift, xitems, xtexts)
  182. #define SOC_ENUM_SINGLE_EXT(xitems, xtexts) \
  183. { .items = xitems, .texts = xtexts }
  184. #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xitems, xtexts, xvalues) \
  185. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  186. .mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues}
  187. #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xnitmes, xtexts, xvalues) \
  188. SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xnitmes, xtexts, xvalues)
  189. #define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \
  190. SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts)
  191. #define SOC_ENUM(xname, xenum) \
  192. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  193. .info = snd_soc_info_enum_double, \
  194. .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
  195. .private_value = (unsigned long)&xenum }
  196. #define SOC_VALUE_ENUM(xname, xenum) \
  197. SOC_ENUM(xname, xenum)
  198. #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
  199. xhandler_get, xhandler_put) \
  200. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  201. .info = snd_soc_info_volsw, \
  202. .get = xhandler_get, .put = xhandler_put, \
  203. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) }
  204. #define SOC_DOUBLE_EXT(xname, reg, shift_left, shift_right, max, invert,\
  205. xhandler_get, xhandler_put) \
  206. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  207. .info = snd_soc_info_volsw, \
  208. .get = xhandler_get, .put = xhandler_put, \
  209. .private_value = \
  210. SOC_DOUBLE_VALUE(reg, shift_left, shift_right, max, invert, 0) }
  211. #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
  212. xhandler_get, xhandler_put, tlv_array) \
  213. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  214. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  215. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  216. .tlv.p = (tlv_array), \
  217. .info = snd_soc_info_volsw, \
  218. .get = xhandler_get, .put = xhandler_put, \
  219. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) }
  220. #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
  221. xhandler_get, xhandler_put, tlv_array) \
  222. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  223. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  224. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  225. .tlv.p = (tlv_array), \
  226. .info = snd_soc_info_volsw, \
  227. .get = xhandler_get, .put = xhandler_put, \
  228. .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
  229. xmax, xinvert, 0) }
  230. #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\
  231. xhandler_get, xhandler_put, tlv_array) \
  232. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  233. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  234. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  235. .tlv.p = (tlv_array), \
  236. .info = snd_soc_info_volsw, \
  237. .get = xhandler_get, .put = xhandler_put, \
  238. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  239. xmax, xinvert) }
  240. #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
  241. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  242. .info = snd_soc_info_bool_ext, \
  243. .get = xhandler_get, .put = xhandler_put, \
  244. .private_value = xdata }
  245. #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
  246. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  247. .info = snd_soc_info_enum_double, \
  248. .get = xhandler_get, .put = xhandler_put, \
  249. .private_value = (unsigned long)&xenum }
  250. #define SND_SOC_BYTES(xname, xbase, xregs) \
  251. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  252. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  253. .put = snd_soc_bytes_put, .private_value = \
  254. ((unsigned long)&(struct soc_bytes) \
  255. {.base = xbase, .num_regs = xregs }) }
  256. #define SND_SOC_BYTES_MASK(xname, xbase, xregs, xmask) \
  257. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  258. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  259. .put = snd_soc_bytes_put, .private_value = \
  260. ((unsigned long)&(struct soc_bytes) \
  261. {.base = xbase, .num_regs = xregs, \
  262. .mask = xmask }) }
  263. #define SND_SOC_BYTES_EXT(xname, xcount, xhandler_get, xhandler_put) \
  264. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  265. .info = snd_soc_bytes_info_ext, \
  266. .get = xhandler_get, .put = xhandler_put, \
  267. .private_value = (unsigned long)&(struct soc_bytes_ext) \
  268. {.max = xcount} }
  269. #define SOC_SINGLE_XR_SX(xname, xregbase, xregcount, xnbits, \
  270. xmin, xmax, xinvert) \
  271. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  272. .info = snd_soc_info_xr_sx, .get = snd_soc_get_xr_sx, \
  273. .put = snd_soc_put_xr_sx, \
  274. .private_value = (unsigned long)&(struct soc_mreg_control) \
  275. {.regbase = xregbase, .regcount = xregcount, .nbits = xnbits, \
  276. .invert = xinvert, .min = xmin, .max = xmax} }
  277. #define SOC_SINGLE_STROBE(xname, xreg, xshift, xinvert) \
  278. SOC_SINGLE_EXT(xname, xreg, xshift, 1, xinvert, \
  279. snd_soc_get_strobe, snd_soc_put_strobe)
  280. /*
  281. * Simplified versions of above macros, declaring a struct and calculating
  282. * ARRAY_SIZE internally
  283. */
  284. #define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \
  285. const struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
  286. ARRAY_SIZE(xtexts), xtexts)
  287. #define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \
  288. SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
  289. #define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \
  290. const struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts)
  291. #define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \
  292. const struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \
  293. ARRAY_SIZE(xtexts), xtexts, xvalues)
  294. #define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
  295. SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
  296. #define SOC_ENUM_SINGLE_VIRT_DECL(name, xtexts) \
  297. const struct soc_enum name = SOC_ENUM_SINGLE_VIRT(ARRAY_SIZE(xtexts), xtexts)
  298. /*
  299. * Component probe and remove ordering levels for components with runtime
  300. * dependencies.
  301. */
  302. #define SND_SOC_COMP_ORDER_FIRST -2
  303. #define SND_SOC_COMP_ORDER_EARLY -1
  304. #define SND_SOC_COMP_ORDER_NORMAL 0
  305. #define SND_SOC_COMP_ORDER_LATE 1
  306. #define SND_SOC_COMP_ORDER_LAST 2
  307. /*
  308. * Bias levels
  309. *
  310. * @ON: Bias is fully on for audio playback and capture operations.
  311. * @PREPARE: Prepare for audio operations. Called before DAPM switching for
  312. * stream start and stop operations.
  313. * @STANDBY: Low power standby state when no playback/capture operations are
  314. * in progress. NOTE: The transition time between STANDBY and ON
  315. * should be as fast as possible and no longer than 10ms.
  316. * @OFF: Power Off. No restrictions on transition times.
  317. */
  318. enum snd_soc_bias_level {
  319. SND_SOC_BIAS_OFF = 0,
  320. SND_SOC_BIAS_STANDBY = 1,
  321. SND_SOC_BIAS_PREPARE = 2,
  322. SND_SOC_BIAS_ON = 3,
  323. };
  324. struct device_node;
  325. struct snd_jack;
  326. struct snd_soc_card;
  327. struct snd_soc_pcm_stream;
  328. struct snd_soc_ops;
  329. struct snd_soc_pcm_runtime;
  330. struct snd_soc_dai;
  331. struct snd_soc_dai_driver;
  332. struct snd_soc_platform;
  333. struct snd_soc_dai_link;
  334. struct snd_soc_platform_driver;
  335. struct snd_soc_codec;
  336. struct snd_soc_codec_driver;
  337. struct snd_soc_component;
  338. struct snd_soc_component_driver;
  339. struct soc_enum;
  340. struct snd_soc_jack;
  341. struct snd_soc_jack_zone;
  342. struct snd_soc_jack_pin;
  343. #include <sound/soc-dapm.h>
  344. #include <sound/soc-dpcm.h>
  345. struct snd_soc_jack_gpio;
  346. typedef int (*hw_write_t)(void *,const char* ,int);
  347. extern struct snd_ac97_bus_ops *soc_ac97_ops;
  348. enum snd_soc_pcm_subclass {
  349. SND_SOC_PCM_CLASS_PCM = 0,
  350. SND_SOC_PCM_CLASS_BE = 1,
  351. };
  352. enum snd_soc_card_subclass {
  353. SND_SOC_CARD_CLASS_INIT = 0,
  354. SND_SOC_CARD_CLASS_RUNTIME = 1,
  355. };
  356. int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
  357. int source, unsigned int freq, int dir);
  358. int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
  359. unsigned int freq_in, unsigned int freq_out);
  360. int snd_soc_register_card(struct snd_soc_card *card);
  361. int snd_soc_unregister_card(struct snd_soc_card *card);
  362. int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
  363. int snd_soc_suspend(struct device *dev);
  364. int snd_soc_resume(struct device *dev);
  365. int snd_soc_poweroff(struct device *dev);
  366. int snd_soc_register_platform(struct device *dev,
  367. const struct snd_soc_platform_driver *platform_drv);
  368. void snd_soc_unregister_platform(struct device *dev);
  369. int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
  370. const struct snd_soc_platform_driver *platform_drv);
  371. void snd_soc_remove_platform(struct snd_soc_platform *platform);
  372. struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev);
  373. int snd_soc_register_codec(struct device *dev,
  374. const struct snd_soc_codec_driver *codec_drv,
  375. struct snd_soc_dai_driver *dai_drv, int num_dai);
  376. void snd_soc_unregister_codec(struct device *dev);
  377. int snd_soc_register_component(struct device *dev,
  378. const struct snd_soc_component_driver *cmpnt_drv,
  379. struct snd_soc_dai_driver *dai_drv, int num_dai);
  380. int devm_snd_soc_register_component(struct device *dev,
  381. const struct snd_soc_component_driver *cmpnt_drv,
  382. struct snd_soc_dai_driver *dai_drv, int num_dai);
  383. void snd_soc_unregister_component(struct device *dev);
  384. int snd_soc_cache_sync(struct snd_soc_codec *codec);
  385. int snd_soc_cache_init(struct snd_soc_codec *codec);
  386. int snd_soc_cache_exit(struct snd_soc_codec *codec);
  387. int snd_soc_cache_write(struct snd_soc_codec *codec,
  388. unsigned int reg, unsigned int value);
  389. int snd_soc_cache_read(struct snd_soc_codec *codec,
  390. unsigned int reg, unsigned int *value);
  391. int snd_soc_platform_read(struct snd_soc_platform *platform,
  392. unsigned int reg);
  393. int snd_soc_platform_write(struct snd_soc_platform *platform,
  394. unsigned int reg, unsigned int val);
  395. int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
  396. int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num);
  397. struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
  398. const char *dai_link, int stream);
  399. struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
  400. const char *dai_link);
  401. bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd);
  402. void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream);
  403. void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream);
  404. /* Utility functions to get clock rates from various things */
  405. int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
  406. int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
  407. int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
  408. int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);
  409. /* set runtime hw params */
  410. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  411. const struct snd_pcm_hardware *hw);
  412. int snd_soc_platform_trigger(struct snd_pcm_substream *substream,
  413. int cmd, struct snd_soc_platform *platform);
  414. /* Jack reporting */
  415. int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type,
  416. struct snd_soc_jack *jack);
  417. void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
  418. int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
  419. struct snd_soc_jack_pin *pins);
  420. void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
  421. struct notifier_block *nb);
  422. void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
  423. struct notifier_block *nb);
  424. int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
  425. struct snd_soc_jack_zone *zones);
  426. int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
  427. #ifdef CONFIG_GPIOLIB
  428. int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  429. struct snd_soc_jack_gpio *gpios);
  430. void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  431. struct snd_soc_jack_gpio *gpios);
  432. #else
  433. static inline int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  434. struct snd_soc_jack_gpio *gpios)
  435. {
  436. return 0;
  437. }
  438. static inline void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  439. struct snd_soc_jack_gpio *gpios)
  440. {
  441. }
  442. #endif
  443. /* codec register bit access */
  444. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned int reg,
  445. unsigned int mask, unsigned int value);
  446. int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
  447. unsigned int reg, unsigned int mask,
  448. unsigned int value);
  449. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned int reg,
  450. unsigned int mask, unsigned int value);
  451. int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  452. struct snd_ac97_bus_ops *ops, int num);
  453. void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
  454. int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops);
  455. int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
  456. struct platform_device *pdev);
  457. /*
  458. *Controls
  459. */
  460. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  461. void *data, const char *long_name,
  462. const char *prefix);
  463. struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
  464. const char *name);
  465. int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
  466. const struct snd_kcontrol_new *controls, int num_controls);
  467. int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
  468. const struct snd_kcontrol_new *controls, int num_controls);
  469. int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
  470. const struct snd_kcontrol_new *controls, int num_controls);
  471. int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
  472. const struct snd_kcontrol_new *controls, int num_controls);
  473. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  474. struct snd_ctl_elem_info *uinfo);
  475. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  476. struct snd_ctl_elem_value *ucontrol);
  477. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  478. struct snd_ctl_elem_value *ucontrol);
  479. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  480. struct snd_ctl_elem_info *uinfo);
  481. #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
  482. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  483. struct snd_ctl_elem_value *ucontrol);
  484. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  485. struct snd_ctl_elem_value *ucontrol);
  486. #define snd_soc_get_volsw_2r snd_soc_get_volsw
  487. #define snd_soc_put_volsw_2r snd_soc_put_volsw
  488. int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
  489. struct snd_ctl_elem_value *ucontrol);
  490. int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
  491. struct snd_ctl_elem_value *ucontrol);
  492. int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
  493. struct snd_ctl_elem_info *uinfo);
  494. int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
  495. struct snd_ctl_elem_value *ucontrol);
  496. int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
  497. struct snd_ctl_elem_value *ucontrol);
  498. int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
  499. struct snd_ctl_elem_info *uinfo);
  500. int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
  501. struct snd_ctl_elem_value *ucontrol);
  502. int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
  503. struct snd_ctl_elem_value *ucontrol);
  504. int snd_soc_limit_volume(struct snd_soc_codec *codec,
  505. const char *name, int max);
  506. int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
  507. struct snd_ctl_elem_info *uinfo);
  508. int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
  509. struct snd_ctl_elem_value *ucontrol);
  510. int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
  511. struct snd_ctl_elem_value *ucontrol);
  512. int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,
  513. struct snd_ctl_elem_info *ucontrol);
  514. int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
  515. struct snd_ctl_elem_info *uinfo);
  516. int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
  517. struct snd_ctl_elem_value *ucontrol);
  518. int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
  519. struct snd_ctl_elem_value *ucontrol);
  520. int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
  521. struct snd_ctl_elem_value *ucontrol);
  522. int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
  523. struct snd_ctl_elem_value *ucontrol);
  524. /**
  525. * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
  526. *
  527. * @pin: name of the pin to update
  528. * @mask: bits to check for in reported jack status
  529. * @invert: if non-zero then pin is enabled when status is not reported
  530. */
  531. struct snd_soc_jack_pin {
  532. struct list_head list;
  533. const char *pin;
  534. int mask;
  535. bool invert;
  536. };
  537. /**
  538. * struct snd_soc_jack_zone - Describes voltage zones of jack detection
  539. *
  540. * @min_mv: start voltage in mv
  541. * @max_mv: end voltage in mv
  542. * @jack_type: type of jack that is expected for this voltage
  543. * @debounce_time: debounce_time for jack, codec driver should wait for this
  544. * duration before reading the adc for voltages
  545. * @:list: list container
  546. */
  547. struct snd_soc_jack_zone {
  548. unsigned int min_mv;
  549. unsigned int max_mv;
  550. unsigned int jack_type;
  551. unsigned int debounce_time;
  552. struct list_head list;
  553. };
  554. /**
  555. * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
  556. *
  557. * @gpio: gpio number
  558. * @name: gpio name
  559. * @report: value to report when jack detected
  560. * @invert: report presence in low state
  561. * @debouce_time: debouce time in ms
  562. * @wake: enable as wake source
  563. * @jack_status_check: callback function which overrides the detection
  564. * to provide more complex checks (eg, reading an
  565. * ADC).
  566. */
  567. struct snd_soc_jack_gpio {
  568. unsigned int gpio;
  569. const char *name;
  570. int report;
  571. int invert;
  572. int debounce_time;
  573. bool wake;
  574. struct snd_soc_jack *jack;
  575. struct delayed_work work;
  576. void *data;
  577. int (*jack_status_check)(void *data);
  578. };
  579. struct snd_soc_jack {
  580. struct mutex mutex;
  581. struct snd_jack *jack;
  582. struct snd_soc_codec *codec;
  583. struct list_head pins;
  584. int status;
  585. struct blocking_notifier_head notifier;
  586. struct list_head jack_zones;
  587. };
  588. /* SoC PCM stream information */
  589. struct snd_soc_pcm_stream {
  590. const char *stream_name;
  591. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  592. unsigned int rates; /* SNDRV_PCM_RATE_* */
  593. unsigned int rate_min; /* min rate */
  594. unsigned int rate_max; /* max rate */
  595. unsigned int channels_min; /* min channels */
  596. unsigned int channels_max; /* max channels */
  597. unsigned int sig_bits; /* number of bits of content */
  598. };
  599. /* SoC audio ops */
  600. struct snd_soc_ops {
  601. int (*startup)(struct snd_pcm_substream *);
  602. void (*shutdown)(struct snd_pcm_substream *);
  603. int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
  604. int (*hw_free)(struct snd_pcm_substream *);
  605. int (*prepare)(struct snd_pcm_substream *);
  606. int (*trigger)(struct snd_pcm_substream *, int);
  607. };
  608. struct snd_soc_compr_ops {
  609. int (*startup)(struct snd_compr_stream *);
  610. void (*shutdown)(struct snd_compr_stream *);
  611. int (*set_params)(struct snd_compr_stream *);
  612. int (*trigger)(struct snd_compr_stream *);
  613. };
  614. /* component interface */
  615. struct snd_soc_component_driver {
  616. const char *name;
  617. /* DT */
  618. int (*of_xlate_dai_name)(struct snd_soc_component *component,
  619. struct of_phandle_args *args,
  620. const char **dai_name);
  621. };
  622. struct snd_soc_component {
  623. const char *name;
  624. int id;
  625. struct device *dev;
  626. unsigned int active;
  627. unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */
  628. unsigned int registered_as_component:1;
  629. struct list_head list;
  630. struct snd_soc_dai_driver *dai_drv;
  631. int num_dai;
  632. const struct snd_soc_component_driver *driver;
  633. struct list_head dai_list;
  634. int (*read)(struct snd_soc_component *, unsigned int, unsigned int *);
  635. int (*write)(struct snd_soc_component *, unsigned int, unsigned int);
  636. struct regmap *regmap;
  637. int val_bytes;
  638. struct mutex io_mutex;
  639. };
  640. /* SoC Audio Codec device */
  641. struct snd_soc_codec {
  642. const char *name;
  643. const char *name_prefix;
  644. int id;
  645. struct device *dev;
  646. const struct snd_soc_codec_driver *driver;
  647. struct mutex mutex;
  648. struct snd_soc_card *card;
  649. struct list_head list;
  650. struct list_head card_list;
  651. /* runtime */
  652. struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
  653. unsigned int cache_bypass:1; /* Suppress access to the cache */
  654. unsigned int suspended:1; /* Codec is in suspend PM state */
  655. unsigned int probed:1; /* Codec has been probed */
  656. unsigned int ac97_registered:1; /* Codec has been AC97 registered */
  657. unsigned int ac97_created:1; /* Codec has been created by SoC */
  658. unsigned int cache_init:1; /* codec cache has been initialized */
  659. u32 cache_only; /* Suppress writes to hardware */
  660. u32 cache_sync; /* Cache needs to be synced to hardware */
  661. /* codec IO */
  662. void *control_data; /* codec control (i2c/3wire) data */
  663. hw_write_t hw_write;
  664. void *reg_cache;
  665. struct mutex cache_rw_mutex;
  666. /* component */
  667. struct snd_soc_component component;
  668. /* dapm */
  669. struct snd_soc_dapm_context dapm;
  670. #ifdef CONFIG_DEBUG_FS
  671. struct dentry *debugfs_codec_root;
  672. struct dentry *debugfs_reg;
  673. #endif
  674. };
  675. /* codec driver */
  676. struct snd_soc_codec_driver {
  677. /* driver ops */
  678. int (*probe)(struct snd_soc_codec *);
  679. int (*remove)(struct snd_soc_codec *);
  680. int (*suspend)(struct snd_soc_codec *);
  681. int (*resume)(struct snd_soc_codec *);
  682. struct snd_soc_component_driver component_driver;
  683. /* Default control and setup, added after probe() is run */
  684. const struct snd_kcontrol_new *controls;
  685. int num_controls;
  686. const struct snd_soc_dapm_widget *dapm_widgets;
  687. int num_dapm_widgets;
  688. const struct snd_soc_dapm_route *dapm_routes;
  689. int num_dapm_routes;
  690. /* codec wide operations */
  691. int (*set_sysclk)(struct snd_soc_codec *codec,
  692. int clk_id, int source, unsigned int freq, int dir);
  693. int (*set_pll)(struct snd_soc_codec *codec, int pll_id, int source,
  694. unsigned int freq_in, unsigned int freq_out);
  695. /* codec IO */
  696. struct regmap *(*get_regmap)(struct device *);
  697. unsigned int (*read)(struct snd_soc_codec *, unsigned int);
  698. int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
  699. unsigned int reg_cache_size;
  700. short reg_cache_step;
  701. short reg_word_size;
  702. const void *reg_cache_default;
  703. /* codec bias level */
  704. int (*set_bias_level)(struct snd_soc_codec *,
  705. enum snd_soc_bias_level level);
  706. bool idle_bias_off;
  707. void (*seq_notifier)(struct snd_soc_dapm_context *,
  708. enum snd_soc_dapm_type, int);
  709. /* codec stream completion event */
  710. int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
  711. bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
  712. /* probe ordering - for components with runtime dependencies */
  713. int probe_order;
  714. int remove_order;
  715. };
  716. /* SoC platform interface */
  717. struct snd_soc_platform_driver {
  718. int (*probe)(struct snd_soc_platform *);
  719. int (*remove)(struct snd_soc_platform *);
  720. int (*suspend)(struct snd_soc_dai *dai);
  721. int (*resume)(struct snd_soc_dai *dai);
  722. struct snd_soc_component_driver component_driver;
  723. /* pcm creation and destruction */
  724. int (*pcm_new)(struct snd_soc_pcm_runtime *);
  725. void (*pcm_free)(struct snd_pcm *);
  726. /* Default control and setup, added after probe() is run */
  727. const struct snd_kcontrol_new *controls;
  728. int num_controls;
  729. const struct snd_soc_dapm_widget *dapm_widgets;
  730. int num_dapm_widgets;
  731. const struct snd_soc_dapm_route *dapm_routes;
  732. int num_dapm_routes;
  733. /*
  734. * For platform caused delay reporting.
  735. * Optional.
  736. */
  737. snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
  738. struct snd_soc_dai *);
  739. /* platform stream pcm ops */
  740. const struct snd_pcm_ops *ops;
  741. /* platform stream compress ops */
  742. const struct snd_compr_ops *compr_ops;
  743. /* platform stream completion event */
  744. int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
  745. /* probe ordering - for components with runtime dependencies */
  746. int probe_order;
  747. int remove_order;
  748. /* platform IO - used for platform DAPM */
  749. unsigned int (*read)(struct snd_soc_platform *, unsigned int);
  750. int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
  751. int (*bespoke_trigger)(struct snd_pcm_substream *, int);
  752. };
  753. struct snd_soc_platform {
  754. const char *name;
  755. int id;
  756. struct device *dev;
  757. const struct snd_soc_platform_driver *driver;
  758. unsigned int suspended:1; /* platform is suspended */
  759. unsigned int probed:1;
  760. struct snd_soc_card *card;
  761. struct list_head list;
  762. struct list_head card_list;
  763. struct snd_soc_component component;
  764. struct snd_soc_dapm_context dapm;
  765. #ifdef CONFIG_DEBUG_FS
  766. struct dentry *debugfs_platform_root;
  767. #endif
  768. };
  769. struct snd_soc_dai_link {
  770. /* config - must be set by machine driver */
  771. const char *name; /* Codec name */
  772. const char *stream_name; /* Stream name */
  773. /*
  774. * You MAY specify the link's CPU-side device, either by device name,
  775. * or by DT/OF node, but not both. If this information is omitted,
  776. * the CPU-side DAI is matched using .cpu_dai_name only, which hence
  777. * must be globally unique. These fields are currently typically used
  778. * only for codec to codec links, or systems using device tree.
  779. */
  780. const char *cpu_name;
  781. const struct device_node *cpu_of_node;
  782. /*
  783. * You MAY specify the DAI name of the CPU DAI. If this information is
  784. * omitted, the CPU-side DAI is matched using .cpu_name/.cpu_of_node
  785. * only, which only works well when that device exposes a single DAI.
  786. */
  787. const char *cpu_dai_name;
  788. /*
  789. * You MUST specify the link's codec, either by device name, or by
  790. * DT/OF node, but not both.
  791. */
  792. const char *codec_name;
  793. const struct device_node *codec_of_node;
  794. /* You MUST specify the DAI name within the codec */
  795. const char *codec_dai_name;
  796. /*
  797. * You MAY specify the link's platform/PCM/DMA driver, either by
  798. * device name, or by DT/OF node, but not both. Some forms of link
  799. * do not need a platform.
  800. */
  801. const char *platform_name;
  802. const struct device_node *platform_of_node;
  803. int be_id; /* optional ID for machine driver BE identification */
  804. const struct snd_soc_pcm_stream *params;
  805. unsigned int dai_fmt; /* format to set on init */
  806. enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */
  807. /* Keep DAI active over suspend */
  808. unsigned int ignore_suspend:1;
  809. /* Symmetry requirements */
  810. unsigned int symmetric_rates:1;
  811. unsigned int symmetric_channels:1;
  812. unsigned int symmetric_samplebits:1;
  813. /* Do not create a PCM for this DAI link (Backend link) */
  814. unsigned int no_pcm:1;
  815. /* This DAI link can route to other DAI links at runtime (Frontend)*/
  816. unsigned int dynamic:1;
  817. /* DPCM capture and Playback support */
  818. unsigned int dpcm_capture:1;
  819. unsigned int dpcm_playback:1;
  820. /* pmdown_time is ignored at stop */
  821. unsigned int ignore_pmdown_time:1;
  822. /* codec/machine specific init - e.g. add machine controls */
  823. int (*init)(struct snd_soc_pcm_runtime *rtd);
  824. /* optional hw_params re-writing for BE and FE sync */
  825. int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
  826. struct snd_pcm_hw_params *params);
  827. /* machine stream operations */
  828. const struct snd_soc_ops *ops;
  829. const struct snd_soc_compr_ops *compr_ops;
  830. /* For unidirectional dai links */
  831. bool playback_only;
  832. bool capture_only;
  833. };
  834. struct snd_soc_codec_conf {
  835. const char *dev_name;
  836. /*
  837. * optional map of kcontrol, widget and path name prefixes that are
  838. * associated per device
  839. */
  840. const char *name_prefix;
  841. };
  842. struct snd_soc_aux_dev {
  843. const char *name; /* Codec name */
  844. const char *codec_name; /* for multi-codec */
  845. /* codec/machine specific init - e.g. add machine controls */
  846. int (*init)(struct snd_soc_dapm_context *dapm);
  847. };
  848. /* SoC card */
  849. struct snd_soc_card {
  850. const char *name;
  851. const char *long_name;
  852. const char *driver_name;
  853. struct device *dev;
  854. struct snd_card *snd_card;
  855. struct module *owner;
  856. struct mutex mutex;
  857. struct mutex dapm_mutex;
  858. bool instantiated;
  859. int (*probe)(struct snd_soc_card *card);
  860. int (*late_probe)(struct snd_soc_card *card);
  861. int (*remove)(struct snd_soc_card *card);
  862. /* the pre and post PM functions are used to do any PM work before and
  863. * after the codec and DAI's do any PM work. */
  864. int (*suspend_pre)(struct snd_soc_card *card);
  865. int (*suspend_post)(struct snd_soc_card *card);
  866. int (*resume_pre)(struct snd_soc_card *card);
  867. int (*resume_post)(struct snd_soc_card *card);
  868. /* callbacks */
  869. int (*set_bias_level)(struct snd_soc_card *,
  870. struct snd_soc_dapm_context *dapm,
  871. enum snd_soc_bias_level level);
  872. int (*set_bias_level_post)(struct snd_soc_card *,
  873. struct snd_soc_dapm_context *dapm,
  874. enum snd_soc_bias_level level);
  875. long pmdown_time;
  876. /* CPU <--> Codec DAI links */
  877. struct snd_soc_dai_link *dai_link;
  878. int num_links;
  879. struct snd_soc_pcm_runtime *rtd;
  880. int num_rtd;
  881. /* optional codec specific configuration */
  882. struct snd_soc_codec_conf *codec_conf;
  883. int num_configs;
  884. /*
  885. * optional auxiliary devices such as amplifiers or codecs with DAI
  886. * link unused
  887. */
  888. struct snd_soc_aux_dev *aux_dev;
  889. int num_aux_devs;
  890. struct snd_soc_pcm_runtime *rtd_aux;
  891. int num_aux_rtd;
  892. const struct snd_kcontrol_new *controls;
  893. int num_controls;
  894. /*
  895. * Card-specific routes and widgets.
  896. */
  897. const struct snd_soc_dapm_widget *dapm_widgets;
  898. int num_dapm_widgets;
  899. const struct snd_soc_dapm_route *dapm_routes;
  900. int num_dapm_routes;
  901. bool fully_routed;
  902. struct work_struct deferred_resume_work;
  903. /* lists of probed devices belonging to this card */
  904. struct list_head codec_dev_list;
  905. struct list_head platform_dev_list;
  906. struct list_head widgets;
  907. struct list_head paths;
  908. struct list_head dapm_list;
  909. struct list_head dapm_dirty;
  910. /* Generic DAPM context for the card */
  911. struct snd_soc_dapm_context dapm;
  912. struct snd_soc_dapm_stats dapm_stats;
  913. struct snd_soc_dapm_update *update;
  914. #ifdef CONFIG_DEBUG_FS
  915. struct dentry *debugfs_card_root;
  916. struct dentry *debugfs_pop_time;
  917. #endif
  918. u32 pop_time;
  919. void *drvdata;
  920. };
  921. /* SoC machine DAI configuration, glues a codec and cpu DAI together */
  922. struct snd_soc_pcm_runtime {
  923. struct device *dev;
  924. struct snd_soc_card *card;
  925. struct snd_soc_dai_link *dai_link;
  926. struct mutex pcm_mutex;
  927. enum snd_soc_pcm_subclass pcm_subclass;
  928. struct snd_pcm_ops ops;
  929. unsigned int dev_registered:1;
  930. /* Dynamic PCM BE runtime data */
  931. struct snd_soc_dpcm_runtime dpcm[2];
  932. int fe_compr;
  933. long pmdown_time;
  934. unsigned char pop_wait:1;
  935. /* runtime devices */
  936. struct snd_pcm *pcm;
  937. struct snd_compr *compr;
  938. struct snd_soc_codec *codec;
  939. struct snd_soc_platform *platform;
  940. struct snd_soc_dai *codec_dai;
  941. struct snd_soc_dai *cpu_dai;
  942. struct delayed_work delayed_work;
  943. #ifdef CONFIG_DEBUG_FS
  944. struct dentry *debugfs_dpcm_root;
  945. struct dentry *debugfs_dpcm_state;
  946. #endif
  947. };
  948. /* mixer control */
  949. struct soc_mixer_control {
  950. int min, max, platform_max;
  951. int reg, rreg;
  952. unsigned int shift, rshift;
  953. unsigned int sign_bit;
  954. unsigned int invert:1;
  955. unsigned int autodisable:1;
  956. };
  957. struct soc_bytes {
  958. int base;
  959. int num_regs;
  960. u32 mask;
  961. };
  962. struct soc_bytes_ext {
  963. int max;
  964. };
  965. /* multi register control */
  966. struct soc_mreg_control {
  967. long min, max;
  968. unsigned int regbase, regcount, nbits, invert;
  969. };
  970. /* enumerated kcontrol */
  971. struct soc_enum {
  972. int reg;
  973. unsigned char shift_l;
  974. unsigned char shift_r;
  975. unsigned int items;
  976. unsigned int mask;
  977. const char * const *texts;
  978. const unsigned int *values;
  979. };
  980. /**
  981. * snd_soc_component_to_codec() - Casts a component to the CODEC it is embedded in
  982. * @component: The component to cast to a CODEC
  983. *
  984. * This function must only be used on components that are known to be CODECs.
  985. * Otherwise the behavior is undefined.
  986. */
  987. static inline struct snd_soc_codec *snd_soc_component_to_codec(
  988. struct snd_soc_component *component)
  989. {
  990. return container_of(component, struct snd_soc_codec, component);
  991. }
  992. /**
  993. * snd_soc_component_to_platform() - Casts a component to the platform it is embedded in
  994. * @component: The component to cast to a platform
  995. *
  996. * This function must only be used on components that are known to be platforms.
  997. * Otherwise the behavior is undefined.
  998. */
  999. static inline struct snd_soc_platform *snd_soc_component_to_platform(
  1000. struct snd_soc_component *component)
  1001. {
  1002. return container_of(component, struct snd_soc_platform, component);
  1003. }
  1004. /* codec IO */
  1005. unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
  1006. int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg,
  1007. unsigned int val);
  1008. /* component IO */
  1009. int snd_soc_component_read(struct snd_soc_component *component,
  1010. unsigned int reg, unsigned int *val);
  1011. int snd_soc_component_write(struct snd_soc_component *component,
  1012. unsigned int reg, unsigned int val);
  1013. int snd_soc_component_update_bits(struct snd_soc_component *component,
  1014. unsigned int reg, unsigned int mask, unsigned int val);
  1015. int snd_soc_component_update_bits_async(struct snd_soc_component *component,
  1016. unsigned int reg, unsigned int mask, unsigned int val);
  1017. void snd_soc_component_async_complete(struct snd_soc_component *component);
  1018. int snd_soc_component_test_bits(struct snd_soc_component *component,
  1019. unsigned int reg, unsigned int mask, unsigned int value);
  1020. int snd_soc_component_init_io(struct snd_soc_component *component,
  1021. struct regmap *regmap);
  1022. /* device driver data */
  1023. static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
  1024. void *data)
  1025. {
  1026. card->drvdata = data;
  1027. }
  1028. static inline void *snd_soc_card_get_drvdata(struct snd_soc_card *card)
  1029. {
  1030. return card->drvdata;
  1031. }
  1032. static inline void snd_soc_codec_set_drvdata(struct snd_soc_codec *codec,
  1033. void *data)
  1034. {
  1035. dev_set_drvdata(codec->dev, data);
  1036. }
  1037. static inline void *snd_soc_codec_get_drvdata(struct snd_soc_codec *codec)
  1038. {
  1039. return dev_get_drvdata(codec->dev);
  1040. }
  1041. static inline void snd_soc_platform_set_drvdata(struct snd_soc_platform *platform,
  1042. void *data)
  1043. {
  1044. dev_set_drvdata(platform->dev, data);
  1045. }
  1046. static inline void *snd_soc_platform_get_drvdata(struct snd_soc_platform *platform)
  1047. {
  1048. return dev_get_drvdata(platform->dev);
  1049. }
  1050. static inline void snd_soc_pcm_set_drvdata(struct snd_soc_pcm_runtime *rtd,
  1051. void *data)
  1052. {
  1053. dev_set_drvdata(rtd->dev, data);
  1054. }
  1055. static inline void *snd_soc_pcm_get_drvdata(struct snd_soc_pcm_runtime *rtd)
  1056. {
  1057. return dev_get_drvdata(rtd->dev);
  1058. }
  1059. static inline void snd_soc_initialize_card_lists(struct snd_soc_card *card)
  1060. {
  1061. INIT_LIST_HEAD(&card->codec_dev_list);
  1062. INIT_LIST_HEAD(&card->platform_dev_list);
  1063. INIT_LIST_HEAD(&card->widgets);
  1064. INIT_LIST_HEAD(&card->paths);
  1065. INIT_LIST_HEAD(&card->dapm_list);
  1066. }
  1067. static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)
  1068. {
  1069. if (mc->reg == mc->rreg && mc->shift == mc->rshift)
  1070. return 0;
  1071. /*
  1072. * mc->reg == mc->rreg && mc->shift != mc->rshift, or
  1073. * mc->reg != mc->rreg means that the control is
  1074. * stereo (bits in one register or in two registers)
  1075. */
  1076. return 1;
  1077. }
  1078. static inline unsigned int snd_soc_enum_val_to_item(struct soc_enum *e,
  1079. unsigned int val)
  1080. {
  1081. unsigned int i;
  1082. if (!e->values)
  1083. return val;
  1084. for (i = 0; i < e->items; i++)
  1085. if (val == e->values[i])
  1086. return i;
  1087. return 0;
  1088. }
  1089. static inline unsigned int snd_soc_enum_item_to_val(struct soc_enum *e,
  1090. unsigned int item)
  1091. {
  1092. if (!e->values)
  1093. return item;
  1094. return e->values[item];
  1095. }
  1096. static inline bool snd_soc_component_is_active(
  1097. struct snd_soc_component *component)
  1098. {
  1099. return component->active != 0;
  1100. }
  1101. static inline bool snd_soc_codec_is_active(struct snd_soc_codec *codec)
  1102. {
  1103. return snd_soc_component_is_active(&codec->component);
  1104. }
  1105. /**
  1106. * snd_soc_kcontrol_component() - Returns the component that registered the
  1107. * control
  1108. * @kcontrol: The control for which to get the component
  1109. *
  1110. * Note: This function will work correctly if the control has been registered
  1111. * for a component. Either with snd_soc_add_codec_controls() or
  1112. * snd_soc_add_platform_controls() or via table based setup for either a
  1113. * CODEC, a platform or component driver. Otherwise the behavior is undefined.
  1114. */
  1115. static inline struct snd_soc_component *snd_soc_kcontrol_component(
  1116. struct snd_kcontrol *kcontrol)
  1117. {
  1118. return snd_kcontrol_chip(kcontrol);
  1119. }
  1120. /**
  1121. * snd_soc_kcontrol_codec() - Returns the CODEC that registered the control
  1122. * @kcontrol: The control for which to get the CODEC
  1123. *
  1124. * Note: This function will only work correctly if the control has been
  1125. * registered with snd_soc_add_codec_controls() or via table based setup of
  1126. * snd_soc_codec_driver. Otherwise the behavior is undefined.
  1127. */
  1128. static inline struct snd_soc_codec *snd_soc_kcontrol_codec(
  1129. struct snd_kcontrol *kcontrol)
  1130. {
  1131. return snd_soc_component_to_codec(snd_soc_kcontrol_component(kcontrol));
  1132. }
  1133. /**
  1134. * snd_soc_kcontrol_platform() - Returns the platform that registerd the control
  1135. * @kcontrol: The control for which to get the platform
  1136. *
  1137. * Note: This function will only work correctly if the control has been
  1138. * registered with snd_soc_add_platform_controls() or via table based setup of
  1139. * a snd_soc_platform_driver. Otherwise the behavior is undefined.
  1140. */
  1141. static inline struct snd_soc_platform *snd_soc_kcontrol_platform(
  1142. struct snd_kcontrol *kcontrol)
  1143. {
  1144. return snd_soc_component_to_platform(snd_soc_kcontrol_component(kcontrol));
  1145. }
  1146. int snd_soc_util_init(void);
  1147. void snd_soc_util_exit(void);
  1148. int snd_soc_of_parse_card_name(struct snd_soc_card *card,
  1149. const char *propname);
  1150. int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
  1151. const char *propname);
  1152. int snd_soc_of_parse_tdm_slot(struct device_node *np,
  1153. unsigned int *slots,
  1154. unsigned int *slot_width);
  1155. int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
  1156. const char *propname);
  1157. unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
  1158. const char *prefix);
  1159. int snd_soc_of_get_dai_name(struct device_node *of_node,
  1160. const char **dai_name);
  1161. #include <sound/soc-dai.h>
  1162. #ifdef CONFIG_DEBUG_FS
  1163. extern struct dentry *snd_soc_debugfs_root;
  1164. #endif
  1165. extern const struct dev_pm_ops snd_soc_pm_ops;
  1166. /* Helper functions */
  1167. static inline void snd_soc_dapm_mutex_lock(struct snd_soc_dapm_context *dapm)
  1168. {
  1169. mutex_lock(&dapm->card->dapm_mutex);
  1170. }
  1171. static inline void snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm)
  1172. {
  1173. mutex_unlock(&dapm->card->dapm_mutex);
  1174. }
  1175. #endif