blob: 22b5b86e41468fd4cd90e03cfdc8e0e555965429 [file] [log] [blame]
Liam Girdwood01d75842012-04-25 12:12:49 +01001/*
2 * linux/sound/soc-dpcm.h -- ALSA SoC Dynamic PCM Support
3 *
4 * Author: Liam Girdwood <lrg@ti.com>
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_DPCM_H
12#define __LINUX_SND_SOC_DPCM_H
13
Liam Girdwood23607022014-01-17 17:03:55 +000014#include <linux/slab.h>
Liam Girdwood01d75842012-04-25 12:12:49 +010015#include <linux/list.h>
16#include <sound/pcm.h>
17
18struct snd_soc_pcm_runtime;
19
Banajit Goswami8886fb02016-11-21 21:39:54 -080020#define DPCM_MAX_BE_USERS 8
Liam Girdwood01d75842012-04-25 12:12:49 +010021/*
22 * Types of runtime_update to perform. e.g. originated from FE PCM ops
23 * or audio route changes triggered by muxes/mixers.
24 */
25enum snd_soc_dpcm_update {
26 SND_SOC_DPCM_UPDATE_NO = 0,
27 SND_SOC_DPCM_UPDATE_BE,
28 SND_SOC_DPCM_UPDATE_FE,
29};
30
31/*
32 * Dynamic PCM Frontend -> Backend link management states.
33 */
34enum snd_soc_dpcm_link_state {
35 SND_SOC_DPCM_LINK_STATE_NEW = 0, /* newly created link */
36 SND_SOC_DPCM_LINK_STATE_FREE, /* link to be dismantled */
37};
38
39/*
40 * Dynamic PCM Frontend -> Backend link PCM states.
41 */
42enum snd_soc_dpcm_state {
43 SND_SOC_DPCM_STATE_NEW = 0,
44 SND_SOC_DPCM_STATE_OPEN,
45 SND_SOC_DPCM_STATE_HW_PARAMS,
46 SND_SOC_DPCM_STATE_PREPARE,
47 SND_SOC_DPCM_STATE_START,
48 SND_SOC_DPCM_STATE_STOP,
49 SND_SOC_DPCM_STATE_PAUSED,
50 SND_SOC_DPCM_STATE_SUSPEND,
51 SND_SOC_DPCM_STATE_HW_FREE,
52 SND_SOC_DPCM_STATE_CLOSE,
53};
54
55/*
56 * Dynamic PCM trigger ordering. Triggering flexibility is required as some
57 * DSPs require triggering before/after their CPU platform and DAIs.
58 *
59 * i.e. some clients may want to manually order this call in their PCM
60 * trigger() whilst others will just use the regular core ordering.
61 */
62enum snd_soc_dpcm_trigger {
63 SND_SOC_DPCM_TRIGGER_PRE = 0,
64 SND_SOC_DPCM_TRIGGER_POST,
Liam Girdwood07bf84a2012-04-25 12:12:52 +010065 SND_SOC_DPCM_TRIGGER_BESPOKE,
Liam Girdwood01d75842012-04-25 12:12:49 +010066};
67
68/*
69 * Dynamic PCM link
70 * This links together a FE and BE DAI at runtime and stores the link
71 * state information and the hw_params configuration.
72 */
73struct snd_soc_dpcm {
74 /* FE and BE DAIs*/
75 struct snd_soc_pcm_runtime *be;
76 struct snd_soc_pcm_runtime *fe;
77
78 /* link state */
79 enum snd_soc_dpcm_link_state state;
80
81 /* list of BE and FE for this DPCM link */
82 struct list_head list_be;
83 struct list_head list_fe;
84
85 /* hw params for this link - may be different for each link */
86 struct snd_pcm_hw_params hw_params;
Liam Girdwoodf86dcef2012-04-25 12:12:50 +010087#ifdef CONFIG_DEBUG_FS
88 struct dentry *debugfs_state;
89#endif
Banajit Goswami8886fb02016-11-21 21:39:54 -080090 int stream;
Liam Girdwood01d75842012-04-25 12:12:49 +010091};
92
93/*
94 * Dynamic PCM runtime data.
95 */
96struct snd_soc_dpcm_runtime {
97 struct list_head be_clients;
98 struct list_head fe_clients;
99
100 int users;
101 struct snd_pcm_runtime *runtime;
102 struct snd_pcm_hw_params hw_params;
103
104 /* state and update */
105 enum snd_soc_dpcm_update runtime_update;
106 enum snd_soc_dpcm_state state;
Takashi Iwaiea9d0d72014-11-04 16:52:28 +0100107
108 int trigger_pending; /* trigger cmd + 1 if pending, 0 if not */
Liam Girdwood01d75842012-04-25 12:12:49 +0100109};
110
111/* can this BE stop and free */
112int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
113 struct snd_soc_pcm_runtime *be, int stream);
114
115/* can this BE perform a hw_params() */
116int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
117 struct snd_soc_pcm_runtime *be, int stream);
118
119/* is the current PCM operation for this FE ? */
120int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream);
121
122/* is the current PCM operation for this BE ? */
123int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe,
124 struct snd_soc_pcm_runtime *be, int stream);
125
126/* get the substream for this BE */
127struct snd_pcm_substream *
128 snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream);
129
130/* get the BE runtime state */
131enum snd_soc_dpcm_state
132 snd_soc_dpcm_be_get_state(struct snd_soc_pcm_runtime *be, int stream);
133
134/* set the BE runtime state */
135void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime *be, int stream,
136 enum snd_soc_dpcm_state state);
137
138/* internal use only */
139int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute);
Lars-Peter Clausen2e55b902015-04-09 10:52:37 +0200140void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd);
Lars-Peter Clausenc3f48ae2013-07-24 15:27:36 +0200141int soc_dpcm_runtime_update(struct snd_soc_card *);
Liam Girdwood01d75842012-04-25 12:12:49 +0100142
Liam Girdwood23607022014-01-17 17:03:55 +0000143int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
144 int stream, struct snd_soc_dapm_widget_list **list_);
145int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
146 int stream, struct snd_soc_dapm_widget_list **list, int new);
147int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream);
148int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream);
149void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream);
150void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream);
151int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream);
152int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int tream);
Banajit Goswami8886fb02016-11-21 21:39:54 -0800153int dpcm_fe_dai_hw_params_be(struct snd_soc_pcm_runtime *fe,
154 struct snd_soc_pcm_runtime *be, struct snd_pcm_hw_params *hw_params,
155 int stream);
Liam Girdwood23607022014-01-17 17:03:55 +0000156int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, int cmd);
157int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream);
Banajit Goswami8886fb02016-11-21 21:39:54 -0800158int dpcm_fe_dai_prepare_be(struct snd_soc_pcm_runtime *fe,
159 struct snd_soc_pcm_runtime *be, int stream);
Liam Girdwood23607022014-01-17 17:03:55 +0000160int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
161 int event);
162
163static inline void dpcm_path_put(struct snd_soc_dapm_widget_list **list)
164{
165 kfree(*list);
166}
167
168
Liam Girdwood01d75842012-04-25 12:12:49 +0100169#endif