soc.h 40 KB

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