soc.h 54 KB

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