soc.h 41 KB

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