soc.h 39 KB

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