soc.h 56 KB

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