soc.h 47 KB

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