soc.h 40 KB

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