soc.h 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886
  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_add_component(struct device *dev,
  452. struct snd_soc_component *component,
  453. const struct snd_soc_component_driver *component_driver,
  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. struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
  464. const char *driver_name);
  465. int snd_soc_cache_init(struct snd_soc_codec *codec);
  466. int snd_soc_cache_exit(struct snd_soc_codec *codec);
  467. int snd_soc_platform_read(struct snd_soc_platform *platform,
  468. unsigned int reg);
  469. int snd_soc_platform_write(struct snd_soc_platform *platform,
  470. unsigned int reg, unsigned int val);
  471. int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
  472. #ifdef CONFIG_SND_SOC_COMPRESS
  473. int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num);
  474. #endif
  475. void snd_soc_disconnect_sync(struct device *dev);
  476. struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
  477. const char *dai_link, int stream);
  478. struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
  479. const char *dai_link);
  480. bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd);
  481. void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream);
  482. void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream);
  483. int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
  484. unsigned int dai_fmt);
  485. #ifdef CONFIG_DMI
  486. int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour);
  487. #else
  488. static inline int snd_soc_set_dmi_name(struct snd_soc_card *card,
  489. const char *flavour)
  490. {
  491. return 0;
  492. }
  493. #endif
  494. /* Utility functions to get clock rates from various things */
  495. int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
  496. int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
  497. int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
  498. int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);
  499. /* set runtime hw params */
  500. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  501. const struct snd_pcm_hardware *hw);
  502. int soc_dai_hw_params(struct snd_pcm_substream *substream,
  503. struct snd_pcm_hw_params *params,
  504. struct snd_soc_dai *dai);
  505. /* Jack reporting */
  506. int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
  507. struct snd_soc_jack *jack, struct snd_soc_jack_pin *pins,
  508. unsigned int num_pins);
  509. void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
  510. int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
  511. struct snd_soc_jack_pin *pins);
  512. void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
  513. struct notifier_block *nb);
  514. void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
  515. struct notifier_block *nb);
  516. int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
  517. struct snd_soc_jack_zone *zones);
  518. int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
  519. #ifdef CONFIG_GPIOLIB
  520. int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  521. struct snd_soc_jack_gpio *gpios);
  522. int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
  523. struct snd_soc_jack *jack,
  524. int count, struct snd_soc_jack_gpio *gpios);
  525. void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  526. struct snd_soc_jack_gpio *gpios);
  527. #else
  528. static inline int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  529. struct snd_soc_jack_gpio *gpios)
  530. {
  531. return 0;
  532. }
  533. static inline int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
  534. struct snd_soc_jack *jack,
  535. int count,
  536. struct snd_soc_jack_gpio *gpios)
  537. {
  538. return 0;
  539. }
  540. static inline void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  541. struct snd_soc_jack_gpio *gpios)
  542. {
  543. }
  544. #endif
  545. /* codec register bit access */
  546. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned int reg,
  547. unsigned int mask, unsigned int value);
  548. int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
  549. unsigned int reg, unsigned int mask,
  550. unsigned int value);
  551. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned int reg,
  552. unsigned int mask, unsigned int value);
  553. #ifdef CONFIG_SND_SOC_AC97_BUS
  554. #define snd_soc_alloc_ac97_codec(codec) \
  555. snd_soc_alloc_ac97_component(&codec->component)
  556. #define snd_soc_new_ac97_codec(codec, id, id_mask) \
  557. snd_soc_new_ac97_component(&codec->component, id, id_mask)
  558. #define snd_soc_free_ac97_codec(ac97) \
  559. snd_soc_free_ac97_component(ac97)
  560. struct snd_ac97 *snd_soc_alloc_ac97_component(struct snd_soc_component *component);
  561. struct snd_ac97 *snd_soc_new_ac97_component(struct snd_soc_component *component,
  562. unsigned int id, unsigned int id_mask);
  563. void snd_soc_free_ac97_component(struct snd_ac97 *ac97);
  564. int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops);
  565. int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
  566. struct platform_device *pdev);
  567. extern struct snd_ac97_bus_ops *soc_ac97_ops;
  568. #else
  569. static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
  570. struct platform_device *pdev)
  571. {
  572. return 0;
  573. }
  574. static inline int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
  575. {
  576. return 0;
  577. }
  578. #endif
  579. /*
  580. *Controls
  581. */
  582. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  583. void *data, const char *long_name,
  584. const char *prefix);
  585. struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
  586. const char *name);
  587. int snd_soc_add_component_controls(struct snd_soc_component *component,
  588. const struct snd_kcontrol_new *controls, unsigned int num_controls);
  589. int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
  590. const struct snd_kcontrol_new *controls, unsigned int num_controls);
  591. int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
  592. const struct snd_kcontrol_new *controls, unsigned int num_controls);
  593. int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
  594. const struct snd_kcontrol_new *controls, int num_controls);
  595. int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
  596. const struct snd_kcontrol_new *controls, int num_controls);
  597. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  598. struct snd_ctl_elem_info *uinfo);
  599. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  600. struct snd_ctl_elem_value *ucontrol);
  601. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  602. struct snd_ctl_elem_value *ucontrol);
  603. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  604. struct snd_ctl_elem_info *uinfo);
  605. int snd_soc_info_volsw_sx(struct snd_kcontrol *kcontrol,
  606. struct snd_ctl_elem_info *uinfo);
  607. #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
  608. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  609. struct snd_ctl_elem_value *ucontrol);
  610. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  611. struct snd_ctl_elem_value *ucontrol);
  612. #define snd_soc_get_volsw_2r snd_soc_get_volsw
  613. #define snd_soc_put_volsw_2r snd_soc_put_volsw
  614. int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
  615. struct snd_ctl_elem_value *ucontrol);
  616. int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
  617. struct snd_ctl_elem_value *ucontrol);
  618. int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
  619. struct snd_ctl_elem_info *uinfo);
  620. int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
  621. struct snd_ctl_elem_value *ucontrol);
  622. int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
  623. struct snd_ctl_elem_value *ucontrol);
  624. int snd_soc_limit_volume(struct snd_soc_card *card,
  625. const char *name, int max);
  626. int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
  627. struct snd_ctl_elem_info *uinfo);
  628. int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
  629. struct snd_ctl_elem_value *ucontrol);
  630. int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
  631. struct snd_ctl_elem_value *ucontrol);
  632. int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,
  633. struct snd_ctl_elem_info *ucontrol);
  634. int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag,
  635. unsigned int size, unsigned int __user *tlv);
  636. int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
  637. struct snd_ctl_elem_info *uinfo);
  638. int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
  639. struct snd_ctl_elem_value *ucontrol);
  640. int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
  641. struct snd_ctl_elem_value *ucontrol);
  642. int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
  643. struct snd_ctl_elem_value *ucontrol);
  644. int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
  645. struct snd_ctl_elem_value *ucontrol);
  646. /**
  647. * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
  648. *
  649. * @pin: name of the pin to update
  650. * @mask: bits to check for in reported jack status
  651. * @invert: if non-zero then pin is enabled when status is not reported
  652. * @list: internal list entry
  653. */
  654. struct snd_soc_jack_pin {
  655. struct list_head list;
  656. const char *pin;
  657. int mask;
  658. bool invert;
  659. };
  660. /**
  661. * struct snd_soc_jack_zone - Describes voltage zones of jack detection
  662. *
  663. * @min_mv: start voltage in mv
  664. * @max_mv: end voltage in mv
  665. * @jack_type: type of jack that is expected for this voltage
  666. * @debounce_time: debounce_time for jack, codec driver should wait for this
  667. * duration before reading the adc for voltages
  668. * @list: internal list entry
  669. */
  670. struct snd_soc_jack_zone {
  671. unsigned int min_mv;
  672. unsigned int max_mv;
  673. unsigned int jack_type;
  674. unsigned int debounce_time;
  675. struct list_head list;
  676. };
  677. /**
  678. * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
  679. *
  680. * @gpio: legacy gpio number
  681. * @idx: gpio descriptor index within the function of the GPIO
  682. * consumer device
  683. * @gpiod_dev: GPIO consumer device
  684. * @name: gpio name. Also as connection ID for the GPIO consumer
  685. * device function name lookup
  686. * @report: value to report when jack detected
  687. * @invert: report presence in low state
  688. * @debounce_time: debounce time in ms
  689. * @wake: enable as wake source
  690. * @jack_status_check: callback function which overrides the detection
  691. * to provide more complex checks (eg, reading an
  692. * ADC).
  693. */
  694. struct snd_soc_jack_gpio {
  695. unsigned int gpio;
  696. unsigned int idx;
  697. struct device *gpiod_dev;
  698. const char *name;
  699. int report;
  700. int invert;
  701. int debounce_time;
  702. bool wake;
  703. /* private: */
  704. struct snd_soc_jack *jack;
  705. struct delayed_work work;
  706. struct notifier_block pm_notifier;
  707. struct gpio_desc *desc;
  708. void *data;
  709. /* public: */
  710. int (*jack_status_check)(void *data);
  711. };
  712. struct snd_soc_jack {
  713. struct mutex mutex;
  714. struct snd_jack *jack;
  715. struct snd_soc_card *card;
  716. struct list_head pins;
  717. int status;
  718. struct blocking_notifier_head notifier;
  719. struct list_head jack_zones;
  720. };
  721. /* SoC PCM stream information */
  722. struct snd_soc_pcm_stream {
  723. const char *stream_name;
  724. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  725. unsigned int rates; /* SNDRV_PCM_RATE_* */
  726. unsigned int rate_min; /* min rate */
  727. unsigned int rate_max; /* max rate */
  728. unsigned int channels_min; /* min channels */
  729. unsigned int channels_max; /* max channels */
  730. unsigned int sig_bits; /* number of bits of content */
  731. };
  732. /* SoC audio ops */
  733. struct snd_soc_ops {
  734. int (*startup)(struct snd_pcm_substream *);
  735. void (*shutdown)(struct snd_pcm_substream *);
  736. int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
  737. int (*hw_free)(struct snd_pcm_substream *);
  738. int (*prepare)(struct snd_pcm_substream *);
  739. int (*trigger)(struct snd_pcm_substream *, int);
  740. };
  741. struct snd_soc_compr_ops {
  742. int (*startup)(struct snd_compr_stream *);
  743. void (*shutdown)(struct snd_compr_stream *);
  744. int (*set_params)(struct snd_compr_stream *);
  745. int (*trigger)(struct snd_compr_stream *);
  746. };
  747. /* component interface */
  748. struct snd_soc_component_driver {
  749. const char *name;
  750. /* Default control and setup, added after probe() is run */
  751. const struct snd_kcontrol_new *controls;
  752. unsigned int num_controls;
  753. const struct snd_soc_dapm_widget *dapm_widgets;
  754. unsigned int num_dapm_widgets;
  755. const struct snd_soc_dapm_route *dapm_routes;
  756. unsigned int num_dapm_routes;
  757. int (*probe)(struct snd_soc_component *);
  758. void (*remove)(struct snd_soc_component *);
  759. int (*suspend)(struct snd_soc_component *);
  760. int (*resume)(struct snd_soc_component *);
  761. unsigned int (*read)(struct snd_soc_component *, unsigned int);
  762. int (*write)(struct snd_soc_component *, unsigned int, unsigned int);
  763. /* pcm creation and destruction */
  764. int (*pcm_new)(struct snd_soc_pcm_runtime *);
  765. void (*pcm_free)(struct snd_pcm *);
  766. /* component wide operations */
  767. int (*set_sysclk)(struct snd_soc_component *component,
  768. int clk_id, int source, unsigned int freq, int dir);
  769. int (*set_pll)(struct snd_soc_component *component, int pll_id,
  770. int source, unsigned int freq_in, unsigned int freq_out);
  771. int (*set_jack)(struct snd_soc_component *component,
  772. struct snd_soc_jack *jack, void *data);
  773. /* DT */
  774. int (*of_xlate_dai_name)(struct snd_soc_component *component,
  775. struct of_phandle_args *args,
  776. const char **dai_name);
  777. int (*of_xlate_dai_id)(struct snd_soc_component *comment,
  778. struct device_node *endpoint);
  779. void (*seq_notifier)(struct snd_soc_component *, enum snd_soc_dapm_type,
  780. int subseq);
  781. int (*stream_event)(struct snd_soc_component *, int event);
  782. int (*set_bias_level)(struct snd_soc_component *component,
  783. enum snd_soc_bias_level level);
  784. const struct snd_pcm_ops *ops;
  785. const struct snd_compr_ops *compr_ops;
  786. /* probe ordering - for components with runtime dependencies */
  787. int probe_order;
  788. int remove_order;
  789. /* bits */
  790. unsigned int idle_bias_on:1;
  791. unsigned int suspend_bias_off:1;
  792. unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
  793. unsigned int endianness:1;
  794. unsigned int non_legacy_dai_naming:1;
  795. };
  796. struct snd_soc_component {
  797. const char *name;
  798. int id;
  799. const char *name_prefix;
  800. struct device *dev;
  801. struct snd_soc_card *card;
  802. unsigned int active;
  803. unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */
  804. unsigned int registered_as_component:1;
  805. unsigned int suspended:1; /* is in suspend PM state */
  806. struct list_head list;
  807. struct list_head card_aux_list; /* for auxiliary bound components */
  808. struct list_head card_list;
  809. const struct snd_soc_component_driver *driver;
  810. struct list_head dai_list;
  811. int num_dai;
  812. int (*read)(struct snd_soc_component *, unsigned int, unsigned int *);
  813. int (*write)(struct snd_soc_component *, unsigned int, unsigned int);
  814. struct regmap *regmap;
  815. int val_bytes;
  816. struct mutex io_mutex;
  817. /* attached dynamic objects */
  818. struct list_head dobj_list;
  819. #ifdef CONFIG_DEBUG_FS
  820. struct dentry *debugfs_root;
  821. #endif
  822. /*
  823. * DO NOT use any of the fields below in drivers, they are temporary and
  824. * are going to be removed again soon. If you use them in driver code the
  825. * driver will be marked as BROKEN when these fields are removed.
  826. */
  827. /* Don't use these, use snd_soc_component_get_dapm() */
  828. struct snd_soc_dapm_context dapm;
  829. struct snd_soc_codec *codec;
  830. int (*probe)(struct snd_soc_component *);
  831. void (*remove)(struct snd_soc_component *);
  832. int (*suspend)(struct snd_soc_component *);
  833. int (*resume)(struct snd_soc_component *);
  834. int (*pcm_new)(struct snd_soc_component *, struct snd_soc_pcm_runtime *);
  835. void (*pcm_free)(struct snd_soc_component *, struct snd_pcm *);
  836. int (*set_sysclk)(struct snd_soc_component *component,
  837. int clk_id, int source, unsigned int freq, int dir);
  838. int (*set_pll)(struct snd_soc_component *component, int pll_id,
  839. int source, unsigned int freq_in, unsigned int freq_out);
  840. int (*set_jack)(struct snd_soc_component *component,
  841. struct snd_soc_jack *jack, void *data);
  842. int (*set_bias_level)(struct snd_soc_component *component,
  843. enum snd_soc_bias_level level);
  844. /* machine specific init */
  845. int (*init)(struct snd_soc_component *component);
  846. #ifdef CONFIG_DEBUG_FS
  847. void (*init_debugfs)(struct snd_soc_component *component);
  848. const char *debugfs_prefix;
  849. #endif
  850. };
  851. struct snd_soc_rtdcom_list {
  852. struct snd_soc_component *component;
  853. struct list_head list; /* rtd::component_list */
  854. };
  855. struct snd_soc_component*
  856. snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
  857. const char *driver_name);
  858. #define for_each_rtdcom(rtd, rtdcom) \
  859. list_for_each_entry(rtdcom, &(rtd)->component_list, list)
  860. #define for_each_rtdcom_safe(rtd, rtdcom1, rtdcom2) \
  861. list_for_each_entry_safe(rtdcom1, rtdcom2, &(rtd)->component_list, list)
  862. /* SoC Audio Codec device */
  863. struct snd_soc_codec {
  864. struct device *dev;
  865. const struct snd_soc_codec_driver *driver;
  866. struct list_head list;
  867. /* runtime */
  868. unsigned int cache_init:1; /* codec cache has been initialized */
  869. /* codec IO */
  870. void *control_data; /* codec control (i2c/3wire) data */
  871. hw_write_t hw_write;
  872. void *reg_cache;
  873. /* component */
  874. struct snd_soc_component component;
  875. };
  876. /* codec driver */
  877. struct snd_soc_codec_driver {
  878. /* driver ops */
  879. int (*probe)(struct snd_soc_codec *);
  880. int (*remove)(struct snd_soc_codec *);
  881. int (*suspend)(struct snd_soc_codec *);
  882. int (*resume)(struct snd_soc_codec *);
  883. struct snd_soc_component_driver component_driver;
  884. /* codec wide operations */
  885. int (*set_sysclk)(struct snd_soc_codec *codec,
  886. int clk_id, int source, unsigned int freq, int dir);
  887. int (*set_pll)(struct snd_soc_codec *codec, int pll_id, int source,
  888. unsigned int freq_in, unsigned int freq_out);
  889. int (*set_jack)(struct snd_soc_codec *codec,
  890. struct snd_soc_jack *jack, void *data);
  891. /* codec IO */
  892. struct regmap *(*get_regmap)(struct device *);
  893. unsigned int (*read)(struct snd_soc_codec *, unsigned int);
  894. int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
  895. unsigned int reg_cache_size;
  896. short reg_cache_step;
  897. short reg_word_size;
  898. const void *reg_cache_default;
  899. /* codec bias level */
  900. int (*set_bias_level)(struct snd_soc_codec *,
  901. enum snd_soc_bias_level level);
  902. bool idle_bias_off;
  903. bool suspend_bias_off;
  904. void (*seq_notifier)(struct snd_soc_dapm_context *,
  905. enum snd_soc_dapm_type, int);
  906. bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
  907. };
  908. /* SoC platform interface */
  909. struct snd_soc_platform_driver {
  910. int (*probe)(struct snd_soc_platform *);
  911. int (*remove)(struct snd_soc_platform *);
  912. struct snd_soc_component_driver component_driver;
  913. /* pcm creation and destruction */
  914. int (*pcm_new)(struct snd_soc_pcm_runtime *);
  915. void (*pcm_free)(struct snd_pcm *);
  916. /* platform stream pcm ops */
  917. const struct snd_pcm_ops *ops;
  918. /* platform stream compress ops */
  919. const struct snd_compr_ops *compr_ops;
  920. };
  921. struct snd_soc_dai_link_component {
  922. const char *name;
  923. struct device_node *of_node;
  924. const char *dai_name;
  925. };
  926. struct snd_soc_platform {
  927. struct device *dev;
  928. const struct snd_soc_platform_driver *driver;
  929. struct list_head list;
  930. struct snd_soc_component component;
  931. };
  932. struct snd_soc_dai_link {
  933. /* config - must be set by machine driver */
  934. const char *name; /* Codec name */
  935. const char *stream_name; /* Stream name */
  936. /*
  937. * You MAY specify the link's CPU-side device, either by device name,
  938. * or by DT/OF node, but not both. If this information is omitted,
  939. * the CPU-side DAI is matched using .cpu_dai_name only, which hence
  940. * must be globally unique. These fields are currently typically used
  941. * only for codec to codec links, or systems using device tree.
  942. */
  943. const char *cpu_name;
  944. struct device_node *cpu_of_node;
  945. /*
  946. * You MAY specify the DAI name of the CPU DAI. If this information is
  947. * omitted, the CPU-side DAI is matched using .cpu_name/.cpu_of_node
  948. * only, which only works well when that device exposes a single DAI.
  949. */
  950. const char *cpu_dai_name;
  951. /*
  952. * You MUST specify the link's codec, either by device name, or by
  953. * DT/OF node, but not both.
  954. */
  955. const char *codec_name;
  956. struct device_node *codec_of_node;
  957. /* You MUST specify the DAI name within the codec */
  958. const char *codec_dai_name;
  959. struct snd_soc_dai_link_component *codecs;
  960. unsigned int num_codecs;
  961. /*
  962. * You MAY specify the link's platform/PCM/DMA driver, either by
  963. * device name, or by DT/OF node, but not both. Some forms of link
  964. * do not need a platform.
  965. */
  966. const char *platform_name;
  967. struct device_node *platform_of_node;
  968. int id; /* optional ID for machine driver link identification */
  969. const struct snd_soc_pcm_stream *params;
  970. unsigned int num_params;
  971. unsigned int dai_fmt; /* format to set on init */
  972. enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */
  973. /* codec/machine specific init - e.g. add machine controls */
  974. int (*init)(struct snd_soc_pcm_runtime *rtd);
  975. /* optional hw_params re-writing for BE and FE sync */
  976. int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
  977. struct snd_pcm_hw_params *params);
  978. /* machine stream operations */
  979. const struct snd_soc_ops *ops;
  980. const struct snd_soc_compr_ops *compr_ops;
  981. /* Mark this pcm with non atomic ops */
  982. bool nonatomic;
  983. /* For unidirectional dai links */
  984. unsigned int playback_only:1;
  985. unsigned int capture_only:1;
  986. /* Keep DAI active over suspend */
  987. unsigned int ignore_suspend:1;
  988. /* Symmetry requirements */
  989. unsigned int symmetric_rates:1;
  990. unsigned int symmetric_channels:1;
  991. unsigned int symmetric_samplebits:1;
  992. /* Do not create a PCM for this DAI link (Backend link) */
  993. unsigned int no_pcm:1;
  994. /* This DAI link can route to other DAI links at runtime (Frontend)*/
  995. unsigned int dynamic:1;
  996. /* DPCM capture and Playback support */
  997. unsigned int dpcm_capture:1;
  998. unsigned int dpcm_playback:1;
  999. /* DPCM used FE & BE merged format */
  1000. unsigned int dpcm_merged_format:1;
  1001. /* pmdown_time is ignored at stop */
  1002. unsigned int ignore_pmdown_time:1;
  1003. struct list_head list; /* DAI link list of the soc card */
  1004. struct snd_soc_dobj dobj; /* For topology */
  1005. };
  1006. struct snd_soc_codec_conf {
  1007. /*
  1008. * specify device either by device name, or by
  1009. * DT/OF node, but not both.
  1010. */
  1011. const char *dev_name;
  1012. struct device_node *of_node;
  1013. /*
  1014. * optional map of kcontrol, widget and path name prefixes that are
  1015. * associated per device
  1016. */
  1017. const char *name_prefix;
  1018. };
  1019. struct snd_soc_aux_dev {
  1020. const char *name; /* Codec name */
  1021. /*
  1022. * specify multi-codec either by device name, or by
  1023. * DT/OF node, but not both.
  1024. */
  1025. const char *codec_name;
  1026. struct device_node *codec_of_node;
  1027. /* codec/machine specific init - e.g. add machine controls */
  1028. int (*init)(struct snd_soc_component *component);
  1029. };
  1030. /* SoC card */
  1031. struct snd_soc_card {
  1032. const char *name;
  1033. const char *long_name;
  1034. const char *driver_name;
  1035. char dmi_longname[80];
  1036. struct device *dev;
  1037. struct snd_card *snd_card;
  1038. struct module *owner;
  1039. struct mutex mutex;
  1040. struct mutex dapm_mutex;
  1041. bool instantiated;
  1042. int (*probe)(struct snd_soc_card *card);
  1043. int (*late_probe)(struct snd_soc_card *card);
  1044. int (*remove)(struct snd_soc_card *card);
  1045. /* the pre and post PM functions are used to do any PM work before and
  1046. * after the codec and DAI's do any PM work. */
  1047. int (*suspend_pre)(struct snd_soc_card *card);
  1048. int (*suspend_post)(struct snd_soc_card *card);
  1049. int (*resume_pre)(struct snd_soc_card *card);
  1050. int (*resume_post)(struct snd_soc_card *card);
  1051. /* callbacks */
  1052. int (*set_bias_level)(struct snd_soc_card *,
  1053. struct snd_soc_dapm_context *dapm,
  1054. enum snd_soc_bias_level level);
  1055. int (*set_bias_level_post)(struct snd_soc_card *,
  1056. struct snd_soc_dapm_context *dapm,
  1057. enum snd_soc_bias_level level);
  1058. int (*add_dai_link)(struct snd_soc_card *,
  1059. struct snd_soc_dai_link *link);
  1060. void (*remove_dai_link)(struct snd_soc_card *,
  1061. struct snd_soc_dai_link *link);
  1062. long pmdown_time;
  1063. /* CPU <--> Codec DAI links */
  1064. struct snd_soc_dai_link *dai_link; /* predefined links only */
  1065. int num_links; /* predefined links only */
  1066. struct list_head dai_link_list; /* all links */
  1067. int num_dai_links;
  1068. struct list_head rtd_list;
  1069. int num_rtd;
  1070. /* optional codec specific configuration */
  1071. struct snd_soc_codec_conf *codec_conf;
  1072. int num_configs;
  1073. /*
  1074. * optional auxiliary devices such as amplifiers or codecs with DAI
  1075. * link unused
  1076. */
  1077. struct snd_soc_aux_dev *aux_dev;
  1078. int num_aux_devs;
  1079. struct list_head aux_comp_list;
  1080. const struct snd_kcontrol_new *controls;
  1081. int num_controls;
  1082. /*
  1083. * Card-specific routes and widgets.
  1084. * Note: of_dapm_xxx for Device Tree; Otherwise for driver build-in.
  1085. */
  1086. const struct snd_soc_dapm_widget *dapm_widgets;
  1087. int num_dapm_widgets;
  1088. const struct snd_soc_dapm_route *dapm_routes;
  1089. int num_dapm_routes;
  1090. const struct snd_soc_dapm_widget *of_dapm_widgets;
  1091. int num_of_dapm_widgets;
  1092. const struct snd_soc_dapm_route *of_dapm_routes;
  1093. int num_of_dapm_routes;
  1094. bool fully_routed;
  1095. struct work_struct deferred_resume_work;
  1096. /* lists of probed devices belonging to this card */
  1097. struct list_head component_dev_list;
  1098. struct list_head widgets;
  1099. struct list_head paths;
  1100. struct list_head dapm_list;
  1101. struct list_head dapm_dirty;
  1102. /* attached dynamic objects */
  1103. struct list_head dobj_list;
  1104. /* Generic DAPM context for the card */
  1105. struct snd_soc_dapm_context dapm;
  1106. struct snd_soc_dapm_stats dapm_stats;
  1107. struct snd_soc_dapm_update *update;
  1108. #ifdef CONFIG_DEBUG_FS
  1109. struct dentry *debugfs_card_root;
  1110. struct dentry *debugfs_pop_time;
  1111. #endif
  1112. u32 pop_time;
  1113. void *drvdata;
  1114. };
  1115. /* SoC machine DAI configuration, glues a codec and cpu DAI together */
  1116. struct snd_soc_pcm_runtime {
  1117. struct device *dev;
  1118. struct snd_soc_card *card;
  1119. struct snd_soc_dai_link *dai_link;
  1120. struct mutex pcm_mutex;
  1121. enum snd_soc_pcm_subclass pcm_subclass;
  1122. struct snd_pcm_ops ops;
  1123. /* Dynamic PCM BE runtime data */
  1124. struct snd_soc_dpcm_runtime dpcm[2];
  1125. int fe_compr;
  1126. long pmdown_time;
  1127. /* runtime devices */
  1128. struct snd_pcm *pcm;
  1129. struct snd_compr *compr;
  1130. struct snd_soc_codec *codec;
  1131. struct snd_soc_platform *platform; /* will be removed */
  1132. struct snd_soc_dai *codec_dai;
  1133. struct snd_soc_dai *cpu_dai;
  1134. struct snd_soc_dai **codec_dais;
  1135. unsigned int num_codecs;
  1136. struct delayed_work delayed_work;
  1137. #ifdef CONFIG_DEBUG_FS
  1138. struct dentry *debugfs_dpcm_root;
  1139. #endif
  1140. unsigned int num; /* 0-based and monotonic increasing */
  1141. struct list_head list; /* rtd list of the soc card */
  1142. struct list_head component_list; /* list of connected components */
  1143. /* bit field */
  1144. unsigned int dev_registered:1;
  1145. unsigned int pop_wait:1;
  1146. };
  1147. /* mixer control */
  1148. struct soc_mixer_control {
  1149. int min, max, platform_max;
  1150. int reg, rreg;
  1151. unsigned int shift, rshift;
  1152. unsigned int sign_bit;
  1153. unsigned int invert:1;
  1154. unsigned int autodisable:1;
  1155. struct snd_soc_dobj dobj;
  1156. };
  1157. struct soc_bytes {
  1158. int base;
  1159. int num_regs;
  1160. u32 mask;
  1161. };
  1162. struct soc_bytes_ext {
  1163. int max;
  1164. struct snd_soc_dobj dobj;
  1165. /* used for TLV byte control */
  1166. int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
  1167. unsigned int size);
  1168. int (*put)(struct snd_kcontrol *kcontrol, const unsigned int __user *bytes,
  1169. unsigned int size);
  1170. };
  1171. /* multi register control */
  1172. struct soc_mreg_control {
  1173. long min, max;
  1174. unsigned int regbase, regcount, nbits, invert;
  1175. };
  1176. /* enumerated kcontrol */
  1177. struct soc_enum {
  1178. int reg;
  1179. unsigned char shift_l;
  1180. unsigned char shift_r;
  1181. unsigned int items;
  1182. unsigned int mask;
  1183. const char * const *texts;
  1184. const unsigned int *values;
  1185. unsigned int autodisable:1;
  1186. struct snd_soc_dobj dobj;
  1187. };
  1188. /**
  1189. * snd_soc_component_to_codec() - Casts a component to the CODEC it is embedded in
  1190. * @component: The component to cast to a CODEC
  1191. *
  1192. * This function must only be used on components that are known to be CODECs.
  1193. * Otherwise the behavior is undefined.
  1194. */
  1195. static inline struct snd_soc_codec *snd_soc_component_to_codec(
  1196. struct snd_soc_component *component)
  1197. {
  1198. return container_of(component, struct snd_soc_codec, component);
  1199. }
  1200. /**
  1201. * snd_soc_component_to_platform() - Casts a component to the platform it is embedded in
  1202. * @component: The component to cast to a platform
  1203. *
  1204. * This function must only be used on components that are known to be platforms.
  1205. * Otherwise the behavior is undefined.
  1206. */
  1207. static inline struct snd_soc_platform *snd_soc_component_to_platform(
  1208. struct snd_soc_component *component)
  1209. {
  1210. return container_of(component, struct snd_soc_platform, component);
  1211. }
  1212. /**
  1213. * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
  1214. * embedded in
  1215. * @dapm: The DAPM context to cast to the component
  1216. *
  1217. * This function must only be used on DAPM contexts that are known to be part of
  1218. * a component (e.g. in a component driver). Otherwise the behavior is
  1219. * undefined.
  1220. */
  1221. static inline struct snd_soc_component *snd_soc_dapm_to_component(
  1222. struct snd_soc_dapm_context *dapm)
  1223. {
  1224. return container_of(dapm, struct snd_soc_component, dapm);
  1225. }
  1226. /**
  1227. * snd_soc_dapm_to_codec() - Casts a DAPM context to the CODEC it is embedded in
  1228. * @dapm: The DAPM context to cast to the CODEC
  1229. *
  1230. * This function must only be used on DAPM contexts that are known to be part of
  1231. * a CODEC (e.g. in a CODEC driver). Otherwise the behavior is undefined.
  1232. */
  1233. static inline struct snd_soc_codec *snd_soc_dapm_to_codec(
  1234. struct snd_soc_dapm_context *dapm)
  1235. {
  1236. return snd_soc_component_to_codec(snd_soc_dapm_to_component(dapm));
  1237. }
  1238. /**
  1239. * snd_soc_dapm_to_platform() - Casts a DAPM context to the platform it is
  1240. * embedded in
  1241. * @dapm: The DAPM context to cast to the platform.
  1242. *
  1243. * This function must only be used on DAPM contexts that are known to be part of
  1244. * a platform (e.g. in a platform driver). Otherwise the behavior is undefined.
  1245. */
  1246. static inline struct snd_soc_platform *snd_soc_dapm_to_platform(
  1247. struct snd_soc_dapm_context *dapm)
  1248. {
  1249. return snd_soc_component_to_platform(snd_soc_dapm_to_component(dapm));
  1250. }
  1251. /**
  1252. * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
  1253. * component
  1254. * @component: The component for which to get the DAPM context
  1255. */
  1256. static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
  1257. struct snd_soc_component *component)
  1258. {
  1259. return &component->dapm;
  1260. }
  1261. /**
  1262. * snd_soc_codec_get_dapm() - Returns the DAPM context for the CODEC
  1263. * @codec: The CODEC for which to get the DAPM context
  1264. *
  1265. * Note: Use this function instead of directly accessing the CODEC's dapm field
  1266. */
  1267. static inline struct snd_soc_dapm_context *snd_soc_codec_get_dapm(
  1268. struct snd_soc_codec *codec)
  1269. {
  1270. return snd_soc_component_get_dapm(&codec->component);
  1271. }
  1272. /**
  1273. * snd_soc_dapm_init_bias_level() - Initialize CODEC DAPM bias level
  1274. * @codec: The CODEC for which to initialize the DAPM bias level
  1275. * @level: The DAPM level to initialize to
  1276. *
  1277. * Initializes the CODEC DAPM bias level. See snd_soc_dapm_init_bias_level().
  1278. */
  1279. static inline void snd_soc_codec_init_bias_level(struct snd_soc_codec *codec,
  1280. enum snd_soc_bias_level level)
  1281. {
  1282. snd_soc_dapm_init_bias_level(snd_soc_codec_get_dapm(codec), level);
  1283. }
  1284. /**
  1285. * snd_soc_component_init_bias_level() - Initialize COMPONENT DAPM bias level
  1286. * @component: The COMPONENT for which to initialize the DAPM bias level
  1287. * @level: The DAPM level to initialize to
  1288. *
  1289. * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level().
  1290. */
  1291. static inline void
  1292. snd_soc_component_init_bias_level(struct snd_soc_component *component,
  1293. enum snd_soc_bias_level level)
  1294. {
  1295. snd_soc_dapm_init_bias_level(
  1296. snd_soc_component_get_dapm(component), level);
  1297. }
  1298. /**
  1299. * snd_soc_dapm_get_bias_level() - Get current CODEC DAPM bias level
  1300. * @codec: The CODEC for which to get the DAPM bias level
  1301. *
  1302. * Returns: The current DAPM bias level of the CODEC.
  1303. */
  1304. static inline enum snd_soc_bias_level snd_soc_codec_get_bias_level(
  1305. struct snd_soc_codec *codec)
  1306. {
  1307. return snd_soc_dapm_get_bias_level(snd_soc_codec_get_dapm(codec));
  1308. }
  1309. /**
  1310. * snd_soc_component_get_bias_level() - Get current COMPONENT DAPM bias level
  1311. * @component: The COMPONENT for which to get the DAPM bias level
  1312. *
  1313. * Returns: The current DAPM bias level of the COMPONENT.
  1314. */
  1315. static inline enum snd_soc_bias_level
  1316. snd_soc_component_get_bias_level(struct snd_soc_component *component)
  1317. {
  1318. return snd_soc_dapm_get_bias_level(
  1319. snd_soc_component_get_dapm(component));
  1320. }
  1321. /**
  1322. * snd_soc_codec_force_bias_level() - Set the CODEC DAPM bias level
  1323. * @codec: The CODEC for which to set the level
  1324. * @level: The level to set to
  1325. *
  1326. * Forces the CODEC bias level to a specific state. See
  1327. * snd_soc_dapm_force_bias_level().
  1328. */
  1329. static inline int snd_soc_codec_force_bias_level(struct snd_soc_codec *codec,
  1330. enum snd_soc_bias_level level)
  1331. {
  1332. return snd_soc_dapm_force_bias_level(snd_soc_codec_get_dapm(codec),
  1333. level);
  1334. }
  1335. /**
  1336. * snd_soc_component_force_bias_level() - Set the COMPONENT DAPM bias level
  1337. * @component: The COMPONENT for which to set the level
  1338. * @level: The level to set to
  1339. *
  1340. * Forces the COMPONENT bias level to a specific state. See
  1341. * snd_soc_dapm_force_bias_level().
  1342. */
  1343. static inline int
  1344. snd_soc_component_force_bias_level(struct snd_soc_component *component,
  1345. enum snd_soc_bias_level level)
  1346. {
  1347. return snd_soc_dapm_force_bias_level(
  1348. snd_soc_component_get_dapm(component),
  1349. level);
  1350. }
  1351. /**
  1352. * snd_soc_dapm_kcontrol_codec() - Returns the codec associated to a kcontrol
  1353. * @kcontrol: The kcontrol
  1354. *
  1355. * This function must only be used on DAPM contexts that are known to be part of
  1356. * a CODEC (e.g. in a CODEC driver). Otherwise the behavior is undefined.
  1357. */
  1358. static inline struct snd_soc_codec *snd_soc_dapm_kcontrol_codec(
  1359. struct snd_kcontrol *kcontrol)
  1360. {
  1361. return snd_soc_dapm_to_codec(snd_soc_dapm_kcontrol_dapm(kcontrol));
  1362. }
  1363. /**
  1364. * snd_soc_dapm_kcontrol_component() - Returns the component associated to a kcontrol
  1365. * @kcontrol: The kcontrol
  1366. *
  1367. * This function must only be used on DAPM contexts that are known to be part of
  1368. * a COMPONENT (e.g. in a COMPONENT driver). Otherwise the behavior is undefined.
  1369. */
  1370. static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
  1371. struct snd_kcontrol *kcontrol)
  1372. {
  1373. return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
  1374. }
  1375. /* codec IO */
  1376. unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
  1377. int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg,
  1378. unsigned int val);
  1379. /**
  1380. * snd_soc_cache_sync() - Sync the register cache with the hardware
  1381. * @codec: CODEC to sync
  1382. *
  1383. * Note: This function will call regcache_sync()
  1384. */
  1385. static inline int snd_soc_cache_sync(struct snd_soc_codec *codec)
  1386. {
  1387. return regcache_sync(codec->component.regmap);
  1388. }
  1389. /**
  1390. * snd_soc_component_cache_sync() - Sync the register cache with the hardware
  1391. * @component: COMPONENT to sync
  1392. *
  1393. * Note: This function will call regcache_sync()
  1394. */
  1395. static inline int snd_soc_component_cache_sync(
  1396. struct snd_soc_component *component)
  1397. {
  1398. return regcache_sync(component->regmap);
  1399. }
  1400. /* component IO */
  1401. int snd_soc_component_read(struct snd_soc_component *component,
  1402. unsigned int reg, unsigned int *val);
  1403. unsigned int snd_soc_component_read32(struct snd_soc_component *component,
  1404. unsigned int reg);
  1405. int snd_soc_component_write(struct snd_soc_component *component,
  1406. unsigned int reg, unsigned int val);
  1407. int snd_soc_component_update_bits(struct snd_soc_component *component,
  1408. unsigned int reg, unsigned int mask, unsigned int val);
  1409. int snd_soc_component_update_bits_async(struct snd_soc_component *component,
  1410. unsigned int reg, unsigned int mask, unsigned int val);
  1411. void snd_soc_component_async_complete(struct snd_soc_component *component);
  1412. int snd_soc_component_test_bits(struct snd_soc_component *component,
  1413. unsigned int reg, unsigned int mask, unsigned int value);
  1414. /* component wide operations */
  1415. int snd_soc_component_set_sysclk(struct snd_soc_component *component,
  1416. int clk_id, int source, unsigned int freq, int dir);
  1417. int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
  1418. int source, unsigned int freq_in,
  1419. unsigned int freq_out);
  1420. int snd_soc_component_set_jack(struct snd_soc_component *component,
  1421. struct snd_soc_jack *jack, void *data);
  1422. #ifdef CONFIG_REGMAP
  1423. void snd_soc_component_init_regmap(struct snd_soc_component *component,
  1424. struct regmap *regmap);
  1425. void snd_soc_component_exit_regmap(struct snd_soc_component *component);
  1426. /**
  1427. * snd_soc_codec_init_regmap() - Initialize regmap instance for the CODEC
  1428. * @codec: The CODEC for which to initialize the regmap instance
  1429. * @regmap: The regmap instance that should be used by the CODEC
  1430. *
  1431. * This function allows deferred assignment of the regmap instance that is
  1432. * associated with the CODEC. Only use this if the regmap instance is not yet
  1433. * ready when the CODEC is registered. The function must also be called before
  1434. * the first IO attempt of the CODEC.
  1435. */
  1436. static inline void snd_soc_codec_init_regmap(struct snd_soc_codec *codec,
  1437. struct regmap *regmap)
  1438. {
  1439. snd_soc_component_init_regmap(&codec->component, regmap);
  1440. }
  1441. /**
  1442. * snd_soc_codec_exit_regmap() - De-initialize regmap instance for the CODEC
  1443. * @codec: The CODEC for which to de-initialize the regmap instance
  1444. *
  1445. * Calls regmap_exit() on the regmap instance associated to the CODEC and
  1446. * removes the regmap instance from the CODEC.
  1447. *
  1448. * This function should only be used if snd_soc_codec_init_regmap() was used to
  1449. * initialize the regmap instance.
  1450. */
  1451. static inline void snd_soc_codec_exit_regmap(struct snd_soc_codec *codec)
  1452. {
  1453. snd_soc_component_exit_regmap(&codec->component);
  1454. }
  1455. #endif
  1456. /* device driver data */
  1457. static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
  1458. void *data)
  1459. {
  1460. card->drvdata = data;
  1461. }
  1462. static inline void *snd_soc_card_get_drvdata(struct snd_soc_card *card)
  1463. {
  1464. return card->drvdata;
  1465. }
  1466. static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
  1467. void *data)
  1468. {
  1469. dev_set_drvdata(c->dev, data);
  1470. }
  1471. static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
  1472. {
  1473. return dev_get_drvdata(c->dev);
  1474. }
  1475. static inline void snd_soc_codec_set_drvdata(struct snd_soc_codec *codec,
  1476. void *data)
  1477. {
  1478. snd_soc_component_set_drvdata(&codec->component, data);
  1479. }
  1480. static inline void *snd_soc_codec_get_drvdata(struct snd_soc_codec *codec)
  1481. {
  1482. return snd_soc_component_get_drvdata(&codec->component);
  1483. }
  1484. static inline void snd_soc_platform_set_drvdata(struct snd_soc_platform *platform,
  1485. void *data)
  1486. {
  1487. snd_soc_component_set_drvdata(&platform->component, data);
  1488. }
  1489. static inline void *snd_soc_platform_get_drvdata(struct snd_soc_platform *platform)
  1490. {
  1491. return snd_soc_component_get_drvdata(&platform->component);
  1492. }
  1493. static inline void snd_soc_initialize_card_lists(struct snd_soc_card *card)
  1494. {
  1495. INIT_LIST_HEAD(&card->widgets);
  1496. INIT_LIST_HEAD(&card->paths);
  1497. INIT_LIST_HEAD(&card->dapm_list);
  1498. INIT_LIST_HEAD(&card->aux_comp_list);
  1499. INIT_LIST_HEAD(&card->component_dev_list);
  1500. }
  1501. static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)
  1502. {
  1503. if (mc->reg == mc->rreg && mc->shift == mc->rshift)
  1504. return 0;
  1505. /*
  1506. * mc->reg == mc->rreg && mc->shift != mc->rshift, or
  1507. * mc->reg != mc->rreg means that the control is
  1508. * stereo (bits in one register or in two registers)
  1509. */
  1510. return 1;
  1511. }
  1512. static inline unsigned int snd_soc_enum_val_to_item(struct soc_enum *e,
  1513. unsigned int val)
  1514. {
  1515. unsigned int i;
  1516. if (!e->values)
  1517. return val;
  1518. for (i = 0; i < e->items; i++)
  1519. if (val == e->values[i])
  1520. return i;
  1521. return 0;
  1522. }
  1523. static inline unsigned int snd_soc_enum_item_to_val(struct soc_enum *e,
  1524. unsigned int item)
  1525. {
  1526. if (!e->values)
  1527. return item;
  1528. return e->values[item];
  1529. }
  1530. static inline bool snd_soc_component_is_active(
  1531. struct snd_soc_component *component)
  1532. {
  1533. return component->active != 0;
  1534. }
  1535. static inline bool snd_soc_codec_is_active(struct snd_soc_codec *codec)
  1536. {
  1537. return snd_soc_component_is_active(&codec->component);
  1538. }
  1539. /**
  1540. * snd_soc_kcontrol_component() - Returns the component that registered the
  1541. * control
  1542. * @kcontrol: The control for which to get the component
  1543. *
  1544. * Note: This function will work correctly if the control has been registered
  1545. * for a component. Either with snd_soc_add_codec_controls() or
  1546. * snd_soc_add_platform_controls() or via table based setup for either a
  1547. * CODEC, a platform or component driver. Otherwise the behavior is undefined.
  1548. */
  1549. static inline struct snd_soc_component *snd_soc_kcontrol_component(
  1550. struct snd_kcontrol *kcontrol)
  1551. {
  1552. return snd_kcontrol_chip(kcontrol);
  1553. }
  1554. /**
  1555. * snd_soc_kcontrol_codec() - Returns the CODEC that registered the control
  1556. * @kcontrol: The control for which to get the CODEC
  1557. *
  1558. * Note: This function will only work correctly if the control has been
  1559. * registered with snd_soc_add_codec_controls() or via table based setup of
  1560. * snd_soc_codec_driver. Otherwise the behavior is undefined.
  1561. */
  1562. static inline struct snd_soc_codec *snd_soc_kcontrol_codec(
  1563. struct snd_kcontrol *kcontrol)
  1564. {
  1565. return snd_soc_component_to_codec(snd_soc_kcontrol_component(kcontrol));
  1566. }
  1567. /**
  1568. * snd_soc_kcontrol_platform() - Returns the platform that registered the control
  1569. * @kcontrol: The control for which to get the platform
  1570. *
  1571. * Note: This function will only work correctly if the control has been
  1572. * registered with snd_soc_add_platform_controls() or via table based setup of
  1573. * a snd_soc_platform_driver. Otherwise the behavior is undefined.
  1574. */
  1575. static inline struct snd_soc_platform *snd_soc_kcontrol_platform(
  1576. struct snd_kcontrol *kcontrol)
  1577. {
  1578. return snd_soc_component_to_platform(snd_soc_kcontrol_component(kcontrol));
  1579. }
  1580. int snd_soc_util_init(void);
  1581. void snd_soc_util_exit(void);
  1582. int snd_soc_of_parse_card_name(struct snd_soc_card *card,
  1583. const char *propname);
  1584. int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
  1585. const char *propname);
  1586. int snd_soc_of_parse_tdm_slot(struct device_node *np,
  1587. unsigned int *tx_mask,
  1588. unsigned int *rx_mask,
  1589. unsigned int *slots,
  1590. unsigned int *slot_width);
  1591. void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
  1592. struct snd_soc_codec_conf *codec_conf,
  1593. struct device_node *of_node,
  1594. const char *propname);
  1595. int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
  1596. const char *propname);
  1597. unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
  1598. const char *prefix,
  1599. struct device_node **bitclkmaster,
  1600. struct device_node **framemaster);
  1601. int snd_soc_get_dai_id(struct device_node *ep);
  1602. int snd_soc_get_dai_name(struct of_phandle_args *args,
  1603. const char **dai_name);
  1604. int snd_soc_of_get_dai_name(struct device_node *of_node,
  1605. const char **dai_name);
  1606. int snd_soc_of_get_dai_link_codecs(struct device *dev,
  1607. struct device_node *of_node,
  1608. struct snd_soc_dai_link *dai_link);
  1609. void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link);
  1610. int snd_soc_add_dai_link(struct snd_soc_card *card,
  1611. struct snd_soc_dai_link *dai_link);
  1612. void snd_soc_remove_dai_link(struct snd_soc_card *card,
  1613. struct snd_soc_dai_link *dai_link);
  1614. struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card,
  1615. int id, const char *name,
  1616. const char *stream_name);
  1617. int snd_soc_register_dai(struct snd_soc_component *component,
  1618. struct snd_soc_dai_driver *dai_drv);
  1619. struct snd_soc_dai *snd_soc_find_dai(
  1620. const struct snd_soc_dai_link_component *dlc);
  1621. #include <sound/soc-dai.h>
  1622. static inline
  1623. struct snd_soc_dai *snd_soc_card_get_codec_dai(struct snd_soc_card *card,
  1624. const char *dai_name)
  1625. {
  1626. struct snd_soc_pcm_runtime *rtd;
  1627. list_for_each_entry(rtd, &card->rtd_list, list) {
  1628. if (!strcmp(rtd->codec_dai->name, dai_name))
  1629. return rtd->codec_dai;
  1630. }
  1631. return NULL;
  1632. }
  1633. #ifdef CONFIG_DEBUG_FS
  1634. extern struct dentry *snd_soc_debugfs_root;
  1635. #endif
  1636. extern const struct dev_pm_ops snd_soc_pm_ops;
  1637. /* Helper functions */
  1638. static inline void snd_soc_dapm_mutex_lock(struct snd_soc_dapm_context *dapm)
  1639. {
  1640. mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
  1641. }
  1642. static inline void snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm)
  1643. {
  1644. mutex_unlock(&dapm->card->dapm_mutex);
  1645. }
  1646. int snd_soc_component_enable_pin(struct snd_soc_component *component,
  1647. const char *pin);
  1648. int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
  1649. const char *pin);
  1650. int snd_soc_component_disable_pin(struct snd_soc_component *component,
  1651. const char *pin);
  1652. int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
  1653. const char *pin);
  1654. int snd_soc_component_nc_pin(struct snd_soc_component *component,
  1655. const char *pin);
  1656. int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
  1657. const char *pin);
  1658. int snd_soc_component_get_pin_status(struct snd_soc_component *component,
  1659. const char *pin);
  1660. int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
  1661. const char *pin);
  1662. int snd_soc_component_force_enable_pin_unlocked(
  1663. struct snd_soc_component *component,
  1664. const char *pin);
  1665. #endif