soc.h 41 KB

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