soc-dapm.h 31 KB

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