soc.h 55 KB

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