soc.h 40 KB

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