soc-dapm.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. struct device;
  17. /* widget has no PM register bit */
  18. #define SND_SOC_NOPM -1
  19. /*
  20. * SoC dynamic audio power management
  21. *
  22. * We can have up to 4 power domains
  23. * 1. Codec domain - VREF, VMID
  24. * Usually controlled at codec probe/remove, although can be set
  25. * at stream time if power is not needed for sidetone, etc.
  26. * 2. Platform/Machine domain - physically connected inputs and outputs
  27. * Is platform/machine and user action specific, is set in the machine
  28. * driver and by userspace e.g when HP are inserted
  29. * 3. Path domain - Internal codec path mixers
  30. * Are automatically set when mixer and mux settings are
  31. * changed by the user.
  32. * 4. Stream domain - DAC's and ADC's.
  33. * Enabled when stream playback/capture is started.
  34. */
  35. /* codec domain */
  36. #define SND_SOC_DAPM_VMID(wname) \
  37. { .id = snd_soc_dapm_vmid, .name = wname, .kcontrol_news = NULL, \
  38. .num_kcontrols = 0}
  39. /* platform domain */
  40. #define SND_SOC_DAPM_SIGGEN(wname) \
  41. { .id = snd_soc_dapm_siggen, .name = wname, .kcontrol_news = NULL, \
  42. .num_kcontrols = 0, .reg = SND_SOC_NOPM }
  43. #define SND_SOC_DAPM_INPUT(wname) \
  44. { .id = snd_soc_dapm_input, .name = wname, .kcontrol_news = NULL, \
  45. .num_kcontrols = 0, .reg = SND_SOC_NOPM }
  46. #define SND_SOC_DAPM_OUTPUT(wname) \
  47. { .id = snd_soc_dapm_output, .name = wname, .kcontrol_news = NULL, \
  48. .num_kcontrols = 0, .reg = SND_SOC_NOPM }
  49. #define SND_SOC_DAPM_MIC(wname, wevent) \
  50. { .id = snd_soc_dapm_mic, .name = wname, .kcontrol_news = NULL, \
  51. .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
  52. .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD}
  53. #define SND_SOC_DAPM_HP(wname, wevent) \
  54. { .id = snd_soc_dapm_hp, .name = wname, .kcontrol_news = NULL, \
  55. .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
  56. .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
  57. #define SND_SOC_DAPM_SPK(wname, wevent) \
  58. { .id = snd_soc_dapm_spk, .name = wname, .kcontrol_news = NULL, \
  59. .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
  60. .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
  61. #define SND_SOC_DAPM_LINE(wname, wevent) \
  62. { .id = snd_soc_dapm_line, .name = wname, .kcontrol_news = NULL, \
  63. .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
  64. .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
  65. #define SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert) \
  66. .reg = wreg, .mask = 1, .shift = wshift, \
  67. .on_val = winvert ? 0 : 1, .off_val = winvert ? 1 : 0
  68. /* path domain */
  69. #define SND_SOC_DAPM_PGA(wname, wreg, wshift, winvert,\
  70. wcontrols, wncontrols) \
  71. { .id = snd_soc_dapm_pga, .name = wname, \
  72. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  73. .kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
  74. #define SND_SOC_DAPM_OUT_DRV(wname, wreg, wshift, winvert,\
  75. wcontrols, wncontrols) \
  76. { .id = snd_soc_dapm_out_drv, .name = wname, \
  77. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  78. .kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
  79. #define SND_SOC_DAPM_MIXER(wname, wreg, wshift, winvert, \
  80. wcontrols, wncontrols)\
  81. { .id = snd_soc_dapm_mixer, .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_NAMED_CTL(wname, wreg, wshift, winvert, \
  85. wcontrols, wncontrols)\
  86. { .id = snd_soc_dapm_mixer_named_ctl, .name = wname, \
  87. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  88. .kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
  89. #define SND_SOC_DAPM_MICBIAS(wname, wreg, wshift, winvert) \
  90. { .id = snd_soc_dapm_micbias, .name = wname, \
  91. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  92. .kcontrol_news = NULL, .num_kcontrols = 0}
  93. #define SND_SOC_DAPM_SWITCH(wname, wreg, wshift, winvert, wcontrols) \
  94. { .id = snd_soc_dapm_switch, .name = wname, \
  95. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  96. .kcontrol_news = wcontrols, .num_kcontrols = 1}
  97. #define SND_SOC_DAPM_MUX(wname, wreg, wshift, winvert, wcontrols) \
  98. { .id = snd_soc_dapm_mux, .name = wname, .reg = wreg, \
  99. .kcontrol_news = wcontrols, .num_kcontrols = 1}
  100. #define SND_SOC_DAPM_VIRT_MUX(wname, wreg, wshift, winvert, wcontrols) \
  101. { .id = snd_soc_dapm_virt_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_VALUE_MUX(wname, wreg, wshift, winvert, wcontrols) \
  105. { .id = snd_soc_dapm_value_mux, .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. #define SND_SOC_DAPM_VIRT_MUX_E(wname, wreg, wshift, winvert, wcontrols, \
  162. wevent, wflags) \
  163. { .id = snd_soc_dapm_virt_mux, .name = wname, \
  164. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  165. .kcontrol_news = wcontrols, .num_kcontrols = 1, \
  166. .event = wevent, .event_flags = wflags}
  167. /* additional sequencing control within an event type */
  168. #define SND_SOC_DAPM_PGA_S(wname, wsubseq, wreg, wshift, winvert, \
  169. wevent, wflags) \
  170. { .id = snd_soc_dapm_pga, .name = wname, \
  171. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  172. .event = wevent, .event_flags = wflags, \
  173. .subseq = wsubseq}
  174. #define SND_SOC_DAPM_SUPPLY_S(wname, wsubseq, wreg, wshift, winvert, wevent, \
  175. wflags) \
  176. { .id = snd_soc_dapm_supply, .name = wname, \
  177. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  178. .event = wevent, .event_flags = wflags, .subseq = wsubseq}
  179. /* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */
  180. #define SOC_PGA_E_ARRAY(wname, wreg, wshift, winvert, wcontrols, \
  181. wevent, wflags) \
  182. { .id = snd_soc_dapm_pga, .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_E_ARRAY(wname, wreg, wshift, winvert, wcontrols, \
  187. 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. #define SOC_MIXER_NAMED_CTL_E_ARRAY(wname, wreg, wshift, winvert, \
  193. wcontrols, wevent, wflags) \
  194. { .id = snd_soc_dapm_mixer, .name = wname, \
  195. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  196. .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols), \
  197. .event = wevent, .event_flags = wflags}
  198. /* events that are pre and post DAPM */
  199. #define SND_SOC_DAPM_PRE(wname, wevent) \
  200. { .id = snd_soc_dapm_pre, .name = wname, .kcontrol_news = NULL, \
  201. .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
  202. .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD}
  203. #define SND_SOC_DAPM_POST(wname, wevent) \
  204. { .id = snd_soc_dapm_post, .name = wname, .kcontrol_news = NULL, \
  205. .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
  206. .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD}
  207. /* stream domain */
  208. #define SND_SOC_DAPM_AIF_IN(wname, stname, wslot, wreg, wshift, winvert) \
  209. { .id = snd_soc_dapm_aif_in, .name = wname, .sname = stname, \
  210. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), }
  211. #define SND_SOC_DAPM_AIF_IN_E(wname, stname, wslot, wreg, wshift, winvert, \
  212. wevent, wflags) \
  213. { .id = snd_soc_dapm_aif_in, .name = wname, .sname = stname, \
  214. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  215. .event = wevent, .event_flags = wflags }
  216. #define SND_SOC_DAPM_AIF_OUT(wname, stname, wslot, wreg, wshift, winvert) \
  217. { .id = snd_soc_dapm_aif_out, .name = wname, .sname = stname, \
  218. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), }
  219. #define SND_SOC_DAPM_AIF_OUT_E(wname, stname, wslot, wreg, wshift, winvert, \
  220. wevent, wflags) \
  221. { .id = snd_soc_dapm_aif_out, .name = wname, .sname = stname, \
  222. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  223. .event = wevent, .event_flags = wflags }
  224. #define SND_SOC_DAPM_DAC(wname, stname, wreg, wshift, winvert) \
  225. { .id = snd_soc_dapm_dac, .name = wname, .sname = stname, \
  226. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert) }
  227. #define SND_SOC_DAPM_DAC_E(wname, stname, wreg, wshift, winvert, \
  228. wevent, wflags) \
  229. { .id = snd_soc_dapm_dac, .name = wname, .sname = stname, \
  230. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  231. .event = wevent, .event_flags = wflags}
  232. #define SND_SOC_DAPM_ADC(wname, stname, wreg, wshift, winvert) \
  233. { .id = snd_soc_dapm_adc, .name = wname, .sname = stname, \
  234. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), }
  235. #define SND_SOC_DAPM_ADC_E(wname, stname, wreg, wshift, winvert, \
  236. wevent, wflags) \
  237. { .id = snd_soc_dapm_adc, .name = wname, .sname = stname, \
  238. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  239. .event = wevent, .event_flags = wflags}
  240. #define SND_SOC_DAPM_CLOCK_SUPPLY(wname) \
  241. { .id = snd_soc_dapm_clock_supply, .name = wname, \
  242. .reg = SND_SOC_NOPM, .event = dapm_clock_event, \
  243. .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD }
  244. /* generic widgets */
  245. #define SND_SOC_DAPM_REG(wid, wname, wreg, wshift, wmask, won_val, woff_val) \
  246. { .id = wid, .name = wname, .kcontrol_news = NULL, .num_kcontrols = 0, \
  247. .reg = -((wreg) + 1), .shift = wshift, .mask = wmask, \
  248. .on_val = won_val, .off_val = woff_val, .event = dapm_reg_event, \
  249. .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD}
  250. #define SND_SOC_DAPM_SUPPLY(wname, wreg, wshift, winvert, wevent, wflags) \
  251. { .id = snd_soc_dapm_supply, .name = wname, \
  252. SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
  253. .event = wevent, .event_flags = wflags}
  254. #define SND_SOC_DAPM_REGULATOR_SUPPLY(wname, wdelay, wflags) \
  255. { .id = snd_soc_dapm_regulator_supply, .name = wname, \
  256. .reg = SND_SOC_NOPM, .shift = wdelay, .event = dapm_regulator_event, \
  257. .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD, \
  258. .on_val = wflags}
  259. /* dapm kcontrol types */
  260. #define SOC_DAPM_SINGLE(xname, reg, shift, max, invert) \
  261. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  262. .info = snd_soc_info_volsw, \
  263. .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
  264. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  265. #define SOC_DAPM_SINGLE_AUTODISABLE(xname, reg, shift, max, invert) \
  266. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  267. .info = snd_soc_info_volsw, \
  268. .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
  269. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 1) }
  270. #define SOC_DAPM_SINGLE_VIRT(xname, max) \
  271. SOC_DAPM_SINGLE(xname, SND_SOC_NOPM, 0, max, 0)
  272. #define SOC_DAPM_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
  273. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  274. .info = snd_soc_info_volsw, \
  275. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  276. .tlv.p = (tlv_array), \
  277. .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
  278. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  279. #define SOC_DAPM_SINGLE_TLV_AUTODISABLE(xname, reg, shift, max, invert, tlv_array) \
  280. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  281. .info = snd_soc_info_volsw, \
  282. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  283. .tlv.p = (tlv_array), \
  284. .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
  285. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
  286. #define SOC_DAPM_SINGLE_TLV_VIRT(xname, max, tlv_array) \
  287. SOC_DAPM_SINGLE(xname, SND_SOC_NOPM, 0, max, 0, tlv_array)
  288. #define SOC_DAPM_ENUM(xname, xenum) \
  289. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  290. .info = snd_soc_info_enum_double, \
  291. .get = snd_soc_dapm_get_enum_double, \
  292. .put = snd_soc_dapm_put_enum_double, \
  293. .private_value = (unsigned long)&xenum }
  294. #define SOC_DAPM_ENUM_VIRT(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_virt, \
  298. .put = snd_soc_dapm_put_enum_virt, \
  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_VALUE_ENUM(xname, xenum) \
  307. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  308. .info = snd_soc_info_enum_double, \
  309. .get = snd_soc_dapm_get_value_enum_double, \
  310. .put = snd_soc_dapm_put_value_enum_double, \
  311. .private_value = (unsigned long)&xenum }
  312. #define SOC_DAPM_PIN_SWITCH(xname) \
  313. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname " Switch", \
  314. .info = snd_soc_dapm_info_pin_switch, \
  315. .get = snd_soc_dapm_get_pin_switch, \
  316. .put = snd_soc_dapm_put_pin_switch, \
  317. .private_value = (unsigned long)xname }
  318. /* dapm stream operations */
  319. #define SND_SOC_DAPM_STREAM_NOP 0x0
  320. #define SND_SOC_DAPM_STREAM_START 0x1
  321. #define SND_SOC_DAPM_STREAM_STOP 0x2
  322. #define SND_SOC_DAPM_STREAM_SUSPEND 0x4
  323. #define SND_SOC_DAPM_STREAM_RESUME 0x8
  324. #define SND_SOC_DAPM_STREAM_PAUSE_PUSH 0x10
  325. #define SND_SOC_DAPM_STREAM_PAUSE_RELEASE 0x20
  326. /* dapm event types */
  327. #define SND_SOC_DAPM_PRE_PMU 0x1 /* before widget power up */
  328. #define SND_SOC_DAPM_POST_PMU 0x2 /* after widget power up */
  329. #define SND_SOC_DAPM_PRE_PMD 0x4 /* before widget power down */
  330. #define SND_SOC_DAPM_POST_PMD 0x8 /* after widget power down */
  331. #define SND_SOC_DAPM_PRE_REG 0x10 /* before audio path setup */
  332. #define SND_SOC_DAPM_POST_REG 0x20 /* after audio path setup */
  333. #define SND_SOC_DAPM_WILL_PMU 0x40 /* called at start of sequence */
  334. #define SND_SOC_DAPM_WILL_PMD 0x80 /* called at start of sequence */
  335. #define SND_SOC_DAPM_PRE_POST_PMD \
  336. (SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD)
  337. /* convenience event type detection */
  338. #define SND_SOC_DAPM_EVENT_ON(e) \
  339. (e & (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU))
  340. #define SND_SOC_DAPM_EVENT_OFF(e) \
  341. (e & (SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD))
  342. /* regulator widget flags */
  343. #define SND_SOC_DAPM_REGULATOR_BYPASS 0x1 /* bypass when disabled */
  344. struct snd_soc_dapm_widget;
  345. enum snd_soc_dapm_type;
  346. struct snd_soc_dapm_path;
  347. struct snd_soc_dapm_pin;
  348. struct snd_soc_dapm_route;
  349. struct snd_soc_dapm_context;
  350. struct regulator;
  351. struct snd_soc_dapm_widget_list;
  352. struct snd_soc_dapm_update;
  353. int dapm_reg_event(struct snd_soc_dapm_widget *w,
  354. struct snd_kcontrol *kcontrol, int event);
  355. int dapm_regulator_event(struct snd_soc_dapm_widget *w,
  356. struct snd_kcontrol *kcontrol, int event);
  357. int dapm_clock_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_get_enum_virt(struct snd_kcontrol *kcontrol,
  369. struct snd_ctl_elem_value *ucontrol);
  370. int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
  371. struct snd_ctl_elem_value *ucontrol);
  372. int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
  373. struct snd_ctl_elem_value *ucontrol);
  374. int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
  375. struct snd_ctl_elem_value *ucontrol);
  376. int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
  377. struct snd_ctl_elem_info *uinfo);
  378. int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
  379. struct snd_ctl_elem_value *uncontrol);
  380. int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
  381. struct snd_ctl_elem_value *uncontrol);
  382. int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
  383. const struct snd_soc_dapm_widget *widget,
  384. int num);
  385. int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
  386. struct snd_soc_dai *dai);
  387. int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card);
  388. int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
  389. const struct snd_soc_pcm_stream *params,
  390. struct snd_soc_dapm_widget *source,
  391. struct snd_soc_dapm_widget *sink);
  392. /* dapm path setup */
  393. int snd_soc_dapm_new_widgets(struct snd_soc_card *card);
  394. void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm);
  395. int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
  396. const struct snd_soc_dapm_route *route, int num);
  397. int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm,
  398. const struct snd_soc_dapm_route *route, int num);
  399. int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
  400. const struct snd_soc_dapm_route *route, int num);
  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. int snd_soc_dapm_sys_add(struct device *dev);
  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_disable_pin(struct snd_soc_dapm_context *dapm,
  420. const char *pin);
  421. int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, 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_force_enable_pin(struct snd_soc_dapm_context *dapm,
  426. const char *pin);
  427. int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
  428. const char *pin);
  429. void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec);
  430. /* Mostly internal - should not normally be used */
  431. void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason);
  432. void dapm_mark_io_dirty(struct snd_soc_dapm_context *dapm);
  433. /* dapm path query */
  434. int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
  435. struct snd_soc_dapm_widget_list **list);
  436. struct snd_soc_codec *snd_soc_dapm_kcontrol_codec(struct snd_kcontrol *kcontrol);
  437. /* dapm widget types */
  438. enum snd_soc_dapm_type {
  439. snd_soc_dapm_input = 0, /* input pin */
  440. snd_soc_dapm_output, /* output pin */
  441. snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */
  442. snd_soc_dapm_virt_mux, /* virtual version of snd_soc_dapm_mux */
  443. snd_soc_dapm_value_mux, /* selects 1 analog signal from many inputs */
  444. snd_soc_dapm_mixer, /* mixes several analog signals together */
  445. snd_soc_dapm_mixer_named_ctl, /* mixer with named controls */
  446. snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */
  447. snd_soc_dapm_out_drv, /* output driver */
  448. snd_soc_dapm_adc, /* analog to digital converter */
  449. snd_soc_dapm_dac, /* digital to analog converter */
  450. snd_soc_dapm_micbias, /* microphone bias (power) */
  451. snd_soc_dapm_mic, /* microphone */
  452. snd_soc_dapm_hp, /* headphones */
  453. snd_soc_dapm_spk, /* speaker */
  454. snd_soc_dapm_line, /* line input/output */
  455. snd_soc_dapm_switch, /* analog switch */
  456. snd_soc_dapm_vmid, /* codec bias/vmid - to minimise pops */
  457. snd_soc_dapm_pre, /* machine specific pre widget - exec first */
  458. snd_soc_dapm_post, /* machine specific post widget - exec last */
  459. snd_soc_dapm_supply, /* power/clock supply */
  460. snd_soc_dapm_regulator_supply, /* external regulator */
  461. snd_soc_dapm_clock_supply, /* external clock */
  462. snd_soc_dapm_aif_in, /* audio interface input */
  463. snd_soc_dapm_aif_out, /* audio interface output */
  464. snd_soc_dapm_siggen, /* signal generator */
  465. snd_soc_dapm_dai_in, /* link to DAI structure */
  466. snd_soc_dapm_dai_out,
  467. snd_soc_dapm_dai_link, /* link between two DAI structures */
  468. snd_soc_dapm_kcontrol, /* Auto-disabled kcontrol */
  469. };
  470. enum snd_soc_dapm_subclass {
  471. SND_SOC_DAPM_CLASS_INIT = 0,
  472. SND_SOC_DAPM_CLASS_RUNTIME = 1,
  473. };
  474. /*
  475. * DAPM audio route definition.
  476. *
  477. * Defines an audio route originating at source via control and finishing
  478. * at sink.
  479. */
  480. struct snd_soc_dapm_route {
  481. const char *sink;
  482. const char *control;
  483. const char *source;
  484. /* Note: currently only supported for links where source is a supply */
  485. int (*connected)(struct snd_soc_dapm_widget *source,
  486. struct snd_soc_dapm_widget *sink);
  487. };
  488. /* dapm audio path between two widgets */
  489. struct snd_soc_dapm_path {
  490. const char *name;
  491. /* source (input) and sink (output) widgets */
  492. struct snd_soc_dapm_widget *source;
  493. struct snd_soc_dapm_widget *sink;
  494. /* status */
  495. u32 connect:1; /* source and sink widgets are connected */
  496. u32 walked:1; /* path has been walked */
  497. u32 walking:1; /* path is in the process of being walked */
  498. u32 weak:1; /* path ignored for power management */
  499. int (*connected)(struct snd_soc_dapm_widget *source,
  500. struct snd_soc_dapm_widget *sink);
  501. struct list_head list_source;
  502. struct list_head list_sink;
  503. struct list_head list_kcontrol;
  504. struct list_head list;
  505. };
  506. /* dapm widget */
  507. struct snd_soc_dapm_widget {
  508. enum snd_soc_dapm_type id;
  509. const char *name; /* widget name */
  510. const char *sname; /* stream name */
  511. struct snd_soc_codec *codec;
  512. struct snd_soc_platform *platform;
  513. struct list_head list;
  514. struct snd_soc_dapm_context *dapm;
  515. void *priv; /* widget specific data */
  516. struct regulator *regulator; /* attached regulator */
  517. const struct snd_soc_pcm_stream *params; /* params for dai links */
  518. /* dapm control */
  519. int reg; /* negative reg = no direct dapm */
  520. unsigned char shift; /* bits to shift */
  521. unsigned int mask; /* non-shifted mask */
  522. unsigned int on_val; /* on state value */
  523. unsigned int off_val; /* off state value */
  524. unsigned char power:1; /* block power status */
  525. unsigned char active:1; /* active stream on DAC, ADC's */
  526. unsigned char connected:1; /* connected codec pin */
  527. unsigned char new:1; /* cnew complete */
  528. unsigned char ext:1; /* has external widgets */
  529. unsigned char force:1; /* force state */
  530. unsigned char ignore_suspend:1; /* kept enabled over suspend */
  531. unsigned char new_power:1; /* power from this run */
  532. unsigned char power_checked:1; /* power checked this run */
  533. int subseq; /* sort within widget type */
  534. int (*power_check)(struct snd_soc_dapm_widget *w);
  535. /* external events */
  536. unsigned short event_flags; /* flags to specify event types */
  537. int (*event)(struct snd_soc_dapm_widget*, struct snd_kcontrol *, int);
  538. /* kcontrols that relate to this widget */
  539. int num_kcontrols;
  540. const struct snd_kcontrol_new *kcontrol_news;
  541. struct snd_kcontrol **kcontrols;
  542. /* widget input and outputs */
  543. struct list_head sources;
  544. struct list_head sinks;
  545. /* used during DAPM updates */
  546. struct list_head power_list;
  547. struct list_head dirty;
  548. int inputs;
  549. int outputs;
  550. struct clk *clk;
  551. };
  552. struct snd_soc_dapm_update {
  553. struct snd_kcontrol *kcontrol;
  554. int reg;
  555. int mask;
  556. int val;
  557. };
  558. /* DAPM context */
  559. struct snd_soc_dapm_context {
  560. enum snd_soc_bias_level bias_level;
  561. enum snd_soc_bias_level suspend_bias_level;
  562. struct delayed_work delayed_work;
  563. unsigned int idle_bias_off:1; /* Use BIAS_OFF instead of STANDBY */
  564. void (*seq_notifier)(struct snd_soc_dapm_context *,
  565. enum snd_soc_dapm_type, int);
  566. struct device *dev; /* from parent - for debug */
  567. struct snd_soc_codec *codec; /* parent codec */
  568. struct snd_soc_platform *platform; /* parent platform */
  569. struct snd_soc_card *card; /* parent card */
  570. /* used during DAPM updates */
  571. enum snd_soc_bias_level target_bias_level;
  572. struct list_head list;
  573. int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
  574. #ifdef CONFIG_DEBUG_FS
  575. struct dentry *debugfs_dapm;
  576. #endif
  577. };
  578. /* A list of widgets associated with an object, typically a snd_kcontrol */
  579. struct snd_soc_dapm_widget_list {
  580. int num_widgets;
  581. struct snd_soc_dapm_widget *widgets[0];
  582. };
  583. struct snd_soc_dapm_stats {
  584. int power_checks;
  585. int path_checks;
  586. int neighbour_checks;
  587. };
  588. #endif