soc.h 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763
  1. /*
  2. * linux/sound/soc.h -- ALSA SoC Layer
  3. *
  4. * Author: Liam Girdwood
  5. * Created: Aug 11th 2005
  6. * Copyright: Wolfson Microelectronics. PLC.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef __LINUX_SND_SOC_H
  13. #define __LINUX_SND_SOC_H
  14. #include <linux/of.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/types.h>
  17. #include <linux/notifier.h>
  18. #include <linux/workqueue.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/kernel.h>
  21. #include <linux/regmap.h>
  22. #include <linux/log2.h>
  23. #include <sound/core.h>
  24. #include <sound/pcm.h>
  25. #include <sound/compress_driver.h>
  26. #include <sound/control.h>
  27. #include <sound/ac97_codec.h>
  28. /*
  29. * Convenience kcontrol builders
  30. */
  31. #define SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, xmax, xinvert, xautodisable) \
  32. ((unsigned long)&(struct soc_mixer_control) \
  33. {.reg = xreg, .rreg = xreg, .shift = shift_left, \
  34. .rshift = shift_right, .max = xmax, .platform_max = xmax, \
  35. .invert = xinvert, .autodisable = xautodisable})
  36. #define SOC_DOUBLE_S_VALUE(xreg, shift_left, shift_right, xmin, xmax, xsign_bit, xinvert, xautodisable) \
  37. ((unsigned long)&(struct soc_mixer_control) \
  38. {.reg = xreg, .rreg = xreg, .shift = shift_left, \
  39. .rshift = shift_right, .min = xmin, .max = xmax, .platform_max = xmax, \
  40. .sign_bit = xsign_bit, .invert = xinvert, .autodisable = xautodisable})
  41. #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, xautodisable) \
  42. SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert, xautodisable)
  43. #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
  44. ((unsigned long)&(struct soc_mixer_control) \
  45. {.reg = xreg, .max = xmax, .platform_max = xmax, .invert = xinvert})
  46. #define SOC_DOUBLE_R_VALUE(xlreg, xrreg, xshift, xmax, xinvert) \
  47. ((unsigned long)&(struct soc_mixer_control) \
  48. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  49. .max = xmax, .platform_max = xmax, .invert = xinvert})
  50. #define SOC_DOUBLE_R_S_VALUE(xlreg, xrreg, xshift, xmin, xmax, xsign_bit, xinvert) \
  51. ((unsigned long)&(struct soc_mixer_control) \
  52. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  53. .max = xmax, .min = xmin, .platform_max = xmax, .sign_bit = xsign_bit, \
  54. .invert = xinvert})
  55. #define SOC_DOUBLE_R_RANGE_VALUE(xlreg, xrreg, xshift, xmin, xmax, xinvert) \
  56. ((unsigned long)&(struct soc_mixer_control) \
  57. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  58. .min = xmin, .max = xmax, .platform_max = xmax, .invert = xinvert})
  59. #define SOC_SINGLE(xname, reg, shift, max, invert) \
  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(reg, shift, max, invert, 0) }
  64. #define SOC_SINGLE_RANGE(xname, xreg, xshift, xmin, xmax, xinvert) \
  65. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  66. .info = snd_soc_info_volsw_range, .get = snd_soc_get_volsw_range, \
  67. .put = snd_soc_put_volsw_range, \
  68. .private_value = (unsigned long)&(struct soc_mixer_control) \
  69. {.reg = xreg, .rreg = xreg, .shift = xshift, \
  70. .rshift = xshift, .min = xmin, .max = xmax, \
  71. .platform_max = xmax, .invert = xinvert} }
  72. #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, 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, .get = snd_soc_get_volsw,\
  78. .put = snd_soc_put_volsw, \
  79. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  80. #define SOC_SINGLE_SX_TLV(xname, xreg, xshift, xmin, xmax, tlv_array) \
  81. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  82. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  83. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  84. .tlv.p = (tlv_array),\
  85. .info = snd_soc_info_volsw_sx, \
  86. .get = snd_soc_get_volsw_sx,\
  87. .put = snd_soc_put_volsw_sx, \
  88. .private_value = (unsigned long)&(struct soc_mixer_control) \
  89. {.reg = xreg, .rreg = xreg, \
  90. .shift = xshift, .rshift = xshift, \
  91. .max = xmax, .min = xmin} }
  92. #define SOC_SINGLE_RANGE_TLV(xname, xreg, xshift, xmin, xmax, xinvert, tlv_array) \
  93. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  94. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  95. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  96. .tlv.p = (tlv_array), \
  97. .info = snd_soc_info_volsw_range, \
  98. .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
  99. .private_value = (unsigned long)&(struct soc_mixer_control) \
  100. {.reg = xreg, .rreg = xreg, .shift = xshift, \
  101. .rshift = xshift, .min = xmin, .max = xmax, \
  102. .platform_max = xmax, .invert = xinvert} }
  103. #define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
  104. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  105. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  106. .put = snd_soc_put_volsw, \
  107. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  108. max, invert, 0) }
  109. #define SOC_DOUBLE_STS(xname, reg, shift_left, shift_right, max, invert) \
  110. { \
  111. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  112. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  113. .access = SNDRV_CTL_ELEM_ACCESS_READ | \
  114. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  115. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  116. max, invert, 0) }
  117. #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
  118. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  119. .info = snd_soc_info_volsw, \
  120. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  121. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  122. xmax, xinvert) }
  123. #define SOC_DOUBLE_R_RANGE(xname, reg_left, reg_right, xshift, xmin, \
  124. xmax, xinvert) \
  125. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  126. .info = snd_soc_info_volsw_range, \
  127. .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
  128. .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \
  129. xshift, xmin, xmax, xinvert) }
  130. #define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
  131. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  132. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  133. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  134. .tlv.p = (tlv_array), \
  135. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  136. .put = snd_soc_put_volsw, \
  137. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  138. max, invert, 0) }
  139. #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
  140. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  141. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  142. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  143. .tlv.p = (tlv_array), \
  144. .info = snd_soc_info_volsw, \
  145. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  146. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  147. xmax, xinvert) }
  148. #define SOC_DOUBLE_R_RANGE_TLV(xname, reg_left, reg_right, xshift, xmin, \
  149. xmax, xinvert, tlv_array) \
  150. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  151. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  152. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  153. .tlv.p = (tlv_array), \
  154. .info = snd_soc_info_volsw_range, \
  155. .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
  156. .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \
  157. xshift, xmin, xmax, xinvert) }
  158. #define SOC_DOUBLE_R_SX_TLV(xname, xreg, xrreg, xshift, xmin, xmax, tlv_array) \
  159. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  160. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  161. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  162. .tlv.p = (tlv_array), \
  163. .info = snd_soc_info_volsw_sx, \
  164. .get = snd_soc_get_volsw_sx, \
  165. .put = snd_soc_put_volsw_sx, \
  166. .private_value = (unsigned long)&(struct soc_mixer_control) \
  167. {.reg = xreg, .rreg = xrreg, \
  168. .shift = xshift, .rshift = xshift, \
  169. .max = xmax, .min = xmin} }
  170. #define SOC_DOUBLE_R_S_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \
  171. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  172. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  173. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  174. .tlv.p = (tlv_array), \
  175. .info = snd_soc_info_volsw, \
  176. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  177. .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \
  178. xmin, xmax, xsign_bit, xinvert) }
  179. #define SOC_SINGLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  180. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  181. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  182. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  183. .tlv.p = (tlv_array), \
  184. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  185. .put = snd_soc_put_volsw, \
  186. .private_value = (unsigned long)&(struct soc_mixer_control) \
  187. {.reg = xreg, .rreg = xreg, \
  188. .min = xmin, .max = xmax, .platform_max = xmax, \
  189. .sign_bit = 7,} }
  190. #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  191. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  192. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  193. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  194. .tlv.p = (tlv_array), \
  195. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  196. .put = snd_soc_put_volsw, \
  197. .private_value = SOC_DOUBLE_S_VALUE(xreg, 0, 8, xmin, xmax, 7, 0, 0) }
  198. #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xitems, xtexts) \
  199. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  200. .items = xitems, .texts = xtexts, \
  201. .mask = xitems ? roundup_pow_of_two(xitems) - 1 : 0}
  202. #define SOC_ENUM_SINGLE(xreg, xshift, xitems, xtexts) \
  203. SOC_ENUM_DOUBLE(xreg, xshift, xshift, xitems, xtexts)
  204. #define SOC_ENUM_SINGLE_EXT(xitems, xtexts) \
  205. { .items = xitems, .texts = xtexts }
  206. #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xitems, xtexts, xvalues) \
  207. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  208. .mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues}
  209. #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
  210. SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xitems, xtexts, xvalues)
  211. #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
  212. { .reg = xreg, .shift_l = xshift, .shift_r = xshift, \
  213. .mask = xmask, .items = xitems, .texts = xtexts, \
  214. .values = xvalues, .autodisable = 1}
  215. #define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \
  216. SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts)
  217. #define SOC_ENUM(xname, xenum) \
  218. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  219. .info = snd_soc_info_enum_double, \
  220. .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
  221. .private_value = (unsigned long)&xenum }
  222. #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
  223. xhandler_get, xhandler_put) \
  224. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  225. .info = snd_soc_info_volsw, \
  226. .get = xhandler_get, .put = xhandler_put, \
  227. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) }
  228. #define SOC_DOUBLE_EXT(xname, reg, shift_left, shift_right, max, invert,\
  229. xhandler_get, xhandler_put) \
  230. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  231. .info = snd_soc_info_volsw, \
  232. .get = xhandler_get, .put = xhandler_put, \
  233. .private_value = \
  234. SOC_DOUBLE_VALUE(reg, shift_left, shift_right, max, invert, 0) }
  235. #define SOC_DOUBLE_R_EXT(xname, reg_left, reg_right, xshift, xmax, xinvert,\
  236. xhandler_get, xhandler_put) \
  237. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  238. .info = snd_soc_info_volsw, \
  239. .get = xhandler_get, .put = xhandler_put, \
  240. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  241. xmax, xinvert) }
  242. #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
  243. xhandler_get, xhandler_put, tlv_array) \
  244. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  245. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  246. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  247. .tlv.p = (tlv_array), \
  248. .info = snd_soc_info_volsw, \
  249. .get = xhandler_get, .put = xhandler_put, \
  250. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) }
  251. #define SOC_SINGLE_RANGE_EXT_TLV(xname, xreg, xshift, xmin, xmax, xinvert, \
  252. xhandler_get, xhandler_put, tlv_array) \
  253. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  254. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  255. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  256. .tlv.p = (tlv_array), \
  257. .info = snd_soc_info_volsw_range, \
  258. .get = xhandler_get, .put = xhandler_put, \
  259. .private_value = (unsigned long)&(struct soc_mixer_control) \
  260. {.reg = xreg, .rreg = xreg, .shift = xshift, \
  261. .rshift = xshift, .min = xmin, .max = xmax, \
  262. .platform_max = xmax, .invert = xinvert} }
  263. #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
  264. xhandler_get, xhandler_put, tlv_array) \
  265. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  266. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  267. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  268. .tlv.p = (tlv_array), \
  269. .info = snd_soc_info_volsw, \
  270. .get = xhandler_get, .put = xhandler_put, \
  271. .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
  272. xmax, xinvert, 0) }
  273. #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, 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_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  282. xmax, xinvert) }
  283. #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
  284. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  285. .info = snd_soc_info_bool_ext, \
  286. .get = xhandler_get, .put = xhandler_put, \
  287. .private_value = xdata }
  288. #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
  289. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  290. .info = snd_soc_info_enum_double, \
  291. .get = xhandler_get, .put = xhandler_put, \
  292. .private_value = (unsigned long)&xenum }
  293. #define SOC_VALUE_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
  294. SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put)
  295. #define SND_SOC_BYTES(xname, xbase, xregs) \
  296. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  297. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  298. .put = snd_soc_bytes_put, .private_value = \
  299. ((unsigned long)&(struct soc_bytes) \
  300. {.base = xbase, .num_regs = xregs }) }
  301. #define SND_SOC_BYTES_MASK(xname, xbase, xregs, xmask) \
  302. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  303. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  304. .put = snd_soc_bytes_put, .private_value = \
  305. ((unsigned long)&(struct soc_bytes) \
  306. {.base = xbase, .num_regs = xregs, \
  307. .mask = xmask }) }
  308. /*
  309. * SND_SOC_BYTES_EXT is deprecated, please USE SND_SOC_BYTES_TLV instead
  310. */
  311. #define SND_SOC_BYTES_EXT(xname, xcount, xhandler_get, xhandler_put) \
  312. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  313. .info = snd_soc_bytes_info_ext, \
  314. .get = xhandler_get, .put = xhandler_put, \
  315. .private_value = (unsigned long)&(struct soc_bytes_ext) \
  316. {.max = xcount} }
  317. #define SND_SOC_BYTES_TLV(xname, xcount, xhandler_get, xhandler_put) \
  318. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  319. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE | \
  320. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
  321. .tlv.c = (snd_soc_bytes_tlv_callback), \
  322. .info = snd_soc_bytes_info_ext, \
  323. .private_value = (unsigned long)&(struct soc_bytes_ext) \
  324. {.max = xcount, .get = xhandler_get, .put = xhandler_put, } }
  325. #define SOC_SINGLE_XR_SX(xname, xregbase, xregcount, xnbits, \
  326. xmin, xmax, xinvert) \
  327. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  328. .info = snd_soc_info_xr_sx, .get = snd_soc_get_xr_sx, \
  329. .put = snd_soc_put_xr_sx, \
  330. .private_value = (unsigned long)&(struct soc_mreg_control) \
  331. {.regbase = xregbase, .regcount = xregcount, .nbits = xnbits, \
  332. .invert = xinvert, .min = xmin, .max = xmax} }
  333. #define SOC_SINGLE_STROBE(xname, xreg, xshift, xinvert) \
  334. SOC_SINGLE_EXT(xname, xreg, xshift, 1, xinvert, \
  335. snd_soc_get_strobe, snd_soc_put_strobe)
  336. /*
  337. * Simplified versions of above macros, declaring a struct and calculating
  338. * ARRAY_SIZE internally
  339. */
  340. #define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \
  341. const struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
  342. ARRAY_SIZE(xtexts), xtexts)
  343. #define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \
  344. SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
  345. #define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \
  346. const struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts)
  347. #define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \
  348. const struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \
  349. ARRAY_SIZE(xtexts), xtexts, xvalues)
  350. #define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
  351. SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
  352. #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
  353. const struct soc_enum name = SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, \
  354. xshift, xmask, ARRAY_SIZE(xtexts), xtexts, xvalues)
  355. #define SOC_ENUM_SINGLE_VIRT_DECL(name, xtexts) \
  356. const struct soc_enum name = SOC_ENUM_SINGLE_VIRT(ARRAY_SIZE(xtexts), xtexts)
  357. /*
  358. * Component probe and remove ordering levels for components with runtime
  359. * dependencies.
  360. */
  361. #define SND_SOC_COMP_ORDER_FIRST -2
  362. #define SND_SOC_COMP_ORDER_EARLY -1
  363. #define SND_SOC_COMP_ORDER_NORMAL 0
  364. #define SND_SOC_COMP_ORDER_LATE 1
  365. #define SND_SOC_COMP_ORDER_LAST 2
  366. /*
  367. * Bias levels
  368. *
  369. * @ON: Bias is fully on for audio playback and capture operations.
  370. * @PREPARE: Prepare for audio operations. Called before DAPM switching for
  371. * stream start and stop operations.
  372. * @STANDBY: Low power standby state when no playback/capture operations are
  373. * in progress. NOTE: The transition time between STANDBY and ON
  374. * should be as fast as possible and no longer than 10ms.
  375. * @OFF: Power Off. No restrictions on transition times.
  376. */
  377. enum snd_soc_bias_level {
  378. SND_SOC_BIAS_OFF = 0,
  379. SND_SOC_BIAS_STANDBY = 1,
  380. SND_SOC_BIAS_PREPARE = 2,
  381. SND_SOC_BIAS_ON = 3,
  382. };
  383. struct device_node;
  384. struct snd_jack;
  385. struct snd_soc_card;
  386. struct snd_soc_pcm_stream;
  387. struct snd_soc_ops;
  388. struct snd_soc_pcm_runtime;
  389. struct snd_soc_dai;
  390. struct snd_soc_dai_driver;
  391. struct snd_soc_platform;
  392. struct snd_soc_dai_link;
  393. struct snd_soc_platform_driver;
  394. struct snd_soc_codec;
  395. struct snd_soc_codec_driver;
  396. struct snd_soc_component;
  397. struct snd_soc_component_driver;
  398. struct soc_enum;
  399. struct snd_soc_jack;
  400. struct snd_soc_jack_zone;
  401. struct snd_soc_jack_pin;
  402. #include <sound/soc-dapm.h>
  403. #include <sound/soc-dpcm.h>
  404. #include <sound/soc-topology.h>
  405. struct snd_soc_jack_gpio;
  406. typedef int (*hw_write_t)(void *,const char* ,int);
  407. enum snd_soc_pcm_subclass {
  408. SND_SOC_PCM_CLASS_PCM = 0,
  409. SND_SOC_PCM_CLASS_BE = 1,
  410. };
  411. enum snd_soc_card_subclass {
  412. SND_SOC_CARD_CLASS_INIT = 0,
  413. SND_SOC_CARD_CLASS_RUNTIME = 1,
  414. };
  415. int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
  416. int source, unsigned int freq, int dir);
  417. int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
  418. unsigned int freq_in, unsigned int freq_out);
  419. int snd_soc_codec_set_jack(struct snd_soc_codec *codec,
  420. struct snd_soc_jack *jack, void *data);
  421. int snd_soc_register_card(struct snd_soc_card *card);
  422. int snd_soc_unregister_card(struct snd_soc_card *card);
  423. int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
  424. #ifdef CONFIG_PM_SLEEP
  425. int snd_soc_suspend(struct device *dev);
  426. int snd_soc_resume(struct device *dev);
  427. #else
  428. static inline int snd_soc_suspend(struct device *dev)
  429. {
  430. return 0;
  431. }
  432. static inline int snd_soc_resume(struct device *dev)
  433. {
  434. return 0;
  435. }
  436. #endif
  437. int snd_soc_poweroff(struct device *dev);
  438. int snd_soc_register_platform(struct device *dev,
  439. const struct snd_soc_platform_driver *platform_drv);
  440. int devm_snd_soc_register_platform(struct device *dev,
  441. const struct snd_soc_platform_driver *platform_drv);
  442. void snd_soc_unregister_platform(struct device *dev);
  443. int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
  444. const struct snd_soc_platform_driver *platform_drv);
  445. void snd_soc_remove_platform(struct snd_soc_platform *platform);
  446. struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev);
  447. int snd_soc_register_codec(struct device *dev,
  448. const struct snd_soc_codec_driver *codec_drv,
  449. struct snd_soc_dai_driver *dai_drv, int num_dai);
  450. void snd_soc_unregister_codec(struct device *dev);
  451. int snd_soc_register_component(struct device *dev,
  452. const struct snd_soc_component_driver *component_driver,
  453. struct snd_soc_dai_driver *dai_drv, int num_dai);
  454. int devm_snd_soc_register_component(struct device *dev,
  455. const struct snd_soc_component_driver *component_driver,
  456. struct snd_soc_dai_driver *dai_drv, int num_dai);
  457. void snd_soc_unregister_component(struct device *dev);
  458. int snd_soc_cache_init(struct snd_soc_codec *codec);
  459. int snd_soc_cache_exit(struct snd_soc_codec *codec);
  460. int snd_soc_platform_read(struct snd_soc_platform *platform,
  461. unsigned int reg);
  462. int snd_soc_platform_write(struct snd_soc_platform *platform,
  463. unsigned int reg, unsigned int val);
  464. int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
  465. #ifdef CONFIG_SND_SOC_COMPRESS
  466. int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num);
  467. #endif
  468. struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
  469. const char *dai_link, int stream);
  470. struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
  471. const char *dai_link);
  472. bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd);
  473. void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream);
  474. void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream);
  475. int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
  476. unsigned int dai_fmt);
  477. #ifdef CONFIG_DMI
  478. int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour);
  479. #else
  480. static inline int snd_soc_set_dmi_name(struct snd_soc_card *card,
  481. const char *flavour)
  482. {
  483. return 0;
  484. }
  485. #endif
  486. /* Utility functions to get clock rates from various things */
  487. int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
  488. int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
  489. int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
  490. int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);
  491. /* set runtime hw params */
  492. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  493. const struct snd_pcm_hardware *hw);
  494. int soc_dai_hw_params(struct snd_pcm_substream *substream,
  495. struct snd_pcm_hw_params *params,
  496. struct snd_soc_dai *dai);
  497. /* Jack reporting */
  498. int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
  499. struct snd_soc_jack *jack, struct snd_soc_jack_pin *pins,
  500. unsigned int num_pins);
  501. void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
  502. int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
  503. struct snd_soc_jack_pin *pins);
  504. void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
  505. struct notifier_block *nb);
  506. void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
  507. struct notifier_block *nb);
  508. int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
  509. struct snd_soc_jack_zone *zones);
  510. int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
  511. #ifdef CONFIG_GPIOLIB
  512. int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  513. struct snd_soc_jack_gpio *gpios);
  514. int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
  515. struct snd_soc_jack *jack,
  516. int count, struct snd_soc_jack_gpio *gpios);
  517. void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  518. struct snd_soc_jack_gpio *gpios);
  519. #else
  520. static inline int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  521. struct snd_soc_jack_gpio *gpios)
  522. {
  523. return 0;
  524. }
  525. static inline int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
  526. struct snd_soc_jack *jack,
  527. int count,
  528. struct snd_soc_jack_gpio *gpios)
  529. {
  530. return 0;
  531. }
  532. static inline void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  533. struct snd_soc_jack_gpio *gpios)
  534. {
  535. }
  536. #endif
  537. /* codec register bit access */
  538. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned int reg,
  539. unsigned int mask, unsigned int value);
  540. int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
  541. unsigned int reg, unsigned int mask,
  542. unsigned int value);
  543. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned int reg,
  544. unsigned int mask, unsigned int value);
  545. #ifdef CONFIG_SND_SOC_AC97_BUS
  546. struct snd_ac97 *snd_soc_alloc_ac97_codec(struct snd_soc_codec *codec);
  547. struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  548. unsigned int id, unsigned int id_mask);
  549. void snd_soc_free_ac97_codec(struct snd_ac97 *ac97);
  550. int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops);
  551. int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
  552. struct platform_device *pdev);
  553. extern struct snd_ac97_bus_ops *soc_ac97_ops;
  554. #else
  555. static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
  556. struct platform_device *pdev)
  557. {
  558. return 0;
  559. }
  560. static inline int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
  561. {
  562. return 0;
  563. }
  564. #endif
  565. /*
  566. *Controls
  567. */
  568. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  569. void *data, const char *long_name,
  570. const char *prefix);
  571. struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
  572. const char *name);
  573. int snd_soc_add_component_controls(struct snd_soc_component *component,
  574. const struct snd_kcontrol_new *controls, unsigned int num_controls);
  575. int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
  576. const struct snd_kcontrol_new *controls, unsigned int num_controls);
  577. int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
  578. const struct snd_kcontrol_new *controls, unsigned int num_controls);
  579. int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
  580. const struct snd_kcontrol_new *controls, int num_controls);
  581. int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
  582. const struct snd_kcontrol_new *controls, int num_controls);
  583. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  584. struct snd_ctl_elem_info *uinfo);
  585. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  586. struct snd_ctl_elem_value *ucontrol);
  587. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  588. struct snd_ctl_elem_value *ucontrol);
  589. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  590. struct snd_ctl_elem_info *uinfo);
  591. int snd_soc_info_volsw_sx(struct snd_kcontrol *kcontrol,
  592. struct snd_ctl_elem_info *uinfo);
  593. #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
  594. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  595. struct snd_ctl_elem_value *ucontrol);
  596. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  597. struct snd_ctl_elem_value *ucontrol);
  598. #define snd_soc_get_volsw_2r snd_soc_get_volsw
  599. #define snd_soc_put_volsw_2r snd_soc_put_volsw
  600. int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
  601. struct snd_ctl_elem_value *ucontrol);
  602. int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
  603. struct snd_ctl_elem_value *ucontrol);
  604. int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
  605. struct snd_ctl_elem_info *uinfo);
  606. int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
  607. struct snd_ctl_elem_value *ucontrol);
  608. int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
  609. struct snd_ctl_elem_value *ucontrol);
  610. int snd_soc_limit_volume(struct snd_soc_card *card,
  611. const char *name, int max);
  612. int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
  613. struct snd_ctl_elem_info *uinfo);
  614. int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
  615. struct snd_ctl_elem_value *ucontrol);
  616. int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
  617. struct snd_ctl_elem_value *ucontrol);
  618. int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,
  619. struct snd_ctl_elem_info *ucontrol);
  620. int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag,
  621. unsigned int size, unsigned int __user *tlv);
  622. int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
  623. struct snd_ctl_elem_info *uinfo);
  624. int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
  625. struct snd_ctl_elem_value *ucontrol);
  626. int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
  627. struct snd_ctl_elem_value *ucontrol);
  628. int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
  629. struct snd_ctl_elem_value *ucontrol);
  630. int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
  631. struct snd_ctl_elem_value *ucontrol);
  632. /**
  633. * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
  634. *
  635. * @pin: name of the pin to update
  636. * @mask: bits to check for in reported jack status
  637. * @invert: if non-zero then pin is enabled when status is not reported
  638. * @list: internal list entry
  639. */
  640. struct snd_soc_jack_pin {
  641. struct list_head list;
  642. const char *pin;
  643. int mask;
  644. bool invert;
  645. };
  646. /**
  647. * struct snd_soc_jack_zone - Describes voltage zones of jack detection
  648. *
  649. * @min_mv: start voltage in mv
  650. * @max_mv: end voltage in mv
  651. * @jack_type: type of jack that is expected for this voltage
  652. * @debounce_time: debounce_time for jack, codec driver should wait for this
  653. * duration before reading the adc for voltages
  654. * @list: internal list entry
  655. */
  656. struct snd_soc_jack_zone {
  657. unsigned int min_mv;
  658. unsigned int max_mv;
  659. unsigned int jack_type;
  660. unsigned int debounce_time;
  661. struct list_head list;
  662. };
  663. /**
  664. * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
  665. *
  666. * @gpio: legacy gpio number
  667. * @idx: gpio descriptor index within the function of the GPIO
  668. * consumer device
  669. * @gpiod_dev: GPIO consumer device
  670. * @name: gpio name. Also as connection ID for the GPIO consumer
  671. * device function name lookup
  672. * @report: value to report when jack detected
  673. * @invert: report presence in low state
  674. * @debounce_time: debounce time in ms
  675. * @wake: enable as wake source
  676. * @jack_status_check: callback function which overrides the detection
  677. * to provide more complex checks (eg, reading an
  678. * ADC).
  679. */
  680. struct snd_soc_jack_gpio {
  681. unsigned int gpio;
  682. unsigned int idx;
  683. struct device *gpiod_dev;
  684. const char *name;
  685. int report;
  686. int invert;
  687. int debounce_time;
  688. bool wake;
  689. /* private: */
  690. struct snd_soc_jack *jack;
  691. struct delayed_work work;
  692. struct notifier_block pm_notifier;
  693. struct gpio_desc *desc;
  694. void *data;
  695. /* public: */
  696. int (*jack_status_check)(void *data);
  697. };
  698. struct snd_soc_jack {
  699. struct mutex mutex;
  700. struct snd_jack *jack;
  701. struct snd_soc_card *card;
  702. struct list_head pins;
  703. int status;
  704. struct blocking_notifier_head notifier;
  705. struct list_head jack_zones;
  706. };
  707. /* SoC PCM stream information */
  708. struct snd_soc_pcm_stream {
  709. const char *stream_name;
  710. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  711. unsigned int rates; /* SNDRV_PCM_RATE_* */
  712. unsigned int rate_min; /* min rate */
  713. unsigned int rate_max; /* max rate */
  714. unsigned int channels_min; /* min channels */
  715. unsigned int channels_max; /* max channels */
  716. unsigned int sig_bits; /* number of bits of content */
  717. };
  718. /* SoC audio ops */
  719. struct snd_soc_ops {
  720. int (*startup)(struct snd_pcm_substream *);
  721. void (*shutdown)(struct snd_pcm_substream *);
  722. int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
  723. int (*hw_free)(struct snd_pcm_substream *);
  724. int (*prepare)(struct snd_pcm_substream *);
  725. int (*trigger)(struct snd_pcm_substream *, int);
  726. };
  727. struct snd_soc_compr_ops {
  728. int (*startup)(struct snd_compr_stream *);
  729. void (*shutdown)(struct snd_compr_stream *);
  730. int (*set_params)(struct snd_compr_stream *);
  731. int (*trigger)(struct snd_compr_stream *);
  732. };
  733. /* component interface */
  734. struct snd_soc_component_driver {
  735. const char *name;
  736. /* Default control and setup, added after probe() is run */
  737. const struct snd_kcontrol_new *controls;
  738. unsigned int num_controls;
  739. const struct snd_soc_dapm_widget *dapm_widgets;
  740. unsigned int num_dapm_widgets;
  741. const struct snd_soc_dapm_route *dapm_routes;
  742. unsigned int num_dapm_routes;
  743. int (*probe)(struct snd_soc_component *);
  744. void (*remove)(struct snd_soc_component *);
  745. int (*suspend)(struct snd_soc_component *);
  746. int (*resume)(struct snd_soc_component *);
  747. /* component wide operations */
  748. int (*set_sysclk)(struct snd_soc_component *component,
  749. int clk_id, int source, unsigned int freq, int dir);
  750. int (*set_pll)(struct snd_soc_component *component, int pll_id,
  751. int source, unsigned int freq_in, unsigned int freq_out);
  752. int (*set_jack)(struct snd_soc_component *component,
  753. struct snd_soc_jack *jack, void *data);
  754. /* DT */
  755. int (*of_xlate_dai_name)(struct snd_soc_component *component,
  756. struct of_phandle_args *args,
  757. const char **dai_name);
  758. int (*of_xlate_dai_id)(struct snd_soc_component *comment,
  759. struct device_node *endpoint);
  760. void (*seq_notifier)(struct snd_soc_component *, enum snd_soc_dapm_type,
  761. int subseq);
  762. int (*stream_event)(struct snd_soc_component *, int event);
  763. /* probe ordering - for components with runtime dependencies */
  764. int probe_order;
  765. int remove_order;
  766. };
  767. struct snd_soc_component {
  768. const char *name;
  769. int id;
  770. const char *name_prefix;
  771. struct device *dev;
  772. struct snd_soc_card *card;
  773. unsigned int active;
  774. unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */
  775. unsigned int registered_as_component:1;
  776. unsigned int suspended:1; /* is in suspend PM state */
  777. struct list_head list;
  778. struct list_head card_aux_list; /* for auxiliary bound components */
  779. struct list_head card_list;
  780. struct snd_soc_dai_driver *dai_drv;
  781. int num_dai;
  782. const struct snd_soc_component_driver *driver;
  783. struct list_head dai_list;
  784. int (*read)(struct snd_soc_component *, unsigned int, unsigned int *);
  785. int (*write)(struct snd_soc_component *, unsigned int, unsigned int);
  786. struct regmap *regmap;
  787. int val_bytes;
  788. struct mutex io_mutex;
  789. /* attached dynamic objects */
  790. struct list_head dobj_list;
  791. #ifdef CONFIG_DEBUG_FS
  792. struct dentry *debugfs_root;
  793. #endif
  794. /*
  795. * DO NOT use any of the fields below in drivers, they are temporary and
  796. * are going to be removed again soon. If you use them in driver code the
  797. * driver will be marked as BROKEN when these fields are removed.
  798. */
  799. /* Don't use these, use snd_soc_component_get_dapm() */
  800. struct snd_soc_dapm_context dapm;
  801. struct snd_soc_codec *codec;
  802. int (*probe)(struct snd_soc_component *);
  803. void (*remove)(struct snd_soc_component *);
  804. int (*suspend)(struct snd_soc_component *);
  805. int (*resume)(struct snd_soc_component *);
  806. int (*set_sysclk)(struct snd_soc_component *component,
  807. int clk_id, int source, unsigned int freq, int dir);
  808. int (*set_pll)(struct snd_soc_component *component, int pll_id,
  809. int source, unsigned int freq_in, unsigned int freq_out);
  810. int (*set_jack)(struct snd_soc_component *component,
  811. struct snd_soc_jack *jack, void *data);
  812. /* machine specific init */
  813. int (*init)(struct snd_soc_component *component);
  814. #ifdef CONFIG_DEBUG_FS
  815. void (*init_debugfs)(struct snd_soc_component *component);
  816. const char *debugfs_prefix;
  817. #endif
  818. };
  819. struct snd_soc_rtdcom_list {
  820. struct snd_soc_component *component;
  821. struct list_head list; /* rtd::component_list */
  822. };
  823. struct snd_soc_component*
  824. snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
  825. const char *driver_name);
  826. #define for_each_rtdcom(rtd, rtdcom) \
  827. list_for_each_entry(rtdcom, &(rtd)->component_list, list)
  828. #define for_each_rtdcom_safe(rtd, rtdcom1, rtdcom2) \
  829. list_for_each_entry_safe(rtdcom1, rtdcom2, &(rtd)->component_list, list)
  830. /* SoC Audio Codec device */
  831. struct snd_soc_codec {
  832. struct device *dev;
  833. const struct snd_soc_codec_driver *driver;
  834. struct list_head list;
  835. /* runtime */
  836. unsigned int cache_init:1; /* codec cache has been initialized */
  837. /* codec IO */
  838. void *control_data; /* codec control (i2c/3wire) data */
  839. hw_write_t hw_write;
  840. void *reg_cache;
  841. /* component */
  842. struct snd_soc_component component;
  843. };
  844. /* codec driver */
  845. struct snd_soc_codec_driver {
  846. /* driver ops */
  847. int (*probe)(struct snd_soc_codec *);
  848. int (*remove)(struct snd_soc_codec *);
  849. int (*suspend)(struct snd_soc_codec *);
  850. int (*resume)(struct snd_soc_codec *);
  851. struct snd_soc_component_driver component_driver;
  852. /* codec wide operations */
  853. int (*set_sysclk)(struct snd_soc_codec *codec,
  854. int clk_id, int source, unsigned int freq, int dir);
  855. int (*set_pll)(struct snd_soc_codec *codec, int pll_id, int source,
  856. unsigned int freq_in, unsigned int freq_out);
  857. int (*set_jack)(struct snd_soc_codec *codec,
  858. struct snd_soc_jack *jack, void *data);
  859. /* codec IO */
  860. struct regmap *(*get_regmap)(struct device *);
  861. unsigned int (*read)(struct snd_soc_codec *, unsigned int);
  862. int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
  863. unsigned int reg_cache_size;
  864. short reg_cache_step;
  865. short reg_word_size;
  866. const void *reg_cache_default;
  867. /* codec bias level */
  868. int (*set_bias_level)(struct snd_soc_codec *,
  869. enum snd_soc_bias_level level);
  870. bool idle_bias_off;
  871. bool suspend_bias_off;
  872. void (*seq_notifier)(struct snd_soc_dapm_context *,
  873. enum snd_soc_dapm_type, int);
  874. bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
  875. };
  876. /* SoC platform interface */
  877. struct snd_soc_platform_driver {
  878. int (*probe)(struct snd_soc_platform *);
  879. int (*remove)(struct snd_soc_platform *);
  880. struct snd_soc_component_driver component_driver;
  881. /* pcm creation and destruction */
  882. int (*pcm_new)(struct snd_soc_pcm_runtime *);
  883. void (*pcm_free)(struct snd_pcm *);
  884. /* platform stream pcm ops */
  885. const struct snd_pcm_ops *ops;
  886. /* platform stream compress ops */
  887. const struct snd_compr_ops *compr_ops;
  888. };
  889. struct snd_soc_dai_link_component {
  890. const char *name;
  891. struct device_node *of_node;
  892. const char *dai_name;
  893. };
  894. struct snd_soc_platform {
  895. struct device *dev;
  896. const struct snd_soc_platform_driver *driver;
  897. struct list_head list;
  898. struct snd_soc_component component;
  899. };
  900. struct snd_soc_dai_link {
  901. /* config - must be set by machine driver */
  902. const char *name; /* Codec name */
  903. const char *stream_name; /* Stream name */
  904. /*
  905. * You MAY specify the link's CPU-side device, either by device name,
  906. * or by DT/OF node, but not both. If this information is omitted,
  907. * the CPU-side DAI is matched using .cpu_dai_name only, which hence
  908. * must be globally unique. These fields are currently typically used
  909. * only for codec to codec links, or systems using device tree.
  910. */
  911. const char *cpu_name;
  912. struct device_node *cpu_of_node;
  913. /*
  914. * You MAY specify the DAI name of the CPU DAI. If this information is
  915. * omitted, the CPU-side DAI is matched using .cpu_name/.cpu_of_node
  916. * only, which only works well when that device exposes a single DAI.
  917. */
  918. const char *cpu_dai_name;
  919. /*
  920. * You MUST specify the link's codec, either by device name, or by
  921. * DT/OF node, but not both.
  922. */
  923. const char *codec_name;
  924. struct device_node *codec_of_node;
  925. /* You MUST specify the DAI name within the codec */
  926. const char *codec_dai_name;
  927. struct snd_soc_dai_link_component *codecs;
  928. unsigned int num_codecs;
  929. /*
  930. * You MAY specify the link's platform/PCM/DMA driver, either by
  931. * device name, or by DT/OF node, but not both. Some forms of link
  932. * do not need a platform.
  933. */
  934. const char *platform_name;
  935. struct device_node *platform_of_node;
  936. int id; /* optional ID for machine driver link identification */
  937. const struct snd_soc_pcm_stream *params;
  938. unsigned int num_params;
  939. unsigned int dai_fmt; /* format to set on init */
  940. enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */
  941. /* codec/machine specific init - e.g. add machine controls */
  942. int (*init)(struct snd_soc_pcm_runtime *rtd);
  943. /* optional hw_params re-writing for BE and FE sync */
  944. int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
  945. struct snd_pcm_hw_params *params);
  946. /* machine stream operations */
  947. const struct snd_soc_ops *ops;
  948. const struct snd_soc_compr_ops *compr_ops;
  949. /* Mark this pcm with non atomic ops */
  950. bool nonatomic;
  951. /* For unidirectional dai links */
  952. unsigned int playback_only:1;
  953. unsigned int capture_only:1;
  954. /* Keep DAI active over suspend */
  955. unsigned int ignore_suspend:1;
  956. /* Symmetry requirements */
  957. unsigned int symmetric_rates:1;
  958. unsigned int symmetric_channels:1;
  959. unsigned int symmetric_samplebits:1;
  960. /* Do not create a PCM for this DAI link (Backend link) */
  961. unsigned int no_pcm:1;
  962. /* This DAI link can route to other DAI links at runtime (Frontend)*/
  963. unsigned int dynamic:1;
  964. /* DPCM capture and Playback support */
  965. unsigned int dpcm_capture:1;
  966. unsigned int dpcm_playback:1;
  967. /* DPCM used FE & BE merged format */
  968. unsigned int dpcm_merged_format:1;
  969. /* pmdown_time is ignored at stop */
  970. unsigned int ignore_pmdown_time:1;
  971. struct list_head list; /* DAI link list of the soc card */
  972. struct snd_soc_dobj dobj; /* For topology */
  973. };
  974. struct snd_soc_codec_conf {
  975. /*
  976. * specify device either by device name, or by
  977. * DT/OF node, but not both.
  978. */
  979. const char *dev_name;
  980. struct device_node *of_node;
  981. /*
  982. * optional map of kcontrol, widget and path name prefixes that are
  983. * associated per device
  984. */
  985. const char *name_prefix;
  986. };
  987. struct snd_soc_aux_dev {
  988. const char *name; /* Codec name */
  989. /*
  990. * specify multi-codec either by device name, or by
  991. * DT/OF node, but not both.
  992. */
  993. const char *codec_name;
  994. struct device_node *codec_of_node;
  995. /* codec/machine specific init - e.g. add machine controls */
  996. int (*init)(struct snd_soc_component *component);
  997. };
  998. /* SoC card */
  999. struct snd_soc_card {
  1000. const char *name;
  1001. const char *long_name;
  1002. const char *driver_name;
  1003. char dmi_longname[80];
  1004. struct device *dev;
  1005. struct snd_card *snd_card;
  1006. struct module *owner;
  1007. struct mutex mutex;
  1008. struct mutex dapm_mutex;
  1009. spinlock_t dpcm_lock;
  1010. bool instantiated;
  1011. int (*probe)(struct snd_soc_card *card);
  1012. int (*late_probe)(struct snd_soc_card *card);
  1013. int (*remove)(struct snd_soc_card *card);
  1014. /* the pre and post PM functions are used to do any PM work before and
  1015. * after the codec and DAI's do any PM work. */
  1016. int (*suspend_pre)(struct snd_soc_card *card);
  1017. int (*suspend_post)(struct snd_soc_card *card);
  1018. int (*resume_pre)(struct snd_soc_card *card);
  1019. int (*resume_post)(struct snd_soc_card *card);
  1020. /* callbacks */
  1021. int (*set_bias_level)(struct snd_soc_card *,
  1022. struct snd_soc_dapm_context *dapm,
  1023. enum snd_soc_bias_level level);
  1024. int (*set_bias_level_post)(struct snd_soc_card *,
  1025. struct snd_soc_dapm_context *dapm,
  1026. enum snd_soc_bias_level level);
  1027. int (*add_dai_link)(struct snd_soc_card *,
  1028. struct snd_soc_dai_link *link);
  1029. void (*remove_dai_link)(struct snd_soc_card *,
  1030. struct snd_soc_dai_link *link);
  1031. long pmdown_time;
  1032. /* CPU <--> Codec DAI links */
  1033. struct snd_soc_dai_link *dai_link; /* predefined links only */
  1034. int num_links; /* predefined links only */
  1035. struct list_head dai_link_list; /* all links */
  1036. int num_dai_links;
  1037. struct list_head rtd_list;
  1038. int num_rtd;
  1039. /* optional codec specific configuration */
  1040. struct snd_soc_codec_conf *codec_conf;
  1041. int num_configs;
  1042. /*
  1043. * optional auxiliary devices such as amplifiers or codecs with DAI
  1044. * link unused
  1045. */
  1046. struct snd_soc_aux_dev *aux_dev;
  1047. int num_aux_devs;
  1048. struct list_head aux_comp_list;
  1049. const struct snd_kcontrol_new *controls;
  1050. int num_controls;
  1051. /*
  1052. * Card-specific routes and widgets.
  1053. * Note: of_dapm_xxx for Device Tree; Otherwise for driver build-in.
  1054. */
  1055. const struct snd_soc_dapm_widget *dapm_widgets;
  1056. int num_dapm_widgets;
  1057. const struct snd_soc_dapm_route *dapm_routes;
  1058. int num_dapm_routes;
  1059. const struct snd_soc_dapm_widget *of_dapm_widgets;
  1060. int num_of_dapm_widgets;
  1061. const struct snd_soc_dapm_route *of_dapm_routes;
  1062. int num_of_dapm_routes;
  1063. bool fully_routed;
  1064. struct work_struct deferred_resume_work;
  1065. /* lists of probed devices belonging to this card */
  1066. struct list_head component_dev_list;
  1067. struct list_head widgets;
  1068. struct list_head paths;
  1069. struct list_head dapm_list;
  1070. struct list_head dapm_dirty;
  1071. /* attached dynamic objects */
  1072. struct list_head dobj_list;
  1073. /* Generic DAPM context for the card */
  1074. struct snd_soc_dapm_context dapm;
  1075. struct snd_soc_dapm_stats dapm_stats;
  1076. struct snd_soc_dapm_update *update;
  1077. #ifdef CONFIG_DEBUG_FS
  1078. struct dentry *debugfs_card_root;
  1079. struct dentry *debugfs_pop_time;
  1080. #endif
  1081. u32 pop_time;
  1082. void *drvdata;
  1083. };
  1084. /* SoC machine DAI configuration, glues a codec and cpu DAI together */
  1085. struct snd_soc_pcm_runtime {
  1086. struct device *dev;
  1087. struct snd_soc_card *card;
  1088. struct snd_soc_dai_link *dai_link;
  1089. struct mutex pcm_mutex;
  1090. enum snd_soc_pcm_subclass pcm_subclass;
  1091. struct snd_pcm_ops ops;
  1092. /* Dynamic PCM BE runtime data */
  1093. struct snd_soc_dpcm_runtime dpcm[2];
  1094. int fe_compr;
  1095. long pmdown_time;
  1096. /* runtime devices */
  1097. struct snd_pcm *pcm;
  1098. struct snd_compr *compr;
  1099. struct snd_soc_codec *codec;
  1100. struct snd_soc_platform *platform; /* will be removed */
  1101. struct snd_soc_dai *codec_dai;
  1102. struct snd_soc_dai *cpu_dai;
  1103. struct snd_soc_dai **codec_dais;
  1104. unsigned int num_codecs;
  1105. struct delayed_work delayed_work;
  1106. #ifdef CONFIG_DEBUG_FS
  1107. struct dentry *debugfs_dpcm_root;
  1108. #endif
  1109. unsigned int num; /* 0-based and monotonic increasing */
  1110. struct list_head list; /* rtd list of the soc card */
  1111. struct list_head component_list; /* list of connected components */
  1112. /* bit field */
  1113. unsigned int dev_registered:1;
  1114. unsigned int pop_wait:1;
  1115. };
  1116. /* mixer control */
  1117. struct soc_mixer_control {
  1118. int min, max, platform_max;
  1119. int reg, rreg;
  1120. unsigned int shift, rshift;
  1121. unsigned int sign_bit;
  1122. unsigned int invert:1;
  1123. unsigned int autodisable:1;
  1124. struct snd_soc_dobj dobj;
  1125. };
  1126. struct soc_bytes {
  1127. int base;
  1128. int num_regs;
  1129. u32 mask;
  1130. };
  1131. struct soc_bytes_ext {
  1132. int max;
  1133. struct snd_soc_dobj dobj;
  1134. /* used for TLV byte control */
  1135. int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
  1136. unsigned int size);
  1137. int (*put)(struct snd_kcontrol *kcontrol, const unsigned int __user *bytes,
  1138. unsigned int size);
  1139. };
  1140. /* multi register control */
  1141. struct soc_mreg_control {
  1142. long min, max;
  1143. unsigned int regbase, regcount, nbits, invert;
  1144. };
  1145. /* enumerated kcontrol */
  1146. struct soc_enum {
  1147. int reg;
  1148. unsigned char shift_l;
  1149. unsigned char shift_r;
  1150. unsigned int items;
  1151. unsigned int mask;
  1152. const char * const *texts;
  1153. const unsigned int *values;
  1154. unsigned int autodisable:1;
  1155. struct snd_soc_dobj dobj;
  1156. };
  1157. /**
  1158. * snd_soc_component_to_codec() - Casts a component to the CODEC it is embedded in
  1159. * @component: The component to cast to a CODEC
  1160. *
  1161. * This function must only be used on components that are known to be CODECs.
  1162. * Otherwise the behavior is undefined.
  1163. */
  1164. static inline struct snd_soc_codec *snd_soc_component_to_codec(
  1165. struct snd_soc_component *component)
  1166. {
  1167. return container_of(component, struct snd_soc_codec, component);
  1168. }
  1169. /**
  1170. * snd_soc_component_to_platform() - Casts a component to the platform it is embedded in
  1171. * @component: The component to cast to a platform
  1172. *
  1173. * This function must only be used on components that are known to be platforms.
  1174. * Otherwise the behavior is undefined.
  1175. */
  1176. static inline struct snd_soc_platform *snd_soc_component_to_platform(
  1177. struct snd_soc_component *component)
  1178. {
  1179. return container_of(component, struct snd_soc_platform, component);
  1180. }
  1181. /**
  1182. * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
  1183. * embedded in
  1184. * @dapm: The DAPM context to cast to the component
  1185. *
  1186. * This function must only be used on DAPM contexts that are known to be part of
  1187. * a component (e.g. in a component driver). Otherwise the behavior is
  1188. * undefined.
  1189. */
  1190. static inline struct snd_soc_component *snd_soc_dapm_to_component(
  1191. struct snd_soc_dapm_context *dapm)
  1192. {
  1193. return container_of(dapm, struct snd_soc_component, dapm);
  1194. }
  1195. /**
  1196. * snd_soc_dapm_to_codec() - Casts a DAPM context to the CODEC it is embedded in
  1197. * @dapm: The DAPM context to cast to the CODEC
  1198. *
  1199. * This function must only be used on DAPM contexts that are known to be part of
  1200. * a CODEC (e.g. in a CODEC driver). Otherwise the behavior is undefined.
  1201. */
  1202. static inline struct snd_soc_codec *snd_soc_dapm_to_codec(
  1203. struct snd_soc_dapm_context *dapm)
  1204. {
  1205. return snd_soc_component_to_codec(snd_soc_dapm_to_component(dapm));
  1206. }
  1207. /**
  1208. * snd_soc_dapm_to_platform() - Casts a DAPM context to the platform it is
  1209. * embedded in
  1210. * @dapm: The DAPM context to cast to the platform.
  1211. *
  1212. * This function must only be used on DAPM contexts that are known to be part of
  1213. * a platform (e.g. in a platform driver). Otherwise the behavior is undefined.
  1214. */
  1215. static inline struct snd_soc_platform *snd_soc_dapm_to_platform(
  1216. struct snd_soc_dapm_context *dapm)
  1217. {
  1218. return snd_soc_component_to_platform(snd_soc_dapm_to_component(dapm));
  1219. }
  1220. /**
  1221. * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
  1222. * component
  1223. * @component: The component for which to get the DAPM context
  1224. */
  1225. static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
  1226. struct snd_soc_component *component)
  1227. {
  1228. return &component->dapm;
  1229. }
  1230. /**
  1231. * snd_soc_codec_get_dapm() - Returns the DAPM context for the CODEC
  1232. * @codec: The CODEC for which to get the DAPM context
  1233. *
  1234. * Note: Use this function instead of directly accessing the CODEC's dapm field
  1235. */
  1236. static inline struct snd_soc_dapm_context *snd_soc_codec_get_dapm(
  1237. struct snd_soc_codec *codec)
  1238. {
  1239. return snd_soc_component_get_dapm(&codec->component);
  1240. }
  1241. /**
  1242. * snd_soc_dapm_init_bias_level() - Initialize CODEC DAPM bias level
  1243. * @codec: The CODEC for which to initialize the DAPM bias level
  1244. * @level: The DAPM level to initialize to
  1245. *
  1246. * Initializes the CODEC DAPM bias level. See snd_soc_dapm_init_bias_level().
  1247. */
  1248. static inline void snd_soc_codec_init_bias_level(struct snd_soc_codec *codec,
  1249. enum snd_soc_bias_level level)
  1250. {
  1251. snd_soc_dapm_init_bias_level(snd_soc_codec_get_dapm(codec), level);
  1252. }
  1253. /**
  1254. * snd_soc_dapm_get_bias_level() - Get current CODEC DAPM bias level
  1255. * @codec: The CODEC for which to get the DAPM bias level
  1256. *
  1257. * Returns: The current DAPM bias level of the CODEC.
  1258. */
  1259. static inline enum snd_soc_bias_level snd_soc_codec_get_bias_level(
  1260. struct snd_soc_codec *codec)
  1261. {
  1262. return snd_soc_dapm_get_bias_level(snd_soc_codec_get_dapm(codec));
  1263. }
  1264. /**
  1265. * snd_soc_codec_force_bias_level() - Set the CODEC DAPM bias level
  1266. * @codec: The CODEC for which to set the level
  1267. * @level: The level to set to
  1268. *
  1269. * Forces the CODEC bias level to a specific state. See
  1270. * snd_soc_dapm_force_bias_level().
  1271. */
  1272. static inline int snd_soc_codec_force_bias_level(struct snd_soc_codec *codec,
  1273. enum snd_soc_bias_level level)
  1274. {
  1275. return snd_soc_dapm_force_bias_level(snd_soc_codec_get_dapm(codec),
  1276. level);
  1277. }
  1278. /**
  1279. * snd_soc_dapm_kcontrol_codec() - Returns the codec associated to a kcontrol
  1280. * @kcontrol: The kcontrol
  1281. *
  1282. * This function must only be used on DAPM contexts that are known to be part of
  1283. * a CODEC (e.g. in a CODEC driver). Otherwise the behavior is undefined.
  1284. */
  1285. static inline struct snd_soc_codec *snd_soc_dapm_kcontrol_codec(
  1286. struct snd_kcontrol *kcontrol)
  1287. {
  1288. return snd_soc_dapm_to_codec(snd_soc_dapm_kcontrol_dapm(kcontrol));
  1289. }
  1290. /* codec IO */
  1291. unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
  1292. int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg,
  1293. unsigned int val);
  1294. /**
  1295. * snd_soc_cache_sync() - Sync the register cache with the hardware
  1296. * @codec: CODEC to sync
  1297. *
  1298. * Note: This function will call regcache_sync()
  1299. */
  1300. static inline int snd_soc_cache_sync(struct snd_soc_codec *codec)
  1301. {
  1302. return regcache_sync(codec->component.regmap);
  1303. }
  1304. /* component IO */
  1305. int snd_soc_component_read(struct snd_soc_component *component,
  1306. unsigned int reg, unsigned int *val);
  1307. int snd_soc_component_write(struct snd_soc_component *component,
  1308. unsigned int reg, unsigned int val);
  1309. int snd_soc_component_update_bits(struct snd_soc_component *component,
  1310. unsigned int reg, unsigned int mask, unsigned int val);
  1311. int snd_soc_component_update_bits_async(struct snd_soc_component *component,
  1312. unsigned int reg, unsigned int mask, unsigned int val);
  1313. void snd_soc_component_async_complete(struct snd_soc_component *component);
  1314. int snd_soc_component_test_bits(struct snd_soc_component *component,
  1315. unsigned int reg, unsigned int mask, unsigned int value);
  1316. /* component wide operations */
  1317. int snd_soc_component_set_sysclk(struct snd_soc_component *component,
  1318. int clk_id, int source, unsigned int freq, int dir);
  1319. int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
  1320. int source, unsigned int freq_in,
  1321. unsigned int freq_out);
  1322. #ifdef CONFIG_REGMAP
  1323. void snd_soc_component_init_regmap(struct snd_soc_component *component,
  1324. struct regmap *regmap);
  1325. void snd_soc_component_exit_regmap(struct snd_soc_component *component);
  1326. /**
  1327. * snd_soc_codec_init_regmap() - Initialize regmap instance for the CODEC
  1328. * @codec: The CODEC for which to initialize the regmap instance
  1329. * @regmap: The regmap instance that should be used by the CODEC
  1330. *
  1331. * This function allows deferred assignment of the regmap instance that is
  1332. * associated with the CODEC. Only use this if the regmap instance is not yet
  1333. * ready when the CODEC is registered. The function must also be called before
  1334. * the first IO attempt of the CODEC.
  1335. */
  1336. static inline void snd_soc_codec_init_regmap(struct snd_soc_codec *codec,
  1337. struct regmap *regmap)
  1338. {
  1339. snd_soc_component_init_regmap(&codec->component, regmap);
  1340. }
  1341. /**
  1342. * snd_soc_codec_exit_regmap() - De-initialize regmap instance for the CODEC
  1343. * @codec: The CODEC for which to de-initialize the regmap instance
  1344. *
  1345. * Calls regmap_exit() on the regmap instance associated to the CODEC and
  1346. * removes the regmap instance from the CODEC.
  1347. *
  1348. * This function should only be used if snd_soc_codec_init_regmap() was used to
  1349. * initialize the regmap instance.
  1350. */
  1351. static inline void snd_soc_codec_exit_regmap(struct snd_soc_codec *codec)
  1352. {
  1353. snd_soc_component_exit_regmap(&codec->component);
  1354. }
  1355. #endif
  1356. /* device driver data */
  1357. static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
  1358. void *data)
  1359. {
  1360. card->drvdata = data;
  1361. }
  1362. static inline void *snd_soc_card_get_drvdata(struct snd_soc_card *card)
  1363. {
  1364. return card->drvdata;
  1365. }
  1366. static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
  1367. void *data)
  1368. {
  1369. dev_set_drvdata(c->dev, data);
  1370. }
  1371. static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
  1372. {
  1373. return dev_get_drvdata(c->dev);
  1374. }
  1375. static inline void snd_soc_codec_set_drvdata(struct snd_soc_codec *codec,
  1376. void *data)
  1377. {
  1378. snd_soc_component_set_drvdata(&codec->component, data);
  1379. }
  1380. static inline void *snd_soc_codec_get_drvdata(struct snd_soc_codec *codec)
  1381. {
  1382. return snd_soc_component_get_drvdata(&codec->component);
  1383. }
  1384. static inline void snd_soc_platform_set_drvdata(struct snd_soc_platform *platform,
  1385. void *data)
  1386. {
  1387. snd_soc_component_set_drvdata(&platform->component, data);
  1388. }
  1389. static inline void *snd_soc_platform_get_drvdata(struct snd_soc_platform *platform)
  1390. {
  1391. return snd_soc_component_get_drvdata(&platform->component);
  1392. }
  1393. static inline void snd_soc_initialize_card_lists(struct snd_soc_card *card)
  1394. {
  1395. INIT_LIST_HEAD(&card->widgets);
  1396. INIT_LIST_HEAD(&card->paths);
  1397. INIT_LIST_HEAD(&card->dapm_list);
  1398. INIT_LIST_HEAD(&card->aux_comp_list);
  1399. INIT_LIST_HEAD(&card->component_dev_list);
  1400. }
  1401. static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)
  1402. {
  1403. if (mc->reg == mc->rreg && mc->shift == mc->rshift)
  1404. return 0;
  1405. /*
  1406. * mc->reg == mc->rreg && mc->shift != mc->rshift, or
  1407. * mc->reg != mc->rreg means that the control is
  1408. * stereo (bits in one register or in two registers)
  1409. */
  1410. return 1;
  1411. }
  1412. static inline unsigned int snd_soc_enum_val_to_item(struct soc_enum *e,
  1413. unsigned int val)
  1414. {
  1415. unsigned int i;
  1416. if (!e->values)
  1417. return val;
  1418. for (i = 0; i < e->items; i++)
  1419. if (val == e->values[i])
  1420. return i;
  1421. return 0;
  1422. }
  1423. static inline unsigned int snd_soc_enum_item_to_val(struct soc_enum *e,
  1424. unsigned int item)
  1425. {
  1426. if (!e->values)
  1427. return item;
  1428. return e->values[item];
  1429. }
  1430. static inline bool snd_soc_component_is_active(
  1431. struct snd_soc_component *component)
  1432. {
  1433. return component->active != 0;
  1434. }
  1435. static inline bool snd_soc_codec_is_active(struct snd_soc_codec *codec)
  1436. {
  1437. return snd_soc_component_is_active(&codec->component);
  1438. }
  1439. /**
  1440. * snd_soc_kcontrol_component() - Returns the component that registered the
  1441. * control
  1442. * @kcontrol: The control for which to get the component
  1443. *
  1444. * Note: This function will work correctly if the control has been registered
  1445. * for a component. Either with snd_soc_add_codec_controls() or
  1446. * snd_soc_add_platform_controls() or via table based setup for either a
  1447. * CODEC, a platform or component driver. Otherwise the behavior is undefined.
  1448. */
  1449. static inline struct snd_soc_component *snd_soc_kcontrol_component(
  1450. struct snd_kcontrol *kcontrol)
  1451. {
  1452. return snd_kcontrol_chip(kcontrol);
  1453. }
  1454. /**
  1455. * snd_soc_kcontrol_codec() - Returns the CODEC that registered the control
  1456. * @kcontrol: The control for which to get the CODEC
  1457. *
  1458. * Note: This function will only work correctly if the control has been
  1459. * registered with snd_soc_add_codec_controls() or via table based setup of
  1460. * snd_soc_codec_driver. Otherwise the behavior is undefined.
  1461. */
  1462. static inline struct snd_soc_codec *snd_soc_kcontrol_codec(
  1463. struct snd_kcontrol *kcontrol)
  1464. {
  1465. return snd_soc_component_to_codec(snd_soc_kcontrol_component(kcontrol));
  1466. }
  1467. /**
  1468. * snd_soc_kcontrol_platform() - Returns the platform that registered the control
  1469. * @kcontrol: The control for which to get the platform
  1470. *
  1471. * Note: This function will only work correctly if the control has been
  1472. * registered with snd_soc_add_platform_controls() or via table based setup of
  1473. * a snd_soc_platform_driver. Otherwise the behavior is undefined.
  1474. */
  1475. static inline struct snd_soc_platform *snd_soc_kcontrol_platform(
  1476. struct snd_kcontrol *kcontrol)
  1477. {
  1478. return snd_soc_component_to_platform(snd_soc_kcontrol_component(kcontrol));
  1479. }
  1480. int snd_soc_util_init(void);
  1481. void snd_soc_util_exit(void);
  1482. int snd_soc_of_parse_card_name(struct snd_soc_card *card,
  1483. const char *propname);
  1484. int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
  1485. const char *propname);
  1486. int snd_soc_of_parse_tdm_slot(struct device_node *np,
  1487. unsigned int *tx_mask,
  1488. unsigned int *rx_mask,
  1489. unsigned int *slots,
  1490. unsigned int *slot_width);
  1491. void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
  1492. struct snd_soc_codec_conf *codec_conf,
  1493. struct device_node *of_node,
  1494. const char *propname);
  1495. int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
  1496. const char *propname);
  1497. unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
  1498. const char *prefix,
  1499. struct device_node **bitclkmaster,
  1500. struct device_node **framemaster);
  1501. int snd_soc_get_dai_id(struct device_node *ep);
  1502. int snd_soc_get_dai_name(struct of_phandle_args *args,
  1503. const char **dai_name);
  1504. int snd_soc_of_get_dai_name(struct device_node *of_node,
  1505. const char **dai_name);
  1506. int snd_soc_of_get_dai_link_codecs(struct device *dev,
  1507. struct device_node *of_node,
  1508. struct snd_soc_dai_link *dai_link);
  1509. int snd_soc_add_dai_link(struct snd_soc_card *card,
  1510. struct snd_soc_dai_link *dai_link);
  1511. void snd_soc_remove_dai_link(struct snd_soc_card *card,
  1512. struct snd_soc_dai_link *dai_link);
  1513. struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card,
  1514. int id, const char *name,
  1515. const char *stream_name);
  1516. int snd_soc_register_dai(struct snd_soc_component *component,
  1517. struct snd_soc_dai_driver *dai_drv);
  1518. struct snd_soc_dai *snd_soc_find_dai(
  1519. const struct snd_soc_dai_link_component *dlc);
  1520. #include <sound/soc-dai.h>
  1521. #ifdef CONFIG_DEBUG_FS
  1522. extern struct dentry *snd_soc_debugfs_root;
  1523. #endif
  1524. extern const struct dev_pm_ops snd_soc_pm_ops;
  1525. /* Helper functions */
  1526. static inline void snd_soc_dapm_mutex_lock(struct snd_soc_dapm_context *dapm)
  1527. {
  1528. mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
  1529. }
  1530. static inline void snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm)
  1531. {
  1532. mutex_unlock(&dapm->card->dapm_mutex);
  1533. }
  1534. int snd_soc_component_enable_pin(struct snd_soc_component *component,
  1535. const char *pin);
  1536. int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
  1537. const char *pin);
  1538. int snd_soc_component_disable_pin(struct snd_soc_component *component,
  1539. const char *pin);
  1540. int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
  1541. const char *pin);
  1542. int snd_soc_component_nc_pin(struct snd_soc_component *component,
  1543. const char *pin);
  1544. int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
  1545. const char *pin);
  1546. int snd_soc_component_get_pin_status(struct snd_soc_component *component,
  1547. const char *pin);
  1548. int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
  1549. const char *pin);
  1550. int snd_soc_component_force_enable_pin_unlocked(
  1551. struct snd_soc_component *component,
  1552. const char *pin);
  1553. #endif