soc.h 40 KB

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