soc.h 40 KB

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