blob: abc892dc753381e08e838b70e76932af48e2b2b3 [file] [log] [blame]
Liam Girdwood80a4c0a2011-12-12 20:30:48 +08001/*
2 * linux/sound/soc-dsp.h -- ALSA SoC DSP
3 *
4 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef __LINUX_SND_SOC_DSP_H
12#define __LINUX_SND_SOC_DSP_H
13
14#include <sound/pcm.h>
15
16struct snd_soc_dapm_widget;
17
18/*
19 * Types of runtime_update to perform (e.g. originated from FE PCM ops
20 * or audio route changes triggered by muxes/mixers.
21 */
22#define SND_SOC_DSP_UPDATE_NO 0
23#define SND_SOC_DSP_UPDATE_BE 1
24#define SND_SOC_DSP_UPDATE_FE 2
25
26/*
27 * DSP trigger ordering. Triggering flexibility is required as some DSPs
28 * require triggering before/after their clients/hosts.
29 *
30 * i.e. some clients may want to manually order this call in their PCM
31 * trigger() whilst others will just use the regular core ordering.
32 */
33enum snd_soc_dsp_trigger {
34 SND_SOC_DSP_TRIGGER_PRE = 0,
35 SND_SOC_DSP_TRIGGER_POST,
36 SND_SOC_DSP_TRIGGER_BESPOKE,
37};
38
39/*
40 * The DSP Frontend -> Backend link state.
41 */
42enum snd_soc_dsp_link_state {
43 SND_SOC_DSP_LINK_STATE_NEW = 0, /* newly created path */
44 SND_SOC_DSP_LINK_STATE_FREE, /* path to be dismantled */
45};
46
47struct snd_soc_dsp_params {
48 struct snd_soc_pcm_runtime *be;
49 struct snd_soc_pcm_runtime *fe;
50 enum snd_soc_dsp_link_state state;
51 struct list_head list_be;
52 struct list_head list_fe;
53 struct snd_pcm_hw_params hw_params;
54#ifdef CONFIG_DEBUG_FS
55 struct dentry *debugfs_state;
56#endif
57};
58
59struct snd_soc_dsp_link {
60 bool capture;
61 bool playback;
62 enum snd_soc_dsp_trigger trigger[2];
63};
64
65/* FE DSP PCM ops - called by soc-core */
66int soc_dsp_fe_dai_open(struct snd_pcm_substream *substream);
67int soc_dsp_fe_dai_close(struct snd_pcm_substream *substream);
68int soc_dsp_fe_dai_prepare(struct snd_pcm_substream *substream);
69int soc_dsp_fe_dai_hw_free(struct snd_pcm_substream *substream);
70int soc_dsp_fe_dai_trigger(struct snd_pcm_substream *substream, int cmd);
71int soc_dsp_fe_dai_hw_params(struct snd_pcm_substream *substream,
72 struct snd_pcm_hw_params *params);
73
74/* Backend DSP trigger.
75 * Can be called by core or components depending on trigger config.
76 */
77int soc_dsp_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, int cmd);
78
79/* Is this trigger() call required for this FE and stream */
80static inline int snd_soc_dsp_is_trigger_for_fe(struct snd_soc_pcm_runtime *fe,
81 int stream)
82{
83 return (fe->dsp[stream].runtime_update == SND_SOC_DSP_UPDATE_FE);
84}
85
86static inline int snd_soc_dsp_is_op_for_be(struct snd_soc_pcm_runtime *fe,
87 struct snd_soc_pcm_runtime *be, int stream)
88{
89 if ((fe->dsp[stream].runtime_update == SND_SOC_DSP_UPDATE_FE) ||
90 ((fe->dsp[stream].runtime_update == SND_SOC_DSP_UPDATE_BE) &&
91 be->dsp[stream].runtime_update))
92 return 1;
93 else
94 return 0;
95}
96
97static inline int snd_soc_dsp_platform_trigger(struct snd_pcm_substream *substream,
98 int cmd, struct snd_soc_platform *platform)
99{
100 if (platform->driver->ops->trigger)
101 return platform->driver->ops->trigger(substream, cmd);
102 return 0;
103}
104int soc_dsp_fe_state_count(struct snd_soc_pcm_runtime *be, int stream,
105 enum snd_soc_dsp_state state);
106
107/* Runtime update - open/close Backend DSP paths depending on mixer updates */
108int soc_dsp_runtime_update(struct snd_soc_dapm_widget *widget);
109
110/* Backend DSP suspend and resume */
111int soc_dsp_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute);
112int soc_dsp_fe_suspend(struct snd_soc_pcm_runtime *fe);
113int soc_dsp_be_ac97_cpu_dai_suspend(struct snd_soc_pcm_runtime *fe);
114int soc_dsp_fe_resume(struct snd_soc_pcm_runtime *fe);
115int soc_dsp_be_ac97_cpu_dai_resume(struct snd_soc_pcm_runtime *fe);
116int soc_dsp_be_platform_resume(struct snd_soc_pcm_runtime *fe);
117int soc_dsp_be_cpu_dai_resume(struct snd_soc_pcm_runtime *fe);
118int soc_dsp_be_cpu_dai_suspend(struct snd_soc_pcm_runtime *fe);
119int soc_dsp_be_platform_suspend(struct snd_soc_pcm_runtime *fe);
120
121/* DAPM stream events for Backend DSP paths */
122int soc_dsp_dapm_stream_event(struct snd_soc_pcm_runtime *fe,
123 int dir, const char *stream, int event);
124
125static inline struct snd_pcm_substream *snd_soc_dsp_get_substream(
126 struct snd_soc_pcm_runtime *be, int stream)
127{
128 return be->pcm->streams[stream].substream;
129}
130
131#endif