soc-dapm.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * linux/sound/soc-dapm.h -- ALSA SoC Dynamic Audio Power Management
  4. *
  5. * Author: Liam Girdwood
  6. * Created: Aug 11th 2005
  7. * Copyright: Wolfson Microelectronics. PLC.
  8. */
  9. #ifndef __LINUX_SND_SOC_DAPM_H
  10. #define __LINUX_SND_SOC_DAPM_H
  11. #include <linux/types.h>
  12. #include <sound/control.h>
  13. #include <sound/soc-topology.h>
  14. #include <sound/asoc.h>
  15. struct device;
  16. /* widget has no PM register bit */
  17. #define SND_SOC_NOPM -1
  18. /*
  19. * SoC dynamic audio power management
  20. *
  21. * We can have up to 4 power domains
  22. * 1. Codec domain - VREF, VMID
  23. * Usually controlled at codec probe/remove, although can be set
  24. * at stream time if power is not needed for sidetone, etc.
  25. * 2. Platform/Machine domain - physically connected inputs and outputs
  26. * Is platform/machine and user action specific, is set in the machine
  27. * driver and by userspace e.g when HP are inserted
  28. * 3. Path domain - Internal codec path mixers
  29. * Are automatically set when mixer and mux settings are
  30. * changed by the user.
  31. * 4. Stream domain - DAC's and ADC's.
  32. * Enabled when stream playback/capture is started.
  33. */
  34. /* codec domain */
  35. #define SND_SOC_DAPM_VMID(wname) \
  36. { .id = snd_soc_dapm_vmid, .name = wname, .kcontrol_news = NULL, \
  37. .num_kcontrols = 0}
  38. /* platform domain */
  39. #define SND_SOC_DAPM_SIGGEN(wname) \
  40. { .id = snd_soc_dapm_siggen, .name = wname, .kcontrol_news = NULL, \
  41. .num_kcontrols = 0, .reg = SND_SOC_NOPM }
  42. #define SND_SOC_DAPM_SINK(wname) \
  43. { .id = snd_soc_dapm_sink, .name = wname, .kcontrol_news = NULL, \
  44. .num_kcontrols = 0, .reg = SND_SOC_NOPM }
  45. #define SND_SOC_DAPM_INPUT(wname) \
  46. { .id = snd_soc_dapm_input, .name = wname, .kcontrol_news = NULL, \
  47. .num_kcontrols = 0, .reg = SND_SOC_NOPM }
  48. #define SND_SOC_DAPM_OUTPUT(wname) \
  49. { .id = snd_soc_dapm_output, .name = wname, .kcontrol_news = NULL, \
  50. .num_kcontrols = 0, .reg = SND_SOC_NOPM }
  51. #define SND_SOC_DAPM_MIC(wname, wevent) \
  52. { .id = snd_soc_dapm_mic, .name = wname, .kcontrol_news = NULL, \
  53. .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
  54. .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD}
  55. #define SND_SOC_DAPM_HP(wname, wevent) \
  56. { .id = snd_soc_dapm_hp, .name = wname, .kcontrol_news = NULL, \
  57. .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
  58. .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
  59. #define SND_SOC_DAPM_SPK(wname, wevent) \
  60. { .id = snd_soc_dapm_spk, .name = wname, .kcontrol_news = NULL, \
  61. .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
  62. .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
  63. #define SND_SOC_DAPM_LINE(wname, wevent) \
  64. { .id = snd_soc_dapm_line, .name = wname, .kcontrol_news = NULL, \
  65. .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
  66. .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
  67. #define SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert) \
  68. .reg = wreg, .mask = 1, .shift = wshift, \
  69. .on_val = winvert ? 0 : 1, .off_val = winvert ? 1 : 0
  70. /* path domain */
  71. #define SND_SOC_DAPM_PGA(wname, wreg, wshift, winvert,\
  72. wcontrols, wncontrols) \
  73. { .id = snd_soc_dapm_pga, .name = wname, \
  74. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  75. .kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
  76. #define SND_SOC_DAPM_OUT_DRV(wname, wreg, wshift, winvert,\
  77. wcontrols, wncontrols) \
  78. { .id = snd_soc_dapm_out_drv, .name = wname, \
  79. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  80. .kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
  81. #define SND_SOC_DAPM_MIXER(wname, wreg, wshift, winvert, \
  82. wcontrols, wncontrols)\
  83. { .id = snd_soc_dapm_mixer, .name = wname, \
  84. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  85. .kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
  86. #define SND_SOC_DAPM_MIXER_NAMED_CTL(wname, wreg, wshift, winvert, \
  87. wcontrols, wncontrols)\
  88. { .id = snd_soc_dapm_mixer_named_ctl, .name = wname, \
  89. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  90. .kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
  91. /* DEPRECATED: use SND_SOC_DAPM_SUPPLY */
  92. #define SND_SOC_DAPM_MICBIAS(wname, wreg, wshift, winvert) \
  93. { .id = snd_soc_dapm_micbias, .name = wname, \
  94. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  95. .kcontrol_news = NULL, .num_kcontrols = 0}
  96. #define SND_SOC_DAPM_SWITCH(wname, wreg, wshift, winvert, wcontrols) \
  97. { .id = snd_soc_dapm_switch, .name = wname, \
  98. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  99. .kcontrol_news = wcontrols, .num_kcontrols = 1}
  100. #define SND_SOC_DAPM_MUX(wname, wreg, wshift, winvert, wcontrols) \
  101. { .id = snd_soc_dapm_mux, .name = wname, \
  102. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  103. .kcontrol_news = wcontrols, .num_kcontrols = 1}
  104. #define SND_SOC_DAPM_DEMUX(wname, wreg, wshift, winvert, wcontrols) \
  105. { .id = snd_soc_dapm_demux, .name = wname, \
  106. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  107. .kcontrol_news = wcontrols, .num_kcontrols = 1}
  108. /* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */
  109. #define SOC_PGA_ARRAY(wname, wreg, wshift, winvert,\
  110. wcontrols) \
  111. { .id = snd_soc_dapm_pga, .name = wname, \
  112. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  113. .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols)}
  114. #define SOC_MIXER_ARRAY(wname, wreg, wshift, winvert, \
  115. wcontrols)\
  116. { .id = snd_soc_dapm_mixer, .name = wname, \
  117. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  118. .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols)}
  119. #define SOC_MIXER_NAMED_CTL_ARRAY(wname, wreg, wshift, winvert, \
  120. wcontrols)\
  121. { .id = snd_soc_dapm_mixer_named_ctl, .name = wname, \
  122. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  123. .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols)}
  124. /* path domain with event - event handler must return 0 for success */
  125. #define SND_SOC_DAPM_PGA_E(wname, wreg, wshift, winvert, wcontrols, \
  126. wncontrols, wevent, wflags) \
  127. { .id = snd_soc_dapm_pga, .name = wname, \
  128. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  129. .kcontrol_news = wcontrols, .num_kcontrols = wncontrols, \
  130. .event = wevent, .event_flags = wflags}
  131. #define SND_SOC_DAPM_OUT_DRV_E(wname, wreg, wshift, winvert, wcontrols, \
  132. wncontrols, wevent, wflags) \
  133. { .id = snd_soc_dapm_out_drv, .name = wname, \
  134. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  135. .kcontrol_news = wcontrols, .num_kcontrols = wncontrols, \
  136. .event = wevent, .event_flags = wflags}
  137. #define SND_SOC_DAPM_MIXER_E(wname, wreg, wshift, winvert, wcontrols, \
  138. wncontrols, wevent, wflags) \
  139. { .id = snd_soc_dapm_mixer, .name = wname, \
  140. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  141. .kcontrol_news = wcontrols, .num_kcontrols = wncontrols, \
  142. .event = wevent, .event_flags = wflags}
  143. #define SND_SOC_DAPM_MIXER_NAMED_CTL_E(wname, wreg, wshift, winvert, \
  144. wcontrols, wncontrols, wevent, wflags) \
  145. { .id = snd_soc_dapm_mixer, .name = wname, \
  146. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  147. .kcontrol_news = wcontrols, \
  148. .num_kcontrols = wncontrols, .event = wevent, .event_flags = wflags}
  149. #define SND_SOC_DAPM_SWITCH_E(wname, wreg, wshift, winvert, wcontrols, \
  150. wevent, wflags) \
  151. { .id = snd_soc_dapm_switch, .name = wname, \
  152. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  153. .kcontrol_news = wcontrols, .num_kcontrols = 1, \
  154. .event = wevent, .event_flags = wflags}
  155. #define SND_SOC_DAPM_MUX_E(wname, wreg, wshift, winvert, wcontrols, \
  156. wevent, wflags) \
  157. { .id = snd_soc_dapm_mux, .name = wname, \
  158. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  159. .kcontrol_news = wcontrols, .num_kcontrols = 1, \
  160. .event = wevent, .event_flags = wflags}
  161. /* additional sequencing control within an event type */
  162. #define SND_SOC_DAPM_PGA_S(wname, wsubseq, wreg, wshift, winvert, \
  163. wevent, wflags) \
  164. { .id = snd_soc_dapm_pga, .name = wname, \
  165. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  166. .event = wevent, .event_flags = wflags, \
  167. .subseq = wsubseq}
  168. #define SND_SOC_DAPM_SUPPLY_S(wname, wsubseq, wreg, wshift, winvert, wevent, \
  169. wflags) \
  170. { .id = snd_soc_dapm_supply, .name = wname, \
  171. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  172. .event = wevent, .event_flags = wflags, .subseq = wsubseq}
  173. /* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */
  174. #define SOC_PGA_E_ARRAY(wname, wreg, wshift, winvert, wcontrols, \
  175. wevent, wflags) \
  176. { .id = snd_soc_dapm_pga, .name = wname, \
  177. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  178. .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols), \
  179. .event = wevent, .event_flags = wflags}
  180. #define SOC_MIXER_E_ARRAY(wname, wreg, wshift, winvert, wcontrols, \
  181. wevent, wflags) \
  182. { .id = snd_soc_dapm_mixer, .name = wname, \
  183. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  184. .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols), \
  185. .event = wevent, .event_flags = wflags}
  186. #define SOC_MIXER_NAMED_CTL_E_ARRAY(wname, wreg, wshift, winvert, \
  187. wcontrols, wevent, wflags) \
  188. { .id = snd_soc_dapm_mixer, .name = wname, \
  189. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  190. .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols), \
  191. .event = wevent, .event_flags = wflags}
  192. /* events that are pre and post DAPM */
  193. #define SND_SOC_DAPM_PRE(wname, wevent) \
  194. { .id = snd_soc_dapm_pre, .name = wname, .kcontrol_news = NULL, \
  195. .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
  196. .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD}
  197. #define SND_SOC_DAPM_POST(wname, wevent) \
  198. { .id = snd_soc_dapm_post, .name = wname, .kcontrol_news = NULL, \
  199. .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
  200. .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD}
  201. /* stream domain */
  202. #define SND_SOC_DAPM_AIF_IN(wname, stname, wslot, wreg, wshift, winvert) \
  203. { .id = snd_soc_dapm_aif_in, .name = wname, .sname = stname, \
  204. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), }
  205. #define SND_SOC_DAPM_AIF_IN_E(wname, stname, wslot, wreg, wshift, winvert, \
  206. wevent, wflags) \
  207. { .id = snd_soc_dapm_aif_in, .name = wname, .sname = stname, \
  208. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  209. .event = wevent, .event_flags = wflags }
  210. #define SND_SOC_DAPM_AIF_OUT(wname, stname, wslot, wreg, wshift, winvert) \
  211. { .id = snd_soc_dapm_aif_out, .name = wname, .sname = stname, \
  212. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), }
  213. #define SND_SOC_DAPM_AIF_OUT_E(wname, stname, wslot, wreg, wshift, winvert, \
  214. wevent, wflags) \
  215. { .id = snd_soc_dapm_aif_out, .name = wname, .sname = stname, \
  216. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  217. .event = wevent, .event_flags = wflags }
  218. #define SND_SOC_DAPM_DAC(wname, stname, wreg, wshift, winvert) \
  219. { .id = snd_soc_dapm_dac, .name = wname, .sname = stname, \
  220. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert) }
  221. #define SND_SOC_DAPM_DAC_E(wname, stname, wreg, wshift, winvert, \
  222. wevent, wflags) \
  223. { .id = snd_soc_dapm_dac, .name = wname, .sname = stname, \
  224. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  225. .event = wevent, .event_flags = wflags}
  226. #define SND_SOC_DAPM_ADC(wname, stname, wreg, wshift, winvert) \
  227. { .id = snd_soc_dapm_adc, .name = wname, .sname = stname, \
  228. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), }
  229. #define SND_SOC_DAPM_ADC_E(wname, stname, wreg, wshift, winvert, \
  230. wevent, wflags) \
  231. { .id = snd_soc_dapm_adc, .name = wname, .sname = stname, \
  232. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  233. .event = wevent, .event_flags = wflags}
  234. #define SND_SOC_DAPM_CLOCK_SUPPLY(wname) \
  235. { .id = snd_soc_dapm_clock_supply, .name = wname, \
  236. .reg = SND_SOC_NOPM, .event = dapm_clock_event, \
  237. .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD }
  238. /* generic widgets */
  239. #define SND_SOC_DAPM_REG(wid, wname, wreg, wshift, wmask, won_val, woff_val) \
  240. { .id = wid, .name = wname, .kcontrol_news = NULL, .num_kcontrols = 0, \
  241. .reg = wreg, .shift = wshift, .mask = wmask, \
  242. .on_val = won_val, .off_val = woff_val, }
  243. #define SND_SOC_DAPM_SUPPLY(wname, wreg, wshift, winvert, wevent, wflags) \
  244. { .id = snd_soc_dapm_supply, .name = wname, \
  245. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  246. .event = wevent, .event_flags = wflags}
  247. #define SND_SOC_DAPM_REGULATOR_SUPPLY(wname, wdelay, wflags) \
  248. { .id = snd_soc_dapm_regulator_supply, .name = wname, \
  249. .reg = SND_SOC_NOPM, .shift = wdelay, .event = dapm_regulator_event, \
  250. .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD, \
  251. .on_val = wflags}
  252. #define SND_SOC_DAPM_PINCTRL(wname, active, sleep) \
  253. { .id = snd_soc_dapm_pinctrl, .name = wname, \
  254. .priv = (&(struct snd_soc_dapm_pinctrl_priv) \
  255. { .active_state = active, .sleep_state = sleep,}), \
  256. .reg = SND_SOC_NOPM, .event = dapm_pinctrl_event, \
  257. .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD }
  258. /* dapm kcontrol types */
  259. #define SOC_DAPM_DOUBLE(xname, reg, lshift, rshift, max, invert) \
  260. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  261. .info = snd_soc_info_volsw, \
  262. .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
  263. .private_value = SOC_DOUBLE_VALUE(reg, lshift, rshift, max, invert, 0) }
  264. #define SOC_DAPM_DOUBLE_R(xname, lreg, rreg, shift, max, invert) \
  265. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  266. .info = snd_soc_info_volsw, \
  267. .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
  268. .private_value = SOC_DOUBLE_R_VALUE(lreg, rreg, shift, max, invert) }
  269. #define SOC_DAPM_SINGLE(xname, reg, shift, max, invert) \
  270. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  271. .info = snd_soc_info_volsw, \
  272. .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
  273. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  274. #define SOC_DAPM_SINGLE_AUTODISABLE(xname, reg, shift, max, invert) \
  275. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  276. .info = snd_soc_info_volsw, \
  277. .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
  278. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 1) }
  279. #define SOC_DAPM_SINGLE_VIRT(xname, max) \
  280. SOC_DAPM_SINGLE(xname, SND_SOC_NOPM, 0, max, 0)
  281. #define SOC_DAPM_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
  282. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  283. .info = snd_soc_info_volsw, \
  284. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  285. .tlv.p = (tlv_array), \
  286. .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
  287. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  288. #define SOC_DAPM_SINGLE_TLV_AUTODISABLE(xname, reg, shift, max, invert, tlv_array) \
  289. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  290. .info = snd_soc_info_volsw, \
  291. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  292. .tlv.p = (tlv_array), \
  293. .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
  294. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 1) }
  295. #define SOC_DAPM_SINGLE_TLV_VIRT(xname, max, tlv_array) \
  296. SOC_DAPM_SINGLE(xname, SND_SOC_NOPM, 0, max, 0, tlv_array)
  297. #define SOC_DAPM_ENUM(xname, xenum) \
  298. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  299. .info = snd_soc_info_enum_double, \
  300. .get = snd_soc_dapm_get_enum_double, \
  301. .put = snd_soc_dapm_put_enum_double, \
  302. .private_value = (unsigned long)&xenum }
  303. #define SOC_DAPM_ENUM_EXT(xname, xenum, xget, xput) \
  304. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  305. .info = snd_soc_info_enum_double, \
  306. .get = xget, \
  307. .put = xput, \
  308. .private_value = (unsigned long)&xenum }
  309. #define SOC_DAPM_PIN_SWITCH(xname) \
  310. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname " Switch", \
  311. .info = snd_soc_dapm_info_pin_switch, \
  312. .get = snd_soc_dapm_get_pin_switch, \
  313. .put = snd_soc_dapm_put_pin_switch, \
  314. .private_value = (unsigned long)xname }
  315. /* dapm stream operations */
  316. #define SND_SOC_DAPM_STREAM_NOP 0x0
  317. #define SND_SOC_DAPM_STREAM_START 0x1
  318. #define SND_SOC_DAPM_STREAM_STOP 0x2
  319. #define SND_SOC_DAPM_STREAM_SUSPEND 0x4
  320. #define SND_SOC_DAPM_STREAM_RESUME 0x8
  321. #define SND_SOC_DAPM_STREAM_PAUSE_PUSH 0x10
  322. #define SND_SOC_DAPM_STREAM_PAUSE_RELEASE 0x20
  323. /* dapm event types */
  324. #define SND_SOC_DAPM_PRE_PMU 0x1 /* before widget power up */
  325. #define SND_SOC_DAPM_POST_PMU 0x2 /* after widget power up */
  326. #define SND_SOC_DAPM_PRE_PMD 0x4 /* before widget power down */
  327. #define SND_SOC_DAPM_POST_PMD 0x8 /* after widget power down */
  328. #define SND_SOC_DAPM_PRE_REG 0x10 /* before audio path setup */
  329. #define SND_SOC_DAPM_POST_REG 0x20 /* after audio path setup */
  330. #define SND_SOC_DAPM_WILL_PMU 0x40 /* called at start of sequence */
  331. #define SND_SOC_DAPM_WILL_PMD 0x80 /* called at start of sequence */
  332. #define SND_SOC_DAPM_PRE_POST_PMD \
  333. (SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD)
  334. #define SND_SOC_DAPM_PRE_POST_PMU \
  335. (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU)
  336. /* convenience event type detection */
  337. #define SND_SOC_DAPM_EVENT_ON(e) \
  338. (e & (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU))
  339. #define SND_SOC_DAPM_EVENT_OFF(e) \
  340. (e & (SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD))
  341. /* regulator widget flags */
  342. #define SND_SOC_DAPM_REGULATOR_BYPASS 0x1 /* bypass when disabled */
  343. struct snd_soc_dapm_widget;
  344. enum snd_soc_dapm_type;
  345. struct snd_soc_dapm_path;
  346. struct snd_soc_dapm_pin;
  347. struct snd_soc_dapm_route;
  348. struct snd_soc_dapm_context;
  349. struct regulator;
  350. struct snd_soc_dapm_widget_list;
  351. struct snd_soc_dapm_update;
  352. enum snd_soc_dapm_direction;
  353. int dapm_regulator_event(struct snd_soc_dapm_widget *w,
  354. struct snd_kcontrol *kcontrol, int event);
  355. int dapm_clock_event(struct snd_soc_dapm_widget *w,
  356. struct snd_kcontrol *kcontrol, int event);
  357. int dapm_pinctrl_event(struct snd_soc_dapm_widget *w,
  358. struct snd_kcontrol *kcontrol, int event);
  359. /* dapm controls */
  360. int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
  361. struct snd_ctl_elem_value *ucontrol);
  362. int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
  363. struct snd_ctl_elem_value *ucontrol);
  364. int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
  365. struct snd_ctl_elem_value *ucontrol);
  366. int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
  367. struct snd_ctl_elem_value *ucontrol);
  368. int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
  369. struct snd_ctl_elem_info *uinfo);
  370. int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
  371. struct snd_ctl_elem_value *uncontrol);
  372. int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
  373. struct snd_ctl_elem_value *uncontrol);
  374. int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
  375. const struct snd_soc_dapm_widget *widget,
  376. int num);
  377. struct snd_soc_dapm_widget *snd_soc_dapm_new_control(
  378. struct snd_soc_dapm_context *dapm,
  379. const struct snd_soc_dapm_widget *widget);
  380. int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
  381. struct snd_soc_dai *dai);
  382. int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card);
  383. void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card);
  384. int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
  385. struct snd_soc_pcm_runtime *rtd,
  386. const struct snd_soc_pcm_stream *params,
  387. unsigned int num_params,
  388. struct snd_soc_dapm_widget *source,
  389. struct snd_soc_dapm_widget *sink);
  390. /* dapm path setup */
  391. int snd_soc_dapm_new_widgets(struct snd_soc_card *card);
  392. void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm);
  393. int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
  394. const struct snd_soc_dapm_route *route, int num);
  395. int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm,
  396. const struct snd_soc_dapm_route *route, int num);
  397. int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
  398. const struct snd_soc_dapm_route *route, int num);
  399. void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w);
  400. void snd_soc_dapm_reset_cache(struct snd_soc_dapm_context *dapm);
  401. /* dapm events */
  402. void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
  403. int event);
  404. void snd_soc_dapm_shutdown(struct snd_soc_card *card);
  405. /* external DAPM widget events */
  406. int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context *dapm,
  407. struct snd_kcontrol *kcontrol, int connect,
  408. struct snd_soc_dapm_update *update);
  409. int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context *dapm,
  410. struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e,
  411. struct snd_soc_dapm_update *update);
  412. /* dapm sys fs - used by the core */
  413. extern struct attribute *soc_dapm_dev_attrs[];
  414. void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
  415. struct dentry *parent);
  416. /* dapm audio pin control and status */
  417. int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm,
  418. const char *pin);
  419. int snd_soc_dapm_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
  420. const char *pin);
  421. int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
  422. const char *pin);
  423. int snd_soc_dapm_disable_pin_unlocked(struct snd_soc_dapm_context *dapm,
  424. const char *pin);
  425. int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin);
  426. int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context *dapm,
  427. const char *pin);
  428. int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
  429. const char *pin);
  430. int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm);
  431. int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context *dapm);
  432. int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
  433. const char *pin);
  434. int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
  435. const char *pin);
  436. int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
  437. const char *pin);
  438. unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol *kcontrol);
  439. /* Mostly internal - should not normally be used */
  440. void dapm_mark_endpoints_dirty(struct snd_soc_card *card);
  441. /* dapm path query */
  442. int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
  443. struct snd_soc_dapm_widget_list **list,
  444. bool (*custom_stop_condition)(struct snd_soc_dapm_widget *,
  445. enum snd_soc_dapm_direction));
  446. struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_dapm(
  447. struct snd_kcontrol *kcontrol);
  448. struct snd_soc_dapm_widget *snd_soc_dapm_kcontrol_widget(
  449. struct snd_kcontrol *kcontrol);
  450. int snd_soc_dapm_force_bias_level(struct snd_soc_dapm_context *dapm,
  451. enum snd_soc_bias_level level);
  452. /* dapm widget types */
  453. enum snd_soc_dapm_type {
  454. snd_soc_dapm_input = 0, /* input pin */
  455. snd_soc_dapm_output, /* output pin */
  456. snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */
  457. snd_soc_dapm_demux, /* connects the input to one of multiple outputs */
  458. snd_soc_dapm_mixer, /* mixes several analog signals together */
  459. snd_soc_dapm_mixer_named_ctl, /* mixer with named controls */
  460. snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */
  461. snd_soc_dapm_out_drv, /* output driver */
  462. snd_soc_dapm_adc, /* analog to digital converter */
  463. snd_soc_dapm_dac, /* digital to analog converter */
  464. snd_soc_dapm_micbias, /* microphone bias (power) - DEPRECATED: use snd_soc_dapm_supply */
  465. snd_soc_dapm_mic, /* microphone */
  466. snd_soc_dapm_hp, /* headphones */
  467. snd_soc_dapm_spk, /* speaker */
  468. snd_soc_dapm_line, /* line input/output */
  469. snd_soc_dapm_switch, /* analog switch */
  470. snd_soc_dapm_vmid, /* codec bias/vmid - to minimise pops */
  471. snd_soc_dapm_pre, /* machine specific pre widget - exec first */
  472. snd_soc_dapm_post, /* machine specific post widget - exec last */
  473. snd_soc_dapm_supply, /* power/clock supply */
  474. snd_soc_dapm_pinctrl, /* pinctrl */
  475. snd_soc_dapm_regulator_supply, /* external regulator */
  476. snd_soc_dapm_clock_supply, /* external clock */
  477. snd_soc_dapm_aif_in, /* audio interface input */
  478. snd_soc_dapm_aif_out, /* audio interface output */
  479. snd_soc_dapm_siggen, /* signal generator */
  480. snd_soc_dapm_sink,
  481. snd_soc_dapm_dai_in, /* link to DAI structure */
  482. snd_soc_dapm_dai_out,
  483. snd_soc_dapm_dai_link, /* link between two DAI structures */
  484. snd_soc_dapm_kcontrol, /* Auto-disabled kcontrol */
  485. snd_soc_dapm_buffer, /* DSP/CODEC internal buffer */
  486. snd_soc_dapm_scheduler, /* DSP/CODEC internal scheduler */
  487. snd_soc_dapm_effect, /* DSP/CODEC effect component */
  488. snd_soc_dapm_src, /* DSP/CODEC SRC component */
  489. snd_soc_dapm_asrc, /* DSP/CODEC ASRC component */
  490. snd_soc_dapm_encoder, /* FW/SW audio encoder component */
  491. snd_soc_dapm_decoder, /* FW/SW audio decoder component */
  492. };
  493. enum snd_soc_dapm_subclass {
  494. SND_SOC_DAPM_CLASS_INIT = 0,
  495. SND_SOC_DAPM_CLASS_RUNTIME = 1,
  496. };
  497. /*
  498. * DAPM audio route definition.
  499. *
  500. * Defines an audio route originating at source via control and finishing
  501. * at sink.
  502. */
  503. struct snd_soc_dapm_route {
  504. const char *sink;
  505. const char *control;
  506. const char *source;
  507. /* Note: currently only supported for links where source is a supply */
  508. int (*connected)(struct snd_soc_dapm_widget *source,
  509. struct snd_soc_dapm_widget *sink);
  510. };
  511. /* dapm audio path between two widgets */
  512. struct snd_soc_dapm_path {
  513. const char *name;
  514. /*
  515. * source (input) and sink (output) widgets
  516. * The union is for convience, since it is a lot nicer to type
  517. * p->source, rather than p->node[SND_SOC_DAPM_DIR_IN]
  518. */
  519. union {
  520. struct {
  521. struct snd_soc_dapm_widget *source;
  522. struct snd_soc_dapm_widget *sink;
  523. };
  524. struct snd_soc_dapm_widget *node[2];
  525. };
  526. /* status */
  527. u32 connect:1; /* source and sink widgets are connected */
  528. u32 walking:1; /* path is in the process of being walked */
  529. u32 weak:1; /* path ignored for power management */
  530. u32 is_supply:1; /* At least one of the connected widgets is a supply */
  531. int (*connected)(struct snd_soc_dapm_widget *source,
  532. struct snd_soc_dapm_widget *sink);
  533. struct list_head list_node[2];
  534. struct list_head list_kcontrol;
  535. struct list_head list;
  536. };
  537. /* dapm widget */
  538. struct snd_soc_dapm_widget {
  539. enum snd_soc_dapm_type id;
  540. const char *name; /* widget name */
  541. const char *sname; /* stream name */
  542. struct list_head list;
  543. struct snd_soc_dapm_context *dapm;
  544. void *priv; /* widget specific data */
  545. struct regulator *regulator; /* attached regulator */
  546. struct pinctrl *pinctrl; /* attached pinctrl */
  547. const struct snd_soc_pcm_stream *params; /* params for dai links */
  548. unsigned int num_params; /* number of params for dai links */
  549. unsigned int params_select; /* currently selected param for dai link */
  550. /* dapm control */
  551. int reg; /* negative reg = no direct dapm */
  552. unsigned char shift; /* bits to shift */
  553. unsigned int mask; /* non-shifted mask */
  554. unsigned int on_val; /* on state value */
  555. unsigned int off_val; /* off state value */
  556. unsigned char power:1; /* block power status */
  557. unsigned char active:1; /* active stream on DAC, ADC's */
  558. unsigned char connected:1; /* connected codec pin */
  559. unsigned char new:1; /* cnew complete */
  560. unsigned char force:1; /* force state */
  561. unsigned char ignore_suspend:1; /* kept enabled over suspend */
  562. unsigned char new_power:1; /* power from this run */
  563. unsigned char power_checked:1; /* power checked this run */
  564. unsigned char is_supply:1; /* Widget is a supply type widget */
  565. unsigned char is_ep:2; /* Widget is a endpoint type widget */
  566. int subseq; /* sort within widget type */
  567. int (*power_check)(struct snd_soc_dapm_widget *w);
  568. /* external events */
  569. unsigned short event_flags; /* flags to specify event types */
  570. int (*event)(struct snd_soc_dapm_widget*, struct snd_kcontrol *, int);
  571. /* kcontrols that relate to this widget */
  572. int num_kcontrols;
  573. const struct snd_kcontrol_new *kcontrol_news;
  574. struct snd_kcontrol **kcontrols;
  575. struct snd_soc_dobj dobj;
  576. /* widget input and output edges */
  577. struct list_head edges[2];
  578. /* used during DAPM updates */
  579. struct list_head work_list;
  580. struct list_head power_list;
  581. struct list_head dirty;
  582. int endpoints[2];
  583. struct clk *clk;
  584. };
  585. struct snd_soc_dapm_update {
  586. struct snd_kcontrol *kcontrol;
  587. int reg;
  588. int mask;
  589. int val;
  590. int reg2;
  591. int mask2;
  592. int val2;
  593. bool has_second_set;
  594. };
  595. struct snd_soc_dapm_wcache {
  596. struct snd_soc_dapm_widget *widget;
  597. };
  598. /* DAPM context */
  599. struct snd_soc_dapm_context {
  600. enum snd_soc_bias_level bias_level;
  601. unsigned int idle_bias_off:1; /* Use BIAS_OFF instead of STANDBY */
  602. /* Go to BIAS_OFF in suspend if the DAPM context is idle */
  603. unsigned int suspend_bias_off:1;
  604. void (*seq_notifier)(struct snd_soc_dapm_context *,
  605. enum snd_soc_dapm_type, int);
  606. struct device *dev; /* from parent - for debug */
  607. struct snd_soc_component *component; /* parent component */
  608. struct snd_soc_card *card; /* parent card */
  609. /* used during DAPM updates */
  610. enum snd_soc_bias_level target_bias_level;
  611. struct list_head list;
  612. int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
  613. int (*set_bias_level)(struct snd_soc_dapm_context *dapm,
  614. enum snd_soc_bias_level level);
  615. struct snd_soc_dapm_wcache path_sink_cache;
  616. struct snd_soc_dapm_wcache path_source_cache;
  617. #ifdef CONFIG_DEBUG_FS
  618. struct dentry *debugfs_dapm;
  619. #endif
  620. };
  621. /* A list of widgets associated with an object, typically a snd_kcontrol */
  622. struct snd_soc_dapm_widget_list {
  623. int num_widgets;
  624. struct snd_soc_dapm_widget *widgets[0];
  625. };
  626. struct snd_soc_dapm_stats {
  627. int power_checks;
  628. int path_checks;
  629. int neighbour_checks;
  630. };
  631. struct snd_soc_dapm_pinctrl_priv {
  632. const char *active_state;
  633. const char *sleep_state;
  634. };
  635. /**
  636. * snd_soc_dapm_init_bias_level() - Initialize DAPM bias level
  637. * @dapm: The DAPM context to initialize
  638. * @level: The DAPM level to initialize to
  639. *
  640. * This function only sets the driver internal state of the DAPM level and will
  641. * not modify the state of the device. Hence it should not be used during normal
  642. * operation, but only to synchronize the internal state to the device state.
  643. * E.g. during driver probe to set the DAPM level to the one corresponding with
  644. * the power-on reset state of the device.
  645. *
  646. * To change the DAPM state of the device use snd_soc_dapm_set_bias_level().
  647. */
  648. static inline void snd_soc_dapm_init_bias_level(
  649. struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
  650. {
  651. dapm->bias_level = level;
  652. }
  653. /**
  654. * snd_soc_dapm_get_bias_level() - Get current DAPM bias level
  655. * @dapm: The context for which to get the bias level
  656. *
  657. * Returns: The current bias level of the passed DAPM context.
  658. */
  659. static inline enum snd_soc_bias_level snd_soc_dapm_get_bias_level(
  660. struct snd_soc_dapm_context *dapm)
  661. {
  662. return dapm->bias_level;
  663. }
  664. enum snd_soc_dapm_direction {
  665. SND_SOC_DAPM_DIR_IN,
  666. SND_SOC_DAPM_DIR_OUT
  667. };
  668. #define SND_SOC_DAPM_DIR_TO_EP(x) BIT(x)
  669. #define SND_SOC_DAPM_EP_SOURCE SND_SOC_DAPM_DIR_TO_EP(SND_SOC_DAPM_DIR_IN)
  670. #define SND_SOC_DAPM_EP_SINK SND_SOC_DAPM_DIR_TO_EP(SND_SOC_DAPM_DIR_OUT)
  671. /**
  672. * snd_soc_dapm_widget_for_each_sink_path - Iterates over all paths in the
  673. * specified direction of a widget
  674. * @w: The widget
  675. * @dir: Whether to iterate over the paths where the specified widget is the
  676. * incoming or outgoing widgets
  677. * @p: The path iterator variable
  678. */
  679. #define snd_soc_dapm_widget_for_each_path(w, dir, p) \
  680. list_for_each_entry(p, &w->edges[dir], list_node[dir])
  681. /**
  682. * snd_soc_dapm_widget_for_each_sink_path_safe - Iterates over all paths in the
  683. * specified direction of a widget
  684. * @w: The widget
  685. * @dir: Whether to iterate over the paths where the specified widget is the
  686. * incoming or outgoing widgets
  687. * @p: The path iterator variable
  688. * @next_p: Temporary storage for the next path
  689. *
  690. * This function works like snd_soc_dapm_widget_for_each_sink_path, expect that
  691. * it is safe to remove the current path from the list while iterating
  692. */
  693. #define snd_soc_dapm_widget_for_each_path_safe(w, dir, p, next_p) \
  694. list_for_each_entry_safe(p, next_p, &w->edges[dir], list_node[dir])
  695. /**
  696. * snd_soc_dapm_widget_for_each_sink_path - Iterates over all paths leaving a
  697. * widget
  698. * @w: The widget
  699. * @p: The path iterator variable
  700. */
  701. #define snd_soc_dapm_widget_for_each_sink_path(w, p) \
  702. snd_soc_dapm_widget_for_each_path(w, SND_SOC_DAPM_DIR_IN, p)
  703. /**
  704. * snd_soc_dapm_widget_for_each_source_path - Iterates over all paths leading to
  705. * a widget
  706. * @w: The widget
  707. * @p: The path iterator variable
  708. */
  709. #define snd_soc_dapm_widget_for_each_source_path(w, p) \
  710. snd_soc_dapm_widget_for_each_path(w, SND_SOC_DAPM_DIR_OUT, p)
  711. #endif