soc.h 40 KB

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