soc.h 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * linux/sound/soc.h -- ALSA SoC Layer
  4. *
  5. * Author: Liam Girdwood
  6. * Created: Aug 11th 2005
  7. * Copyright: Wolfson Microelectronics. PLC.
  8. */
  9. #ifndef __LINUX_SND_SOC_H
  10. #define __LINUX_SND_SOC_H
  11. #include <linux/args.h>
  12. #include <linux/array_size.h>
  13. #include <linux/device.h>
  14. #include <linux/errno.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/lockdep.h>
  17. #include <linux/log2.h>
  18. #include <linux/mutex.h>
  19. #include <linux/notifier.h>
  20. #include <linux/of.h>
  21. #include <linux/types.h>
  22. #include <linux/workqueue.h>
  23. #include <sound/ac97_codec.h>
  24. #include <sound/compress_driver.h>
  25. #include <sound/control.h>
  26. #include <sound/core.h>
  27. #include <sound/pcm.h>
  28. struct module;
  29. struct platform_device;
  30. /* For the current users of sound/soc.h to avoid build issues */
  31. #include <linux/platform_device.h>
  32. #include <linux/regmap.h>
  33. /*
  34. * Convenience kcontrol builders
  35. */
  36. #define SOC_DOUBLE_S_VALUE(xreg, shift_left, shift_right, xmin, xmax, xsign_bit, \
  37. xinvert, xautodisable) \
  38. ((unsigned long)&(struct soc_mixer_control) \
  39. {.reg = xreg, .rreg = xreg, .shift = shift_left, \
  40. .rshift = shift_right, .min = xmin, .max = xmax, \
  41. .sign_bit = xsign_bit, .invert = xinvert, .autodisable = xautodisable})
  42. #define SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, xmin, xmax, xinvert, xautodisable) \
  43. SOC_DOUBLE_S_VALUE(xreg, shift_left, shift_right, xmin, xmax, 0, xinvert, \
  44. xautodisable)
  45. #define SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, xautodisable) \
  46. SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmin, xmax, xinvert, xautodisable)
  47. #define SOC_DOUBLE_R_S_VALUE(xlreg, xrreg, xshift, xmin, xmax, xsign_bit, xinvert) \
  48. ((unsigned long)&(struct soc_mixer_control) \
  49. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  50. .max = xmax, .min = xmin, .sign_bit = xsign_bit, \
  51. .invert = xinvert})
  52. #define SOC_DOUBLE_R_VALUE(xlreg, xrreg, xshift, xmin, xmax, xinvert) \
  53. SOC_DOUBLE_R_S_VALUE(xlreg, xrreg, xshift, xmin, xmax, 0, xinvert)
  54. #define SOC_SINGLE(xname, reg, shift, max, invert) \
  55. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  56. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  57. .put = snd_soc_put_volsw, \
  58. .private_value = SOC_SINGLE_VALUE(reg, shift, 0, max, invert, 0) }
  59. #define SOC_SINGLE_RANGE(xname, xreg, xshift, xmin, xmax, xinvert) \
  60. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  61. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  62. .put = snd_soc_put_volsw, \
  63. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }
  64. #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
  65. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  66. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  67. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  68. .tlv.p = (tlv_array), \
  69. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  70. .put = snd_soc_put_volsw, \
  71. .private_value = SOC_SINGLE_VALUE(reg, shift, 0, max, invert, 0) }
  72. #define SOC_SINGLE_SX_TLV(xname, xreg, xshift, xmin, xmax, tlv_array) \
  73. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  74. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  75. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  76. .tlv.p = (tlv_array),\
  77. .info = snd_soc_info_volsw_sx, \
  78. .get = snd_soc_get_volsw_sx,\
  79. .put = snd_soc_put_volsw_sx, \
  80. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, 0, 0) }
  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, \
  87. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  88. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }
  89. #define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
  90. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  91. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  92. .put = snd_soc_put_volsw, \
  93. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  94. 0, max, invert, 0) }
  95. #define SOC_DOUBLE_STS(xname, reg, shift_left, shift_right, max, invert) \
  96. { \
  97. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  98. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  99. .access = SNDRV_CTL_ELEM_ACCESS_READ | \
  100. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  101. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  102. 0, max, invert, 0) }
  103. #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
  104. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  105. .info = snd_soc_info_volsw, \
  106. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  107. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  108. 0, xmax, xinvert) }
  109. #define SOC_DOUBLE_R_RANGE(xname, reg_left, reg_right, xshift, xmin, \
  110. xmax, xinvert) \
  111. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  112. .info = snd_soc_info_volsw, \
  113. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  114. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, \
  115. xshift, xmin, xmax, xinvert) }
  116. #define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
  117. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  118. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  119. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  120. .tlv.p = (tlv_array), \
  121. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  122. .put = snd_soc_put_volsw, \
  123. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  124. 0, max, invert, 0) }
  125. #define SOC_DOUBLE_SX_TLV(xname, xreg, shift_left, shift_right, xmin, xmax, tlv_array) \
  126. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  127. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  128. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  129. .tlv.p = (tlv_array), \
  130. .info = snd_soc_info_volsw_sx, \
  131. .get = snd_soc_get_volsw_sx, \
  132. .put = snd_soc_put_volsw_sx, \
  133. .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
  134. xmin, xmax, 0, 0) }
  135. #define SOC_DOUBLE_RANGE_TLV(xname, xreg, xshift_left, xshift_right, xmin, xmax, \
  136. xinvert, tlv_array) \
  137. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  138. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  139. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  140. .tlv.p = (tlv_array), \
  141. .info = snd_soc_info_volsw, \
  142. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  143. .private_value = SOC_DOUBLE_VALUE(xreg, xshift_left, xshift_right, \
  144. xmin, xmax, xinvert, 0) }
  145. #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
  146. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  147. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  148. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  149. .tlv.p = (tlv_array), \
  150. .info = snd_soc_info_volsw, \
  151. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  152. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  153. 0, xmax, xinvert) }
  154. #define SOC_DOUBLE_R_RANGE_TLV(xname, reg_left, reg_right, xshift, xmin, \
  155. xmax, xinvert, tlv_array) \
  156. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  157. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  158. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  159. .tlv.p = (tlv_array), \
  160. .info = snd_soc_info_volsw, \
  161. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  162. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, \
  163. xshift, xmin, xmax, xinvert) }
  164. #define SOC_DOUBLE_R_SX_TLV(xname, xreg, xrreg, xshift, xmin, xmax, tlv_array) \
  165. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  166. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  167. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  168. .tlv.p = (tlv_array), \
  169. .info = snd_soc_info_volsw_sx, \
  170. .get = snd_soc_get_volsw_sx, \
  171. .put = snd_soc_put_volsw_sx, \
  172. .private_value = SOC_DOUBLE_R_VALUE(xreg, xrreg, xshift, xmin, xmax, 0) }
  173. #define SOC_DOUBLE_R_S_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \
  174. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  175. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  176. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  177. .tlv.p = (tlv_array), \
  178. .info = snd_soc_info_volsw, \
  179. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  180. .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \
  181. xmin, xmax, xsign_bit, xinvert) }
  182. #define SOC_SINGLE_S_TLV(xname, xreg, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \
  183. SOC_DOUBLE_R_S_TLV(xname, xreg, xreg, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array)
  184. #define SOC_SINGLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  185. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  186. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  187. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  188. .tlv.p = (tlv_array), \
  189. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  190. .put = snd_soc_put_volsw, \
  191. .private_value = (unsigned long)&(struct soc_mixer_control) \
  192. {.reg = xreg, .rreg = xreg, \
  193. .min = xmin, .max = xmax, \
  194. .sign_bit = 7,} }
  195. #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  196. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  197. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  198. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  199. .tlv.p = (tlv_array), \
  200. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  201. .put = snd_soc_put_volsw, \
  202. .private_value = SOC_DOUBLE_S_VALUE(xreg, 0, 8, xmin, xmax, 7, 0, 0) }
  203. #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xitems, xtexts) \
  204. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  205. .items = xitems, .texts = xtexts, \
  206. .mask = xitems ? roundup_pow_of_two(xitems) - 1 : 0}
  207. #define SOC_ENUM_SINGLE(xreg, xshift, xitems, xtexts) \
  208. SOC_ENUM_DOUBLE(xreg, xshift, xshift, xitems, xtexts)
  209. #define SOC_ENUM_SINGLE_EXT(xitems, xtexts) \
  210. { .items = xitems, .texts = xtexts }
  211. #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xitems, xtexts, xvalues) \
  212. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  213. .mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues}
  214. #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
  215. SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xitems, xtexts, xvalues)
  216. #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
  217. { .reg = xreg, .shift_l = xshift, .shift_r = xshift, \
  218. .mask = xmask, .items = xitems, .texts = xtexts, \
  219. .values = xvalues, .autodisable = 1}
  220. #define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \
  221. SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts)
  222. #define SOC_ENUM(xname, xenum) \
  223. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  224. .info = snd_soc_info_enum_double, \
  225. .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
  226. .private_value = (unsigned long)&xenum }
  227. #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
  228. xhandler_get, xhandler_put) \
  229. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  230. .info = snd_soc_info_volsw, \
  231. .get = xhandler_get, .put = xhandler_put, \
  232. .private_value = SOC_SINGLE_VALUE(xreg, xshift, 0, xmax, xinvert, 0) }
  233. #define SOC_DOUBLE_EXT(xname, reg, shift_left, shift_right, max, invert,\
  234. xhandler_get, xhandler_put) \
  235. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  236. .info = snd_soc_info_volsw, \
  237. .get = xhandler_get, .put = xhandler_put, \
  238. .private_value = \
  239. SOC_DOUBLE_VALUE(reg, shift_left, shift_right, 0, max, invert, 0) }
  240. #define SOC_DOUBLE_R_EXT(xname, reg_left, reg_right, xshift, xmax, xinvert,\
  241. xhandler_get, xhandler_put) \
  242. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  243. .info = snd_soc_info_volsw, \
  244. .get = xhandler_get, .put = xhandler_put, \
  245. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  246. 0, xmax, xinvert) }
  247. #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
  248. xhandler_get, xhandler_put, tlv_array) \
  249. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  250. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  251. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  252. .tlv.p = (tlv_array), \
  253. .info = snd_soc_info_volsw, \
  254. .get = xhandler_get, .put = xhandler_put, \
  255. .private_value = SOC_SINGLE_VALUE(xreg, xshift, 0, xmax, xinvert, 0) }
  256. #define SOC_SINGLE_RANGE_EXT_TLV(xname, xreg, xshift, xmin, xmax, xinvert, \
  257. xhandler_get, xhandler_put, tlv_array) \
  258. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  259. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  260. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  261. .tlv.p = (tlv_array), \
  262. .info = snd_soc_info_volsw, \
  263. .get = xhandler_get, .put = xhandler_put, \
  264. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }
  265. #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
  266. xhandler_get, xhandler_put, tlv_array) \
  267. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  268. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  269. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  270. .tlv.p = (tlv_array), \
  271. .info = snd_soc_info_volsw, \
  272. .get = xhandler_get, .put = xhandler_put, \
  273. .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
  274. 0, xmax, xinvert, 0) }
  275. #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\
  276. xhandler_get, xhandler_put, tlv_array) \
  277. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  278. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  279. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  280. .tlv.p = (tlv_array), \
  281. .info = snd_soc_info_volsw, \
  282. .get = xhandler_get, .put = xhandler_put, \
  283. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  284. 0, xmax, xinvert) }
  285. #define SOC_DOUBLE_R_S_EXT_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, \
  286. xsign_bit, xinvert, xhandler_get, xhandler_put, \
  287. tlv_array) \
  288. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  289. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  290. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  291. .tlv.p = (tlv_array), \
  292. .info = snd_soc_info_volsw, \
  293. .get = xhandler_get, .put = xhandler_put, \
  294. .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \
  295. xmin, xmax, xsign_bit, xinvert) }
  296. #define SOC_SINGLE_S_EXT_TLV(xname, xreg, xshift, xmin, xmax, \
  297. xsign_bit, xinvert, xhandler_get, xhandler_put, \
  298. tlv_array) \
  299. SOC_DOUBLE_R_S_EXT_TLV(xname, xreg, xreg, xshift, xmin, xmax, \
  300. xsign_bit, xinvert, xhandler_get, xhandler_put, \
  301. tlv_array)
  302. #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
  303. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  304. .info = snd_soc_info_bool_ext, \
  305. .get = xhandler_get, .put = xhandler_put, \
  306. .private_value = xdata }
  307. #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
  308. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  309. .info = snd_soc_info_enum_double, \
  310. .get = xhandler_get, .put = xhandler_put, \
  311. .private_value = (unsigned long)&xenum }
  312. #define SOC_VALUE_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
  313. SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put)
  314. #define SOC_ENUM_EXT_ACC(xname, xenum, xhandler_get, xhandler_put, xaccess) \
  315. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  316. .access = xaccess, \
  317. .info = snd_soc_info_enum_double, \
  318. .get = xhandler_get, .put = xhandler_put, \
  319. .private_value = (unsigned long)&xenum }
  320. #define SND_SOC_BYTES(xname, xbase, xregs) \
  321. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  322. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  323. .put = snd_soc_bytes_put, .private_value = \
  324. ((unsigned long)&(struct soc_bytes) \
  325. {.base = xbase, .num_regs = xregs }) }
  326. #define SND_SOC_BYTES_E(xname, xbase, xregs, xhandler_get, xhandler_put) \
  327. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  328. .info = snd_soc_bytes_info, .get = xhandler_get, \
  329. .put = xhandler_put, .private_value = \
  330. ((unsigned long)&(struct soc_bytes) \
  331. {.base = xbase, .num_regs = xregs }) }
  332. #define SND_SOC_BYTES_E_ACC(xname, xbase, xregs, xhandler_get, xhandler_put, xaccess) \
  333. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  334. .access = xaccess, \
  335. .info = snd_soc_bytes_info, .get = xhandler_get, \
  336. .put = xhandler_put, .private_value = \
  337. ((unsigned long)&(struct soc_bytes) \
  338. {.base = xbase, .num_regs = xregs }) }
  339. #define SND_SOC_BYTES_MASK(xname, xbase, xregs, xmask) \
  340. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  341. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  342. .put = snd_soc_bytes_put, .private_value = \
  343. ((unsigned long)&(struct soc_bytes) \
  344. {.base = xbase, .num_regs = xregs, \
  345. .mask = xmask }) }
  346. /*
  347. * SND_SOC_BYTES_EXT is deprecated, please USE SND_SOC_BYTES_TLV instead
  348. */
  349. #define SND_SOC_BYTES_EXT(xname, xcount, xhandler_get, xhandler_put) \
  350. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  351. .info = snd_soc_bytes_info_ext, \
  352. .get = xhandler_get, .put = xhandler_put, \
  353. .private_value = (unsigned long)&(struct soc_bytes_ext) \
  354. {.max = xcount} }
  355. #define SND_SOC_BYTES_TLV(xname, xcount, xhandler_get, xhandler_put) \
  356. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  357. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE | \
  358. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
  359. .tlv.c = (snd_soc_bytes_tlv_callback), \
  360. .info = snd_soc_bytes_info_ext, \
  361. .private_value = (unsigned long)&(struct soc_bytes_ext) \
  362. {.max = xcount, .get = xhandler_get, .put = xhandler_put, } }
  363. #define SOC_SINGLE_XR_SX(xname, xregbase, xregcount, xnbits, \
  364. xmin, xmax, xinvert) \
  365. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  366. .info = snd_soc_info_xr_sx, .get = snd_soc_get_xr_sx, \
  367. .put = snd_soc_put_xr_sx, \
  368. .private_value = (unsigned long)&(struct soc_mreg_control) \
  369. {.regbase = xregbase, .regcount = xregcount, .nbits = xnbits, \
  370. .invert = xinvert, .min = xmin, .max = xmax} }
  371. #define SOC_SINGLE_STROBE(xname, xreg, xshift, xinvert) \
  372. SOC_SINGLE_EXT(xname, xreg, xshift, 1, xinvert, \
  373. snd_soc_get_strobe, snd_soc_put_strobe)
  374. /*
  375. * Simplified versions of above macros, declaring a struct and calculating
  376. * ARRAY_SIZE internally
  377. */
  378. #define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \
  379. const struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
  380. ARRAY_SIZE(xtexts), xtexts)
  381. #define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \
  382. SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
  383. #define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \
  384. const struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts)
  385. #define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \
  386. const struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \
  387. ARRAY_SIZE(xtexts), xtexts, xvalues)
  388. #define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
  389. SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
  390. #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
  391. const struct soc_enum name = SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, \
  392. xshift, xmask, ARRAY_SIZE(xtexts), xtexts, xvalues)
  393. #define SOC_ENUM_SINGLE_VIRT_DECL(name, xtexts) \
  394. const struct soc_enum name = SOC_ENUM_SINGLE_VIRT(ARRAY_SIZE(xtexts), xtexts)
  395. struct snd_soc_card;
  396. struct snd_soc_pcm_runtime;
  397. struct snd_soc_dai;
  398. struct snd_soc_dai_driver;
  399. struct snd_soc_dai_link;
  400. struct snd_soc_component;
  401. struct snd_soc_component_driver;
  402. struct snd_soc_jack;
  403. struct snd_soc_jack_pin;
  404. #include <sound/soc-dapm.h>
  405. #include <sound/soc-dpcm.h>
  406. #include <sound/soc-topology.h>
  407. enum snd_soc_pcm_subclass {
  408. SND_SOC_PCM_CLASS_PCM = 0,
  409. SND_SOC_PCM_CLASS_BE = 1,
  410. };
  411. int snd_soc_register_card(struct snd_soc_card *card);
  412. void snd_soc_unregister_card(struct snd_soc_card *card);
  413. int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
  414. int devm_snd_soc_register_deferrable_card(struct device *dev, struct snd_soc_card *card);
  415. #ifdef CONFIG_PM_SLEEP
  416. int snd_soc_suspend(struct device *dev);
  417. int snd_soc_resume(struct device *dev);
  418. #else
  419. static inline int snd_soc_suspend(struct device *dev)
  420. {
  421. return 0;
  422. }
  423. static inline int snd_soc_resume(struct device *dev)
  424. {
  425. return 0;
  426. }
  427. #endif
  428. int snd_soc_poweroff(struct device *dev);
  429. int snd_soc_component_initialize(struct snd_soc_component *component,
  430. const struct snd_soc_component_driver *driver,
  431. struct device *dev);
  432. int snd_soc_add_component(struct snd_soc_component *component,
  433. struct snd_soc_dai_driver *dai_drv,
  434. int num_dai);
  435. int snd_soc_register_component(struct device *dev,
  436. const struct snd_soc_component_driver *component_driver,
  437. struct snd_soc_dai_driver *dai_drv, int num_dai);
  438. int devm_snd_soc_register_component(struct device *dev,
  439. const struct snd_soc_component_driver *component_driver,
  440. struct snd_soc_dai_driver *dai_drv, int num_dai);
  441. #define snd_soc_unregister_component(dev) snd_soc_unregister_component_by_driver(dev, NULL)
  442. void snd_soc_unregister_component_by_driver(struct device *dev,
  443. const struct snd_soc_component_driver *component_driver);
  444. struct snd_soc_component *snd_soc_lookup_component_nolocked(struct device *dev,
  445. const char *driver_name);
  446. struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
  447. const char *driver_name);
  448. int soc_new_pcm(struct snd_soc_pcm_runtime *rtd);
  449. #ifdef CONFIG_SND_SOC_COMPRESS
  450. int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd);
  451. #else
  452. static inline int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd)
  453. {
  454. return 0;
  455. }
  456. #endif
  457. struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
  458. struct snd_soc_dai_link *dai_link);
  459. bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd);
  460. void snd_soc_runtime_action(struct snd_soc_pcm_runtime *rtd,
  461. int stream, int action);
  462. static inline void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd,
  463. int stream)
  464. {
  465. snd_soc_runtime_action(rtd, stream, 1);
  466. }
  467. static inline void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd,
  468. int stream)
  469. {
  470. snd_soc_runtime_action(rtd, stream, -1);
  471. }
  472. int snd_soc_runtime_calc_hw(struct snd_soc_pcm_runtime *rtd,
  473. struct snd_pcm_hardware *hw, int stream);
  474. int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
  475. unsigned int dai_fmt);
  476. /* Utility functions to get clock rates from various things */
  477. int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
  478. int snd_soc_params_to_frame_size(const struct snd_pcm_hw_params *params);
  479. int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
  480. int snd_soc_params_to_bclk(const struct snd_pcm_hw_params *parms);
  481. int snd_soc_tdm_params_to_bclk(const struct snd_pcm_hw_params *params,
  482. int tdm_width, int tdm_slots, int slot_multiple);
  483. int snd_soc_ret(const struct device *dev, int ret, const char *fmt, ...);
  484. /* set runtime hw params */
  485. static inline int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  486. const struct snd_pcm_hardware *hw)
  487. {
  488. substream->runtime->hw = *hw;
  489. return 0;
  490. }
  491. struct snd_ac97 *snd_soc_alloc_ac97_component(struct snd_soc_component *component);
  492. struct snd_ac97 *snd_soc_new_ac97_component(struct snd_soc_component *component,
  493. unsigned int id, unsigned int id_mask);
  494. void snd_soc_free_ac97_component(struct snd_ac97 *ac97);
  495. #ifdef CONFIG_SND_SOC_AC97_BUS
  496. int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops);
  497. int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
  498. struct platform_device *pdev);
  499. extern struct snd_ac97_bus_ops *soc_ac97_ops;
  500. #else
  501. static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
  502. struct platform_device *pdev)
  503. {
  504. return 0;
  505. }
  506. static inline int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
  507. {
  508. return 0;
  509. }
  510. #endif
  511. /*
  512. *Controls
  513. */
  514. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  515. void *data, const char *long_name,
  516. const char *prefix);
  517. int snd_soc_add_component_controls(struct snd_soc_component *component,
  518. const struct snd_kcontrol_new *controls, unsigned int num_controls);
  519. int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
  520. const struct snd_kcontrol_new *controls, int num_controls);
  521. int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
  522. const struct snd_kcontrol_new *controls, int num_controls);
  523. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  524. struct snd_ctl_elem_info *uinfo);
  525. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  526. struct snd_ctl_elem_value *ucontrol);
  527. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  528. struct snd_ctl_elem_value *ucontrol);
  529. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  530. struct snd_ctl_elem_info *uinfo);
  531. int snd_soc_info_volsw_sx(struct snd_kcontrol *kcontrol,
  532. struct snd_ctl_elem_info *uinfo);
  533. #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
  534. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  535. struct snd_ctl_elem_value *ucontrol);
  536. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  537. struct snd_ctl_elem_value *ucontrol);
  538. #define snd_soc_get_volsw_2r snd_soc_get_volsw
  539. #define snd_soc_put_volsw_2r snd_soc_put_volsw
  540. int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
  541. struct snd_ctl_elem_value *ucontrol);
  542. int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
  543. struct snd_ctl_elem_value *ucontrol);
  544. int snd_soc_limit_volume(struct snd_soc_card *card,
  545. const char *name, int max);
  546. int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
  547. struct snd_ctl_elem_info *uinfo);
  548. int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
  549. struct snd_ctl_elem_value *ucontrol);
  550. int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
  551. struct snd_ctl_elem_value *ucontrol);
  552. int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,
  553. struct snd_ctl_elem_info *ucontrol);
  554. int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag,
  555. unsigned int size, unsigned int __user *tlv);
  556. int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
  557. struct snd_ctl_elem_info *uinfo);
  558. int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
  559. struct snd_ctl_elem_value *ucontrol);
  560. int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
  561. struct snd_ctl_elem_value *ucontrol);
  562. int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
  563. struct snd_ctl_elem_value *ucontrol);
  564. int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
  565. struct snd_ctl_elem_value *ucontrol);
  566. enum snd_soc_trigger_order {
  567. /* start stop */
  568. SND_SOC_TRIGGER_ORDER_DEFAULT = 0, /* Link->Component->DAI DAI->Component->Link */
  569. SND_SOC_TRIGGER_ORDER_LDC, /* Link->DAI->Component Component->DAI->Link */
  570. SND_SOC_TRIGGER_ORDER_MAX,
  571. };
  572. /* SoC PCM stream information */
  573. struct snd_soc_pcm_stream {
  574. const char *stream_name;
  575. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  576. u32 subformats; /* for S32_LE format, SNDRV_PCM_SUBFMTBIT_* */
  577. unsigned int rates; /* SNDRV_PCM_RATE_* */
  578. unsigned int rate_min; /* min rate */
  579. unsigned int rate_max; /* max rate */
  580. unsigned int channels_min; /* min channels */
  581. unsigned int channels_max; /* max channels */
  582. unsigned int sig_bits; /* number of bits of content */
  583. };
  584. /* SoC audio ops */
  585. struct snd_soc_ops {
  586. int (*startup)(struct snd_pcm_substream *);
  587. void (*shutdown)(struct snd_pcm_substream *);
  588. int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
  589. int (*hw_free)(struct snd_pcm_substream *);
  590. int (*prepare)(struct snd_pcm_substream *);
  591. int (*trigger)(struct snd_pcm_substream *, int);
  592. };
  593. struct snd_soc_compr_ops {
  594. int (*startup)(struct snd_compr_stream *);
  595. void (*shutdown)(struct snd_compr_stream *);
  596. int (*set_params)(struct snd_compr_stream *);
  597. };
  598. struct snd_soc_component*
  599. snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
  600. const char *driver_name);
  601. struct snd_soc_dai_link_component {
  602. const char *name;
  603. struct device_node *of_node;
  604. const char *dai_name;
  605. const struct of_phandle_args *dai_args;
  606. /*
  607. * Extra format = SND_SOC_DAIFMT_Bx_Fx
  608. *
  609. * [Note] it is Bx_Fx base, not CBx_CFx
  610. *
  611. * It will be used with dai_link->dai_fmt
  612. * see
  613. * snd_soc_runtime_set_dai_fmt()
  614. */
  615. unsigned int ext_fmt;
  616. };
  617. /*
  618. * [dai_link->ch_maps Image sample]
  619. *
  620. *-------------------------
  621. * CPU0 <---> Codec0
  622. *
  623. * ch-map[0].cpu = 0 ch-map[0].codec = 0
  624. *
  625. *-------------------------
  626. * CPU0 <---> Codec0
  627. * CPU1 <---> Codec1
  628. * CPU2 <---> Codec2
  629. *
  630. * ch-map[0].cpu = 0 ch-map[0].codec = 0
  631. * ch-map[1].cpu = 1 ch-map[1].codec = 1
  632. * ch-map[2].cpu = 2 ch-map[2].codec = 2
  633. *
  634. *-------------------------
  635. * CPU0 <---> Codec0
  636. * CPU1 <-+-> Codec1
  637. * CPU2 <-/
  638. *
  639. * ch-map[0].cpu = 0 ch-map[0].codec = 0
  640. * ch-map[1].cpu = 1 ch-map[1].codec = 1
  641. * ch-map[2].cpu = 2 ch-map[2].codec = 1
  642. *
  643. *-------------------------
  644. * CPU0 <---> Codec0
  645. * CPU1 <-+-> Codec1
  646. * \-> Codec2
  647. *
  648. * ch-map[0].cpu = 0 ch-map[0].codec = 0
  649. * ch-map[1].cpu = 1 ch-map[1].codec = 1
  650. * ch-map[2].cpu = 1 ch-map[2].codec = 2
  651. *
  652. */
  653. struct snd_soc_dai_link_ch_map {
  654. unsigned int cpu;
  655. unsigned int codec;
  656. unsigned int ch_mask;
  657. };
  658. struct snd_soc_dai_link {
  659. /* config - must be set by machine driver */
  660. const char *name; /* Codec name */
  661. const char *stream_name; /* Stream name */
  662. /*
  663. * You MAY specify the link's CPU-side device, either by device name,
  664. * or by DT/OF node, but not both. If this information is omitted,
  665. * the CPU-side DAI is matched using .cpu_dai_name only, which hence
  666. * must be globally unique. These fields are currently typically used
  667. * only for codec to codec links, or systems using device tree.
  668. */
  669. /*
  670. * You MAY specify the DAI name of the CPU DAI. If this information is
  671. * omitted, the CPU-side DAI is matched using .cpu_name/.cpu_of_node
  672. * only, which only works well when that device exposes a single DAI.
  673. */
  674. struct snd_soc_dai_link_component *cpus;
  675. unsigned int num_cpus;
  676. /*
  677. * You MUST specify the link's codec, either by device name, or by
  678. * DT/OF node, but not both.
  679. */
  680. /* You MUST specify the DAI name within the codec */
  681. struct snd_soc_dai_link_component *codecs;
  682. unsigned int num_codecs;
  683. /* num_ch_maps = max(num_cpu, num_codecs) */
  684. struct snd_soc_dai_link_ch_map *ch_maps;
  685. /*
  686. * You MAY specify the link's platform/PCM/DMA driver, either by
  687. * device name, or by DT/OF node, but not both. Some forms of link
  688. * do not need a platform. In such case, platforms are not mandatory.
  689. */
  690. struct snd_soc_dai_link_component *platforms;
  691. unsigned int num_platforms;
  692. int id; /* optional ID for machine driver link identification */
  693. /*
  694. * for Codec2Codec
  695. */
  696. const struct snd_soc_pcm_stream *c2c_params;
  697. unsigned int num_c2c_params;
  698. unsigned int dai_fmt; /* format to set on init */
  699. enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */
  700. /* codec/machine specific init - e.g. add machine controls */
  701. int (*init)(struct snd_soc_pcm_runtime *rtd);
  702. /* codec/machine specific exit - dual of init() */
  703. void (*exit)(struct snd_soc_pcm_runtime *rtd);
  704. /* optional hw_params re-writing for BE and FE sync */
  705. int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
  706. struct snd_pcm_hw_params *params);
  707. /* machine stream operations */
  708. const struct snd_soc_ops *ops;
  709. const struct snd_soc_compr_ops *compr_ops;
  710. /*
  711. * soc_pcm_trigger() start/stop sequence.
  712. * see also
  713. * snd_soc_component_driver
  714. * soc_pcm_trigger()
  715. */
  716. enum snd_soc_trigger_order trigger_start;
  717. enum snd_soc_trigger_order trigger_stop;
  718. /* Mark this pcm with non atomic ops */
  719. unsigned int nonatomic:1;
  720. /* For unidirectional dai links */
  721. unsigned int playback_only:1;
  722. unsigned int capture_only:1;
  723. /* Keep DAI active over suspend */
  724. unsigned int ignore_suspend:1;
  725. /* Symmetry requirements */
  726. unsigned int symmetric_rate:1;
  727. unsigned int symmetric_channels:1;
  728. unsigned int symmetric_sample_bits:1;
  729. /* Do not create a PCM for this DAI link (Backend link) */
  730. unsigned int no_pcm:1;
  731. /* This DAI link can route to other DAI links at runtime (Frontend)*/
  732. unsigned int dynamic:1;
  733. /* DPCM used FE & BE merged format */
  734. unsigned int dpcm_merged_format:1;
  735. /* DPCM used FE & BE merged channel */
  736. unsigned int dpcm_merged_chan:1;
  737. /* DPCM used FE & BE merged rate */
  738. unsigned int dpcm_merged_rate:1;
  739. /* pmdown_time is ignored at stop */
  740. unsigned int ignore_pmdown_time:1;
  741. /* Do not create a PCM for this DAI link (Backend link) */
  742. unsigned int ignore:1;
  743. #ifdef CONFIG_SND_SOC_TOPOLOGY
  744. struct snd_soc_dobj dobj; /* For topology */
  745. #endif
  746. };
  747. static inline int snd_soc_link_num_ch_map(const struct snd_soc_dai_link *link)
  748. {
  749. return max(link->num_cpus, link->num_codecs);
  750. }
  751. static inline struct snd_soc_dai_link_component*
  752. snd_soc_link_to_cpu(struct snd_soc_dai_link *link, int n) {
  753. return &(link)->cpus[n];
  754. }
  755. static inline struct snd_soc_dai_link_component*
  756. snd_soc_link_to_codec(struct snd_soc_dai_link *link, int n) {
  757. return &(link)->codecs[n];
  758. }
  759. static inline struct snd_soc_dai_link_component*
  760. snd_soc_link_to_platform(struct snd_soc_dai_link *link, int n) {
  761. return &(link)->platforms[n];
  762. }
  763. #define for_each_link_codecs(link, i, codec) \
  764. for ((i) = 0; \
  765. ((i) < link->num_codecs) && \
  766. ((codec) = snd_soc_link_to_codec(link, i)); \
  767. (i)++)
  768. #define for_each_link_platforms(link, i, platform) \
  769. for ((i) = 0; \
  770. ((i) < link->num_platforms) && \
  771. ((platform) = snd_soc_link_to_platform(link, i)); \
  772. (i)++)
  773. #define for_each_link_cpus(link, i, cpu) \
  774. for ((i) = 0; \
  775. ((i) < link->num_cpus) && \
  776. ((cpu) = snd_soc_link_to_cpu(link, i)); \
  777. (i)++)
  778. #define for_each_link_ch_maps(link, i, ch_map) \
  779. for ((i) = 0; \
  780. ((i) < snd_soc_link_num_ch_map(link) && \
  781. ((ch_map) = link->ch_maps + i)); \
  782. (i)++)
  783. /*
  784. * Sample 1 : Single CPU/Codec/Platform
  785. *
  786. * SND_SOC_DAILINK_DEFS(test,
  787. * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai")),
  788. * DAILINK_COMP_ARRAY(COMP_CODEC("codec", "codec_dai")),
  789. * DAILINK_COMP_ARRAY(COMP_PLATFORM("platform")));
  790. *
  791. * struct snd_soc_dai_link link = {
  792. * ...
  793. * SND_SOC_DAILINK_REG(test),
  794. * };
  795. *
  796. * Sample 2 : Multi CPU/Codec, no Platform
  797. *
  798. * SND_SOC_DAILINK_DEFS(test,
  799. * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai1"),
  800. * COMP_CPU("cpu_dai2")),
  801. * DAILINK_COMP_ARRAY(COMP_CODEC("codec1", "codec_dai1"),
  802. * COMP_CODEC("codec2", "codec_dai2")));
  803. *
  804. * struct snd_soc_dai_link link = {
  805. * ...
  806. * SND_SOC_DAILINK_REG(test),
  807. * };
  808. *
  809. * Sample 3 : Define each CPU/Codec/Platform manually
  810. *
  811. * SND_SOC_DAILINK_DEF(test_cpu,
  812. * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai1"),
  813. * COMP_CPU("cpu_dai2")));
  814. * SND_SOC_DAILINK_DEF(test_codec,
  815. * DAILINK_COMP_ARRAY(COMP_CODEC("codec1", "codec_dai1"),
  816. * COMP_CODEC("codec2", "codec_dai2")));
  817. * SND_SOC_DAILINK_DEF(test_platform,
  818. * DAILINK_COMP_ARRAY(COMP_PLATFORM("platform")));
  819. *
  820. * struct snd_soc_dai_link link = {
  821. * ...
  822. * SND_SOC_DAILINK_REG(test_cpu,
  823. * test_codec,
  824. * test_platform),
  825. * };
  826. *
  827. * Sample 4 : Sample3 without platform
  828. *
  829. * struct snd_soc_dai_link link = {
  830. * ...
  831. * SND_SOC_DAILINK_REG(test_cpu,
  832. * test_codec);
  833. * };
  834. */
  835. #define SND_SOC_DAILINK_REG1(name) SND_SOC_DAILINK_REG3(name##_cpus, name##_codecs, name##_platforms)
  836. #define SND_SOC_DAILINK_REG2(cpu, codec) SND_SOC_DAILINK_REG3(cpu, codec, null_dailink_component)
  837. #define SND_SOC_DAILINK_REG3(cpu, codec, platform) \
  838. .cpus = cpu, \
  839. .num_cpus = ARRAY_SIZE(cpu), \
  840. .codecs = codec, \
  841. .num_codecs = ARRAY_SIZE(codec), \
  842. .platforms = platform, \
  843. .num_platforms = ARRAY_SIZE(platform)
  844. #define SND_SOC_DAILINK_REG(...) \
  845. CONCATENATE(SND_SOC_DAILINK_REG, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__)
  846. #define SND_SOC_DAILINK_DEF(name, def...) \
  847. static struct snd_soc_dai_link_component name[] = { def }
  848. #define SND_SOC_DAILINK_DEFS(name, cpu, codec, platform...) \
  849. SND_SOC_DAILINK_DEF(name##_cpus, cpu); \
  850. SND_SOC_DAILINK_DEF(name##_codecs, codec); \
  851. SND_SOC_DAILINK_DEF(name##_platforms, platform)
  852. #define DAILINK_COMP_ARRAY(param...) param
  853. #define COMP_EMPTY() { }
  854. #define COMP_CPU(_dai) { .dai_name = _dai, }
  855. #define COMP_CODEC(_name, _dai) { .name = _name, .dai_name = _dai, }
  856. #define COMP_PLATFORM(_name) { .name = _name }
  857. #define COMP_AUX(_name) { .name = _name }
  858. #define COMP_CODEC_CONF(_name) { .name = _name }
  859. #define COMP_DUMMY() /* see snd_soc_fill_dummy_dai() */
  860. extern struct snd_soc_dai_link_component null_dailink_component[0];
  861. extern struct snd_soc_dai_link_component snd_soc_dummy_dlc;
  862. int snd_soc_dlc_is_dummy(struct snd_soc_dai_link_component *dlc);
  863. struct snd_soc_codec_conf {
  864. /*
  865. * specify device either by device name, or by
  866. * DT/OF node, but not both.
  867. */
  868. struct snd_soc_dai_link_component dlc;
  869. /*
  870. * optional map of kcontrol, widget and path name prefixes that are
  871. * associated per device
  872. */
  873. const char *name_prefix;
  874. };
  875. struct snd_soc_aux_dev {
  876. /*
  877. * specify multi-codec either by device name, or by
  878. * DT/OF node, but not both.
  879. */
  880. struct snd_soc_dai_link_component dlc;
  881. /* codec/machine specific init - e.g. add machine controls */
  882. int (*init)(struct snd_soc_component *component);
  883. };
  884. /* SoC card */
  885. struct snd_soc_card {
  886. const char *name;
  887. const char *long_name;
  888. const char *driver_name;
  889. const char *components;
  890. #ifdef CONFIG_DMI
  891. char dmi_longname[80];
  892. #endif /* CONFIG_DMI */
  893. #ifdef CONFIG_PCI
  894. /*
  895. * PCI does not define 0 as invalid, so pci_subsystem_set indicates
  896. * whether a value has been written to these fields.
  897. */
  898. unsigned short pci_subsystem_vendor;
  899. unsigned short pci_subsystem_device;
  900. bool pci_subsystem_set;
  901. #endif /* CONFIG_PCI */
  902. char topology_shortname[32];
  903. struct device *dev;
  904. struct snd_card *snd_card;
  905. struct module *owner;
  906. struct mutex mutex;
  907. struct mutex dapm_mutex;
  908. /* Mutex for PCM operations */
  909. struct mutex pcm_mutex;
  910. enum snd_soc_pcm_subclass pcm_subclass;
  911. int (*probe)(struct snd_soc_card *card);
  912. int (*late_probe)(struct snd_soc_card *card);
  913. void (*fixup_controls)(struct snd_soc_card *card);
  914. int (*remove)(struct snd_soc_card *card);
  915. /* the pre and post PM functions are used to do any PM work before and
  916. * after the codec and DAI's do any PM work. */
  917. int (*suspend_pre)(struct snd_soc_card *card);
  918. int (*suspend_post)(struct snd_soc_card *card);
  919. int (*resume_pre)(struct snd_soc_card *card);
  920. int (*resume_post)(struct snd_soc_card *card);
  921. /* callbacks */
  922. int (*set_bias_level)(struct snd_soc_card *,
  923. struct snd_soc_dapm_context *dapm,
  924. enum snd_soc_bias_level level);
  925. int (*set_bias_level_post)(struct snd_soc_card *,
  926. struct snd_soc_dapm_context *dapm,
  927. enum snd_soc_bias_level level);
  928. int (*add_dai_link)(struct snd_soc_card *,
  929. struct snd_soc_dai_link *link);
  930. void (*remove_dai_link)(struct snd_soc_card *,
  931. struct snd_soc_dai_link *link);
  932. long pmdown_time;
  933. /* CPU <--> Codec DAI links */
  934. struct snd_soc_dai_link *dai_link; /* predefined links only */
  935. int num_links; /* predefined links only */
  936. struct list_head rtd_list;
  937. int num_rtd;
  938. /* optional codec specific configuration */
  939. struct snd_soc_codec_conf *codec_conf;
  940. int num_configs;
  941. /*
  942. * optional auxiliary devices such as amplifiers or codecs with DAI
  943. * link unused
  944. */
  945. struct snd_soc_aux_dev *aux_dev;
  946. int num_aux_devs;
  947. struct list_head aux_comp_list;
  948. const struct snd_kcontrol_new *controls;
  949. int num_controls;
  950. /*
  951. * Card-specific routes and widgets.
  952. * Note: of_dapm_xxx for Device Tree; Otherwise for driver build-in.
  953. */
  954. const struct snd_soc_dapm_widget *dapm_widgets;
  955. int num_dapm_widgets;
  956. const struct snd_soc_dapm_route *dapm_routes;
  957. int num_dapm_routes;
  958. const struct snd_soc_dapm_widget *of_dapm_widgets;
  959. int num_of_dapm_widgets;
  960. const struct snd_soc_dapm_route *of_dapm_routes;
  961. int num_of_dapm_routes;
  962. /* lists of probed devices belonging to this card */
  963. struct list_head component_dev_list;
  964. struct list_head list;
  965. struct list_head widgets;
  966. struct list_head paths;
  967. struct list_head dapm_list;
  968. struct list_head dapm_dirty;
  969. /* attached dynamic objects */
  970. struct list_head dobj_list;
  971. /* Generic DAPM context for the card */
  972. struct snd_soc_dapm_context *dapm;
  973. struct snd_soc_dapm_stats dapm_stats;
  974. #ifdef CONFIG_DEBUG_FS
  975. struct dentry *debugfs_card_root;
  976. #endif
  977. #ifdef CONFIG_PM_SLEEP
  978. struct work_struct deferred_resume_work;
  979. #endif
  980. u32 pop_time;
  981. /* bit field */
  982. unsigned int instantiated:1;
  983. unsigned int topology_shortname_created:1;
  984. unsigned int fully_routed:1;
  985. unsigned int probed:1;
  986. unsigned int component_chaining:1;
  987. struct device *devres_dev;
  988. void *drvdata;
  989. };
  990. #define for_each_card_prelinks(card, i, link) \
  991. for ((i) = 0; \
  992. ((i) < (card)->num_links) && ((link) = &(card)->dai_link[i]); \
  993. (i)++)
  994. #define for_each_card_pre_auxs(card, i, aux) \
  995. for ((i) = 0; \
  996. ((i) < (card)->num_aux_devs) && ((aux) = &(card)->aux_dev[i]); \
  997. (i)++)
  998. #define for_each_card_rtds(card, rtd) \
  999. list_for_each_entry(rtd, &(card)->rtd_list, list)
  1000. #define for_each_card_rtds_safe(card, rtd, _rtd) \
  1001. list_for_each_entry_safe(rtd, _rtd, &(card)->rtd_list, list)
  1002. #define for_each_card_auxs(card, component) \
  1003. list_for_each_entry(component, &card->aux_comp_list, card_aux_list)
  1004. #define for_each_card_auxs_safe(card, component, _comp) \
  1005. list_for_each_entry_safe(component, _comp, \
  1006. &card->aux_comp_list, card_aux_list)
  1007. #define for_each_card_components(card, component) \
  1008. list_for_each_entry(component, &(card)->component_dev_list, card_list)
  1009. #define for_each_card_dapms(card, dapm) \
  1010. list_for_each_entry(dapm, &card->dapm_list, list)
  1011. #define for_each_card_widgets(card, w)\
  1012. list_for_each_entry(w, &card->widgets, list)
  1013. #define for_each_card_widgets_safe(card, w, _w) \
  1014. list_for_each_entry_safe(w, _w, &card->widgets, list)
  1015. static inline int snd_soc_card_is_instantiated(struct snd_soc_card *card)
  1016. {
  1017. return card && card->instantiated;
  1018. }
  1019. static inline struct snd_soc_dapm_context *snd_soc_card_to_dapm(struct snd_soc_card *card)
  1020. {
  1021. return card->dapm;
  1022. }
  1023. /* SoC machine DAI configuration, glues a codec and cpu DAI together */
  1024. struct snd_soc_pcm_runtime {
  1025. struct device *dev;
  1026. struct snd_soc_card *card;
  1027. struct snd_soc_dai_link *dai_link;
  1028. struct snd_pcm_ops ops;
  1029. unsigned int c2c_params_select; /* currently selected c2c_param for dai link */
  1030. /* Dynamic PCM BE runtime data */
  1031. struct snd_soc_dpcm_runtime dpcm[SNDRV_PCM_STREAM_LAST + 1];
  1032. struct snd_soc_dapm_widget *c2c_widget[SNDRV_PCM_STREAM_LAST + 1];
  1033. long pmdown_time;
  1034. /* runtime devices */
  1035. struct snd_pcm *pcm;
  1036. struct snd_compr *compr;
  1037. /*
  1038. * dais = cpu_dai + codec_dai
  1039. * see
  1040. * soc_new_pcm_runtime()
  1041. * snd_soc_rtd_to_cpu()
  1042. * snd_soc_rtd_to_codec()
  1043. */
  1044. struct snd_soc_dai **dais;
  1045. struct delayed_work delayed_work;
  1046. void (*close_delayed_work_func)(struct snd_soc_pcm_runtime *rtd);
  1047. #ifdef CONFIG_DEBUG_FS
  1048. struct dentry *debugfs_dpcm_root;
  1049. #endif
  1050. unsigned int id; /* 0-based and monotonic increasing */
  1051. struct list_head list; /* rtd list of the soc card */
  1052. /* function mark */
  1053. struct snd_pcm_substream *mark_startup;
  1054. struct snd_pcm_substream *mark_hw_params;
  1055. struct snd_pcm_substream *mark_trigger;
  1056. struct snd_compr_stream *mark_compr_startup;
  1057. /* bit field */
  1058. unsigned int pop_wait:1;
  1059. unsigned int fe_compr:1; /* for Dynamic PCM */
  1060. unsigned int initialized:1;
  1061. /* CPU/Codec/Platform */
  1062. int num_components;
  1063. struct snd_soc_component *components[] __counted_by(num_components);
  1064. };
  1065. /* see soc_new_pcm_runtime() */
  1066. #define snd_soc_rtd_to_cpu(rtd, n) (rtd)->dais[n]
  1067. #define snd_soc_rtd_to_codec(rtd, n) (rtd)->dais[n + (rtd)->dai_link->num_cpus]
  1068. static inline struct snd_soc_pcm_runtime *
  1069. snd_soc_substream_to_rtd(const struct snd_pcm_substream *substream)
  1070. {
  1071. return snd_pcm_substream_chip(substream);
  1072. }
  1073. #define for_each_rtd_components(rtd, i, component) \
  1074. for ((i) = 0, component = NULL; \
  1075. ((i) < rtd->num_components) && ((component) = rtd->components[i]);\
  1076. (i)++)
  1077. #define for_each_rtd_cpu_dais(rtd, i, dai) \
  1078. for ((i) = 0; \
  1079. ((i) < rtd->dai_link->num_cpus) && ((dai) = snd_soc_rtd_to_cpu(rtd, i)); \
  1080. (i)++)
  1081. #define for_each_rtd_codec_dais(rtd, i, dai) \
  1082. for ((i) = 0; \
  1083. ((i) < rtd->dai_link->num_codecs) && ((dai) = snd_soc_rtd_to_codec(rtd, i)); \
  1084. (i)++)
  1085. #define for_each_rtd_dais(rtd, i, dai) \
  1086. for ((i) = 0; \
  1087. ((i) < (rtd)->dai_link->num_cpus + (rtd)->dai_link->num_codecs) && \
  1088. ((dai) = (rtd)->dais[i]); \
  1089. (i)++)
  1090. #define for_each_rtd_dais_reverse(rtd, i, dai) \
  1091. for ((i) = (rtd)->dai_link->num_cpus + (rtd)->dai_link->num_codecs - 1; \
  1092. (i) >= 0 && ((dai) = (rtd)->dais[i]); \
  1093. (i)--)
  1094. #define for_each_rtd_ch_maps(rtd, i, ch_maps) for_each_link_ch_maps(rtd->dai_link, i, ch_maps)
  1095. void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd);
  1096. /* mixer control */
  1097. struct soc_mixer_control {
  1098. /* Minimum and maximum specified as written to the hardware */
  1099. int min, max;
  1100. /* Limited maximum value specified as presented through the control */
  1101. int platform_max;
  1102. int reg, rreg;
  1103. unsigned int shift, rshift;
  1104. u32 num_channels;
  1105. unsigned int sign_bit;
  1106. unsigned int invert:1;
  1107. unsigned int autodisable:1;
  1108. unsigned int sdca_q78:1;
  1109. #ifdef CONFIG_SND_SOC_TOPOLOGY
  1110. struct snd_soc_dobj dobj;
  1111. #endif
  1112. };
  1113. struct soc_bytes {
  1114. int base;
  1115. int num_regs;
  1116. u32 mask;
  1117. };
  1118. struct soc_bytes_ext {
  1119. int max;
  1120. #ifdef CONFIG_SND_SOC_TOPOLOGY
  1121. struct snd_soc_dobj dobj;
  1122. #endif
  1123. /* used for TLV byte control */
  1124. int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
  1125. unsigned int size);
  1126. int (*put)(struct snd_kcontrol *kcontrol, const unsigned int __user *bytes,
  1127. unsigned int size);
  1128. };
  1129. /* multi register control */
  1130. struct soc_mreg_control {
  1131. long min, max;
  1132. unsigned int regbase, regcount, nbits, invert;
  1133. };
  1134. /* enumerated kcontrol */
  1135. struct soc_enum {
  1136. int reg;
  1137. unsigned char shift_l;
  1138. unsigned char shift_r;
  1139. unsigned int items;
  1140. unsigned int mask;
  1141. const char * const *texts;
  1142. const unsigned int *values;
  1143. unsigned int autodisable:1;
  1144. #ifdef CONFIG_SND_SOC_TOPOLOGY
  1145. struct snd_soc_dobj dobj;
  1146. #endif
  1147. };
  1148. static inline bool snd_soc_volsw_is_stereo(const struct soc_mixer_control *mc)
  1149. {
  1150. if (mc->reg == mc->rreg && mc->shift == mc->rshift)
  1151. return false;
  1152. /*
  1153. * mc->reg == mc->rreg && mc->shift != mc->rshift, or
  1154. * mc->reg != mc->rreg means that the control is
  1155. * stereo (bits in one register or in two registers)
  1156. */
  1157. return true;
  1158. }
  1159. static inline unsigned int snd_soc_enum_val_to_item(const struct soc_enum *e,
  1160. unsigned int val)
  1161. {
  1162. unsigned int i;
  1163. if (!e->values)
  1164. return val;
  1165. for (i = 0; i < e->items; i++)
  1166. if (val == e->values[i])
  1167. return i;
  1168. return 0;
  1169. }
  1170. static inline unsigned int snd_soc_enum_item_to_val(const struct soc_enum *e,
  1171. unsigned int item)
  1172. {
  1173. if (!e->values)
  1174. return item;
  1175. return e->values[item];
  1176. }
  1177. int snd_soc_util_init(void);
  1178. void snd_soc_util_exit(void);
  1179. int snd_soc_of_parse_card_name(struct snd_soc_card *card,
  1180. const char *propname);
  1181. int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
  1182. const char *propname);
  1183. int snd_soc_of_parse_pin_switches(struct snd_soc_card *card, const char *prop);
  1184. int snd_soc_of_get_slot_mask(struct device_node *np,
  1185. const char *prop_name,
  1186. unsigned int *mask);
  1187. int snd_soc_of_parse_tdm_slot(struct device_node *np,
  1188. unsigned int *tx_mask,
  1189. unsigned int *rx_mask,
  1190. unsigned int *slots,
  1191. unsigned int *slot_width);
  1192. void snd_soc_of_parse_node_prefix(struct device_node *np,
  1193. struct snd_soc_codec_conf *codec_conf,
  1194. struct device_node *of_node,
  1195. const char *propname);
  1196. static inline
  1197. void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
  1198. struct snd_soc_codec_conf *codec_conf,
  1199. struct device_node *of_node,
  1200. const char *propname)
  1201. {
  1202. snd_soc_of_parse_node_prefix(card->dev->of_node,
  1203. codec_conf, of_node, propname);
  1204. }
  1205. int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
  1206. const char *propname);
  1207. int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname);
  1208. unsigned int snd_soc_daifmt_clock_provider_flipped(unsigned int dai_fmt);
  1209. unsigned int snd_soc_daifmt_clock_provider_from_bitmap(unsigned int bit_frame);
  1210. unsigned int snd_soc_daifmt_parse_format(struct device_node *np, const char *prefix);
  1211. unsigned int snd_soc_daifmt_parse_clock_provider_raw(struct device_node *np,
  1212. const char *prefix,
  1213. struct device_node **bitclkmaster,
  1214. struct device_node **framemaster);
  1215. #define snd_soc_daifmt_parse_clock_provider_as_bitmap(np, prefix) \
  1216. snd_soc_daifmt_parse_clock_provider_raw(np, prefix, NULL, NULL)
  1217. #define snd_soc_daifmt_parse_clock_provider_as_phandle \
  1218. snd_soc_daifmt_parse_clock_provider_raw
  1219. #define snd_soc_daifmt_parse_clock_provider_as_flag(np, prefix) \
  1220. snd_soc_daifmt_clock_provider_from_bitmap( \
  1221. snd_soc_daifmt_parse_clock_provider_as_bitmap(np, prefix))
  1222. int snd_soc_get_stream_cpu(const struct snd_soc_dai_link *dai_link, int stream);
  1223. int snd_soc_get_dlc(const struct of_phandle_args *args,
  1224. struct snd_soc_dai_link_component *dlc);
  1225. int snd_soc_of_get_dlc(struct device_node *of_node,
  1226. struct of_phandle_args *args,
  1227. struct snd_soc_dai_link_component *dlc,
  1228. int index);
  1229. int snd_soc_get_dai_id(struct device_node *ep);
  1230. int snd_soc_get_dai_name(const struct of_phandle_args *args,
  1231. const char **dai_name);
  1232. int snd_soc_of_get_dai_name(struct device_node *of_node,
  1233. const char **dai_name, int index);
  1234. int snd_soc_of_get_dai_link_codecs(struct device *dev,
  1235. struct device_node *of_node,
  1236. struct snd_soc_dai_link *dai_link);
  1237. void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link);
  1238. int snd_soc_of_get_dai_link_cpus(struct device *dev,
  1239. struct device_node *of_node,
  1240. struct snd_soc_dai_link *dai_link);
  1241. void snd_soc_of_put_dai_link_cpus(struct snd_soc_dai_link *dai_link);
  1242. int snd_soc_add_pcm_runtimes(struct snd_soc_card *card,
  1243. struct snd_soc_dai_link *dai_link,
  1244. int num_dai_link);
  1245. void snd_soc_remove_pcm_runtime(struct snd_soc_card *card,
  1246. struct snd_soc_pcm_runtime *rtd);
  1247. void snd_soc_dlc_use_cpu_as_platform(struct snd_soc_dai_link_component *platforms,
  1248. struct snd_soc_dai_link_component *cpus);
  1249. struct of_phandle_args *snd_soc_copy_dai_args(struct device *dev,
  1250. const struct of_phandle_args *args);
  1251. struct snd_soc_dai *snd_soc_get_dai_via_args(const struct of_phandle_args *dai_args);
  1252. struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
  1253. struct snd_soc_dai_driver *dai_drv,
  1254. bool legacy_dai_naming);
  1255. void snd_soc_unregister_dai(struct snd_soc_dai *dai);
  1256. struct snd_soc_dai *snd_soc_find_dai(
  1257. const struct snd_soc_dai_link_component *dlc);
  1258. struct snd_soc_dai *snd_soc_find_dai_with_mutex(
  1259. const struct snd_soc_dai_link_component *dlc);
  1260. #include <sound/soc-dai.h>
  1261. static inline
  1262. int snd_soc_fixup_dai_links_platform_name(struct snd_soc_card *card,
  1263. const char *platform_name)
  1264. {
  1265. struct snd_soc_dai_link *dai_link;
  1266. const char *name;
  1267. int i;
  1268. if (!platform_name) /* nothing to do */
  1269. return 0;
  1270. /* set platform name for each dailink */
  1271. for_each_card_prelinks(card, i, dai_link) {
  1272. /* only single platform is supported for now */
  1273. if (dai_link->num_platforms != 1)
  1274. return -EINVAL;
  1275. if (!dai_link->platforms)
  1276. return -EINVAL;
  1277. name = devm_kstrdup(card->dev, platform_name, GFP_KERNEL);
  1278. if (!name)
  1279. return -ENOMEM;
  1280. /* only single platform is supported for now */
  1281. dai_link->platforms->name = name;
  1282. }
  1283. return 0;
  1284. }
  1285. #ifdef CONFIG_DEBUG_FS
  1286. extern struct dentry *snd_soc_debugfs_root;
  1287. #endif
  1288. extern const struct dev_pm_ops snd_soc_pm_ops;
  1289. /*
  1290. * DAPM helper functions
  1291. */
  1292. enum snd_soc_dapm_subclass {
  1293. SND_SOC_DAPM_CLASS_ROOT = 0,
  1294. SND_SOC_DAPM_CLASS_RUNTIME = 1,
  1295. };
  1296. static inline void _snd_soc_dapm_mutex_lock_root_c(struct snd_soc_card *card)
  1297. {
  1298. mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_ROOT);
  1299. }
  1300. static inline void _snd_soc_dapm_mutex_lock_c(struct snd_soc_card *card)
  1301. {
  1302. mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
  1303. }
  1304. static inline void _snd_soc_dapm_mutex_unlock_c(struct snd_soc_card *card)
  1305. {
  1306. mutex_unlock(&card->dapm_mutex);
  1307. }
  1308. static inline void _snd_soc_dapm_mutex_assert_held_c(struct snd_soc_card *card)
  1309. {
  1310. lockdep_assert_held(&card->dapm_mutex);
  1311. }
  1312. static inline void _snd_soc_dapm_mutex_lock_root_d(struct snd_soc_dapm_context *dapm)
  1313. {
  1314. _snd_soc_dapm_mutex_lock_root_c(snd_soc_dapm_to_card(dapm));
  1315. }
  1316. static inline void _snd_soc_dapm_mutex_lock_d(struct snd_soc_dapm_context *dapm)
  1317. {
  1318. _snd_soc_dapm_mutex_lock_c(snd_soc_dapm_to_card(dapm));
  1319. }
  1320. static inline void _snd_soc_dapm_mutex_unlock_d(struct snd_soc_dapm_context *dapm)
  1321. {
  1322. _snd_soc_dapm_mutex_unlock_c(snd_soc_dapm_to_card(dapm));
  1323. }
  1324. static inline void _snd_soc_dapm_mutex_assert_held_d(struct snd_soc_dapm_context *dapm)
  1325. {
  1326. _snd_soc_dapm_mutex_assert_held_c(snd_soc_dapm_to_card(dapm));
  1327. }
  1328. #define snd_soc_dapm_mutex_lock_root(x) _Generic((x), \
  1329. struct snd_soc_card * : _snd_soc_dapm_mutex_lock_root_c, \
  1330. struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_lock_root_d)(x)
  1331. #define snd_soc_dapm_mutex_lock(x) _Generic((x), \
  1332. struct snd_soc_card * : _snd_soc_dapm_mutex_lock_c, \
  1333. struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_lock_d)(x)
  1334. #define snd_soc_dapm_mutex_unlock(x) _Generic((x), \
  1335. struct snd_soc_card * : _snd_soc_dapm_mutex_unlock_c, \
  1336. struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_unlock_d)(x)
  1337. #define snd_soc_dapm_mutex_assert_held(x) _Generic((x), \
  1338. struct snd_soc_card * : _snd_soc_dapm_mutex_assert_held_c, \
  1339. struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_assert_held_d)(x)
  1340. /*
  1341. * PCM helper functions
  1342. */
  1343. static inline void _snd_soc_dpcm_mutex_lock_c(struct snd_soc_card *card)
  1344. {
  1345. mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass);
  1346. }
  1347. static inline void _snd_soc_dpcm_mutex_unlock_c(struct snd_soc_card *card)
  1348. {
  1349. mutex_unlock(&card->pcm_mutex);
  1350. }
  1351. static inline void _snd_soc_dpcm_mutex_assert_held_c(struct snd_soc_card *card)
  1352. {
  1353. lockdep_assert_held(&card->pcm_mutex);
  1354. }
  1355. static inline void _snd_soc_dpcm_mutex_lock_r(struct snd_soc_pcm_runtime *rtd)
  1356. {
  1357. _snd_soc_dpcm_mutex_lock_c(rtd->card);
  1358. }
  1359. static inline void _snd_soc_dpcm_mutex_unlock_r(struct snd_soc_pcm_runtime *rtd)
  1360. {
  1361. _snd_soc_dpcm_mutex_unlock_c(rtd->card);
  1362. }
  1363. static inline void _snd_soc_dpcm_mutex_assert_held_r(struct snd_soc_pcm_runtime *rtd)
  1364. {
  1365. _snd_soc_dpcm_mutex_assert_held_c(rtd->card);
  1366. }
  1367. #define snd_soc_dpcm_mutex_lock(x) _Generic((x), \
  1368. struct snd_soc_card * : _snd_soc_dpcm_mutex_lock_c, \
  1369. struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_lock_r)(x)
  1370. #define snd_soc_dpcm_mutex_unlock(x) _Generic((x), \
  1371. struct snd_soc_card * : _snd_soc_dpcm_mutex_unlock_c, \
  1372. struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_unlock_r)(x)
  1373. #define snd_soc_dpcm_mutex_assert_held(x) _Generic((x), \
  1374. struct snd_soc_card * : _snd_soc_dpcm_mutex_assert_held_c, \
  1375. struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_assert_held_r)(x)
  1376. #include <sound/soc-component.h>
  1377. #include <sound/soc-card.h>
  1378. #include <sound/soc-jack.h>
  1379. #endif