soc-dapm.h 32 KB

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