aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/sound/ac97_codec.h1
-rw-r--r--include/sound/soc-dapm.h286
-rw-r--r--include/sound/soc.h480
3 files changed, 767 insertions, 0 deletions
diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
index 33720397a904..5f7c78d9e379 100644
--- a/include/sound/ac97_codec.h
+++ b/include/sound/ac97_codec.h
@@ -425,6 +425,7 @@ struct snd_ac97_build_ops {
425 425
426struct snd_ac97_bus_ops { 426struct snd_ac97_bus_ops {
427 void (*reset) (struct snd_ac97 *ac97); 427 void (*reset) (struct snd_ac97 *ac97);
428 void (*warm_reset)(struct snd_ac97 *ac97);
428 void (*write) (struct snd_ac97 *ac97, unsigned short reg, unsigned short val); 429 void (*write) (struct snd_ac97 *ac97, unsigned short reg, unsigned short val);
429 unsigned short (*read) (struct snd_ac97 *ac97, unsigned short reg); 430 unsigned short (*read) (struct snd_ac97 *ac97, unsigned short reg);
430 void (*wait) (struct snd_ac97 *ac97); 431 void (*wait) (struct snd_ac97 *ac97);
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
new file mode 100644
index 000000000000..2b1ae8edc43c
--- /dev/null
+++ b/include/sound/soc-dapm.h
@@ -0,0 +1,286 @@
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
13#ifndef __LINUX_SND_SOC_DAPM_H
14#define __LINUX_SND_SOC_DAPM_H
15
16#include <linux/device.h>
17#include <linux/types.h>
18#include <sound/control.h>
19#include <sound/soc.h>
20
21/* widget has no PM register bit */
22#define SND_SOC_NOPM -1
23
24/*
25 * SoC dynamic audio power managment
26 *
27 * We can have upto 4 power domains
28 * 1. Codec domain - VREF, VMID
29 * Usually controlled at codec probe/remove, although can be set
30 * at stream time if power is not needed for sidetone, etc.
31 * 2. Platform/Machine domain - physically connected inputs and outputs
32 * Is platform/machine and user action specific, is set in the machine
33 * driver and by userspace e.g when HP are inserted
34 * 3. Path domain - Internal codec path mixers
35 * Are automatically set when mixer and mux settings are
36 * changed by the user.
37 * 4. Stream domain - DAC's and ADC's.
38 * Enabled when stream playback/capture is started.
39 */
40
41/* codec domain */
42#define SND_SOC_DAPM_VMID(wname) \
43{ .id = snd_soc_dapm_vmid, .name = wname, .kcontrols = NULL, \
44 .num_kcontrols = 0}
45
46/* platform domain */
47#define SND_SOC_DAPM_INPUT(wname) \
48{ .id = snd_soc_dapm_input, .name = wname, .kcontrols = NULL, \
49 .num_kcontrols = 0}
50#define SND_SOC_DAPM_OUTPUT(wname) \
51{ .id = snd_soc_dapm_output, .name = wname, .kcontrols = NULL, \
52 .num_kcontrols = 0}
53#define SND_SOC_DAPM_MIC(wname, wevent) \
54{ .id = snd_soc_dapm_mic, .name = wname, .kcontrols = NULL, \
55 .num_kcontrols = 0, .event = wevent, \
56 .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD}
57#define SND_SOC_DAPM_HP(wname, wevent) \
58{ .id = snd_soc_dapm_hp, .name = wname, .kcontrols = NULL, \
59 .num_kcontrols = 0, .event = wevent, \
60 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
61#define SND_SOC_DAPM_SPK(wname, wevent) \
62{ .id = snd_soc_dapm_spk, .name = wname, .kcontrols = NULL, \
63 .num_kcontrols = 0, .event = wevent, \
64 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
65#define SND_SOC_DAPM_LINE(wname, wevent) \
66{ .id = snd_soc_dapm_line, .name = wname, .kcontrols = NULL, \
67 .num_kcontrols = 0, .event = wevent, \
68 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
69
70/* path domain */
71#define SND_SOC_DAPM_PGA(wname, wreg, wshift, winvert,\
72 wcontrols, wncontrols) \
73{ .id = snd_soc_dapm_pga, .name = wname, .reg = wreg, .shift = wshift, \
74 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols}
75#define SND_SOC_DAPM_MIXER(wname, wreg, wshift, winvert, \
76 wcontrols, wncontrols)\
77{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \
78 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols}
79#define SND_SOC_DAPM_MICBIAS(wname, wreg, wshift, winvert) \
80{ .id = snd_soc_dapm_micbias, .name = wname, .reg = wreg, .shift = wshift, \
81 .invert = winvert, .kcontrols = NULL, .num_kcontrols = 0}
82#define SND_SOC_DAPM_SWITCH(wname, wreg, wshift, winvert, wcontrols) \
83{ .id = snd_soc_dapm_switch, .name = wname, .reg = wreg, .shift = wshift, \
84 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1}
85#define SND_SOC_DAPM_MUX(wname, wreg, wshift, winvert, wcontrols) \
86{ .id = snd_soc_dapm_mux, .name = wname, .reg = wreg, .shift = wshift, \
87 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1}
88
89/* path domain with event - event handler must return 0 for success */
90#define SND_SOC_DAPM_PGA_E(wname, wreg, wshift, winvert, wcontrols, \
91 wncontrols, wevent, wflags) \
92{ .id = snd_soc_dapm_pga, .name = wname, .reg = wreg, .shift = wshift, \
93 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols, \
94 .event = wevent, .event_flags = wflags}
95#define SND_SOC_DAPM_MIXER_E(wname, wreg, wshift, winvert, wcontrols, \
96 wncontrols, wevent, wflags) \
97{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \
98 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols, \
99 .event = wevent, .event_flags = wflags}
100#define SND_SOC_DAPM_MICBIAS_E(wname, wreg, wshift, winvert, wevent, wflags) \
101{ .id = snd_soc_dapm_micbias, .name = wname, .reg = wreg, .shift = wshift, \
102 .invert = winvert, .kcontrols = NULL, .num_kcontrols = 0, \
103 .event = wevent, .event_flags = wflags}
104#define SND_SOC_DAPM_SWITCH_E(wname, wreg, wshift, winvert, wcontrols, \
105 wevent, wflags) \
106{ .id = snd_soc_dapm_switch, .name = wname, .reg = wreg, .shift = wshift, \
107 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1 \
108 .event = wevent, .event_flags = wflags}
109#define SND_SOC_DAPM_MUX_E(wname, wreg, wshift, winvert, wcontrols, \
110 wevent, wflags) \
111{ .id = snd_soc_dapm_mux, .name = wname, .reg = wreg, .shift = wshift, \
112 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1, \
113 .event = wevent, .event_flags = wflags}
114
115/* events that are pre and post DAPM */
116#define SND_SOC_DAPM_PRE(wname, wevent) \
117{ .id = snd_soc_dapm_pre, .name = wname, .kcontrols = NULL, \
118 .num_kcontrols = 0, .event = wevent, \
119 .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD}
120#define SND_SOC_DAPM_POST(wname, wevent) \
121{ .id = snd_soc_dapm_post, .name = wname, .kcontrols = NULL, \
122 .num_kcontrols = 0, .event = wevent, \
123 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD}
124
125/* stream domain */
126#define SND_SOC_DAPM_DAC(wname, stname, wreg, wshift, winvert) \
127{ .id = snd_soc_dapm_dac, .name = wname, .sname = stname, .reg = wreg, \
128 .shift = wshift, .invert = winvert}
129#define SND_SOC_DAPM_ADC(wname, stname, wreg, wshift, winvert) \
130{ .id = snd_soc_dapm_adc, .name = wname, .sname = stname, .reg = wreg, \
131 .shift = wshift, .invert = winvert}
132
133/* dapm kcontrol types */
134#define SOC_DAPM_SINGLE(xname, reg, shift, mask, invert) \
135{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
136 .info = snd_soc_info_volsw, \
137 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
138 .private_value = SOC_SINGLE_VALUE(reg, shift, mask, invert) }
139#define SOC_DAPM_DOUBLE(xname, reg, shift_left, shift_right, mask, invert, \
140 power) \
141{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
142 .info = snd_soc_info_volsw, \
143 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
144 .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) |\
145 ((mask) << 16) | ((invert) << 24) }
146#define SOC_DAPM_ENUM(xname, xenum) \
147{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
148 .info = snd_soc_info_enum_double, \
149 .get = snd_soc_dapm_get_enum_double, \
150 .put = snd_soc_dapm_put_enum_double, \
151 .private_value = (unsigned long)&xenum }
152
153/* dapm stream operations */
154#define SND_SOC_DAPM_STREAM_NOP 0x0
155#define SND_SOC_DAPM_STREAM_START 0x1
156#define SND_SOC_DAPM_STREAM_STOP 0x2
157#define SND_SOC_DAPM_STREAM_SUSPEND 0x4
158#define SND_SOC_DAPM_STREAM_RESUME 0x8
159#define SND_SOC_DAPM_STREAM_PAUSE_PUSH 0x10
160#define SND_SOC_DAPM_STREAM_PAUSE_RELEASE 0x20
161
162/* dapm event types */
163#define SND_SOC_DAPM_PRE_PMU 0x1 /* before widget power up */
164#define SND_SOC_DAPM_POST_PMU 0x2 /* after widget power up */
165#define SND_SOC_DAPM_PRE_PMD 0x4 /* before widget power down */
166#define SND_SOC_DAPM_POST_PMD 0x8 /* after widget power down */
167#define SND_SOC_DAPM_PRE_REG 0x10 /* before audio path setup */
168#define SND_SOC_DAPM_POST_REG 0x20 /* after audio path setup */
169
170/* convenience event type detection */
171#define SND_SOC_DAPM_EVENT_ON(e) \
172 (e & (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU))
173#define SND_SOC_DAPM_EVENT_OFF(e) \
174 (e & (SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD))
175
176struct snd_soc_dapm_widget;
177enum snd_soc_dapm_type;
178struct snd_soc_dapm_path;
179struct snd_soc_dapm_pin;
180
181/* dapm controls */
182int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
183 struct snd_ctl_elem_value *ucontrol);
184int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
185 struct snd_ctl_elem_value *ucontrol);
186int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
187 struct snd_ctl_elem_value *ucontrol);
188int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
189 struct snd_ctl_elem_value *ucontrol);
190int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
191 const struct snd_soc_dapm_widget *widget);
192
193/* dapm path setup */
194int snd_soc_dapm_connect_input(struct snd_soc_codec *codec,
195 const char *sink_name, const char *control_name, const char *src_name);
196int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec);
197void snd_soc_dapm_free(struct snd_soc_device *socdev);
198
199/* dapm events */
200int snd_soc_dapm_stream_event(struct snd_soc_codec *codec, char *stream,
201 int event);
202
203/* dapm sys fs - used by the core */
204int snd_soc_dapm_sys_add(struct device *dev);
205
206/* dapm audio endpoint control */
207int snd_soc_dapm_set_endpoint(struct snd_soc_codec *codec,
208 char *pin, int status);
209int snd_soc_dapm_sync_endpoints(struct snd_soc_codec *codec);
210
211/* dapm widget types */
212enum snd_soc_dapm_type {
213 snd_soc_dapm_input = 0, /* input pin */
214 snd_soc_dapm_output, /* output pin */
215 snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */
216 snd_soc_dapm_mixer, /* mixes several analog signals together */
217 snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */
218 snd_soc_dapm_adc, /* analog to digital converter */
219 snd_soc_dapm_dac, /* digital to analog converter */
220 snd_soc_dapm_micbias, /* microphone bias (power) */
221 snd_soc_dapm_mic, /* microphone */
222 snd_soc_dapm_hp, /* headphones */
223 snd_soc_dapm_spk, /* speaker */
224 snd_soc_dapm_line, /* line input/output */
225 snd_soc_dapm_switch, /* analog switch */
226 snd_soc_dapm_vmid, /* codec bias/vmid - to minimise pops */
227 snd_soc_dapm_pre, /* machine specific pre widget - exec first */
228 snd_soc_dapm_post, /* machine specific post widget - exec last */
229};
230
231/* dapm audio path between two widgets */
232struct snd_soc_dapm_path {
233 char *name;
234 char *long_name;
235
236 /* source (input) and sink (output) widgets */
237 struct snd_soc_dapm_widget *source;
238 struct snd_soc_dapm_widget *sink;
239 struct snd_kcontrol *kcontrol;
240
241 /* status */
242 u32 connect:1; /* source and sink widgets are connected */
243 u32 walked:1; /* path has been walked */
244
245 struct list_head list_source;
246 struct list_head list_sink;
247 struct list_head list;
248};
249
250/* dapm widget */
251struct snd_soc_dapm_widget {
252 enum snd_soc_dapm_type id;
253 char *name; /* widget name */
254 char *sname; /* stream name */
255 struct snd_soc_codec *codec;
256 struct list_head list;
257
258 /* dapm control */
259 short reg; /* negative reg = no direct dapm */
260 unsigned char shift; /* bits to shift */
261 unsigned int saved_value; /* widget saved value */
262 unsigned int value; /* widget current value */
263 unsigned char power:1; /* block power status */
264 unsigned char invert:1; /* invert the power bit */
265 unsigned char active:1; /* active stream on DAC, ADC's */
266 unsigned char connected:1; /* connected codec pin */
267 unsigned char new:1; /* cnew complete */
268 unsigned char ext:1; /* has external widgets */
269 unsigned char muted:1; /* muted for pop reduction */
270 unsigned char suspend:1; /* was active before suspend */
271 unsigned char pmdown:1; /* waiting for timeout */
272
273 /* external events */
274 unsigned short event_flags; /* flags to specify event types */
275 int (*event)(struct snd_soc_dapm_widget*, int);
276
277 /* kcontrols that relate to this widget */
278 int num_kcontrols;
279 const struct snd_kcontrol_new *kcontrols;
280
281 /* widget input and outputs */
282 struct list_head sources;
283 struct list_head sinks;
284};
285
286#endif
diff --git a/include/sound/soc.h b/include/sound/soc.h
new file mode 100644
index 000000000000..ecdd1fac94b6
--- /dev/null
+++ b/include/sound/soc.h
@@ -0,0 +1,480 @@
1/*
2 * linux/sound/soc.h -- ALSA SoC Layer
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
13#ifndef __LINUX_SND_SOC_H
14#define __LINUX_SND_SOC_H
15
16#include <linux/platform_device.h>
17#include <linux/types.h>
18#include <sound/driver.h>
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/control.h>
22#include <sound/ac97_codec.h>
23
24#define SND_SOC_VERSION "0.11.8"
25
26/*
27 * Convenience kcontrol builders
28 */
29#define SOC_SINGLE_VALUE(reg,shift,mask,invert) ((reg) | ((shift) << 8) |\
30 ((shift) << 12) | ((mask) << 16) | ((invert) << 24))
31#define SOC_SINGLE_VALUE_EXT(reg,mask,invert) ((reg) | ((mask) << 16) |\
32 ((invert) << 31))
33#define SOC_SINGLE(xname, reg, shift, mask, invert) \
34{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
35 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
36 .put = snd_soc_put_volsw, \
37 .private_value = SOC_SINGLE_VALUE(reg, shift, mask, invert) }
38#define SOC_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
39{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
40 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
41 .put = snd_soc_put_volsw, \
42 .private_value = (reg) | ((shift_left) << 8) | \
43 ((shift_right) << 12) | ((mask) << 16) | ((invert) << 24) }
44#define SOC_DOUBLE_R(xname, reg_left, reg_right, shift, mask, invert) \
45{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
46 .info = snd_soc_info_volsw_2r, \
47 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
48 .private_value = (reg_left) | ((shift) << 8) | \
49 ((mask) << 12) | ((invert) << 20) | ((reg_right) << 24) }
50#define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts) \
51{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
52 .mask = xmask, .texts = xtexts }
53#define SOC_ENUM_SINGLE(xreg, xshift, xmask, xtexts) \
54 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xtexts)
55#define SOC_ENUM_SINGLE_EXT(xmask, xtexts) \
56{ .mask = xmask, .texts = xtexts }
57#define SOC_ENUM(xname, xenum) \
58{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
59 .info = snd_soc_info_enum_double, \
60 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
61 .private_value = (unsigned long)&xenum }
62#define SOC_SINGLE_EXT(xname, xreg, xmask, xinvert,\
63 xhandler_get, xhandler_put) \
64{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
65 .info = snd_soc_info_volsw_ext, \
66 .get = xhandler_get, .put = xhandler_put, \
67 .private_value = SOC_SINGLE_VALUE_EXT(xreg, xmask, xinvert) }
68#define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
69{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
70 .info = snd_soc_info_bool_ext, \
71 .get = xhandler_get, .put = xhandler_put, \
72 .private_value = xdata }
73#define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
74{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
75 .info = snd_soc_info_enum_ext, \
76 .get = xhandler_get, .put = xhandler_put, \
77 .private_value = (unsigned long)&xenum }
78
79/*
80 * Digital Audio Interface (DAI) types
81 */
82#define SND_SOC_DAI_AC97 0x1
83#define SND_SOC_DAI_I2S 0x2
84#define SND_SOC_DAI_PCM 0x4
85
86/*
87 * DAI hardware audio formats
88 */
89#define SND_SOC_DAIFMT_I2S (1 << 0) /* I2S mode */
90#define SND_SOC_DAIFMT_RIGHT_J (1 << 1) /* Right justified mode */
91#define SND_SOC_DAIFMT_LEFT_J (1 << 2) /* Left Justified mode */
92#define SND_SOC_DAIFMT_DSP_A (1 << 3) /* L data msb after FRM or LRC */
93#define SND_SOC_DAIFMT_DSP_B (1 << 4) /* L data msb during FRM or LRC */
94#define SND_SOC_DAIFMT_AC97 (1 << 5) /* AC97 */
95
96/*
97 * DAI hardware signal inversions
98 */
99#define SND_SOC_DAIFMT_NB_NF (1 << 8) /* normal bit clock + frame */
100#define SND_SOC_DAIFMT_NB_IF (1 << 9) /* normal bclk + inv frm */
101#define SND_SOC_DAIFMT_IB_NF (1 << 10) /* invert bclk + nor frm */
102#define SND_SOC_DAIFMT_IB_IF (1 << 11) /* invert bclk + frm */
103
104/*
105 * DAI hardware clock masters
106 * This is wrt the codec, the inverse is true for the interface
107 * i.e. if the codec is clk and frm master then the interface is
108 * clk and frame slave.
109 */
110#define SND_SOC_DAIFMT_CBM_CFM (1 << 12) /* codec clk & frm master */
111#define SND_SOC_DAIFMT_CBS_CFM (1 << 13) /* codec clk slave & frm master */
112#define SND_SOC_DAIFMT_CBM_CFS (1 << 14) /* codec clk master & frame slave */
113#define SND_SOC_DAIFMT_CBS_CFS (1 << 15) /* codec clk & frm slave */
114
115#define SND_SOC_DAIFMT_FORMAT_MASK 0x00ff
116#define SND_SOC_DAIFMT_INV_MASK 0x0f00
117#define SND_SOC_DAIFMT_CLOCK_MASK 0xf000
118
119/*
120 * DAI hardware audio direction
121 */
122#define SND_SOC_DAIDIR_PLAYBACK 0x1
123#define SND_SOC_DAIDIR_CAPTURE 0x2
124
125/*
126 * DAI hardware Time Division Multiplexing (TDM) Slots
127 * Left and Right data word positions
128 * This is measured in words (sample size) and not bits.
129 */
130#define SND_SOC_DAITDM_LRDW(l,r) ((l << 8) | r)
131
132/*
133 * DAI hardware clock ratios
134 * bit clock can either be a generated by dividing mclk or
135 * by multiplying sample rate, hence there are 2 definitions below
136 * depending on codec type.
137 */
138/* ratio of sample rate to mclk/sysclk */
139#define SND_SOC_FS_ALL 0xffff /* all mclk supported */
140
141/* bit clock dividers */
142#define SND_SOC_FSBD(x) (1 << (x - 1)) /* ratio mclk:bclk */
143#define SND_SOC_FSBD_REAL(x) (ffs(x))
144#define SND_SOC_FSBD_ALL 0xffff /* all bit clock dividers supported */
145
146/* bit clock ratio to sample rate */
147#define SND_SOC_FSB(x) (1 << ((x - 16) / 16))
148#define SND_SOC_FSB_REAL(x) (((ffs(x) - 1) * 16) + 16)
149/* all bclk ratios supported */
150#define SND_SOC_FSB_ALL SND_SOC_FSBD_ALL
151
152/*
153 * DAI hardware flags
154 */
155/* use bfs mclk divider mode, else sample rate ratio */
156#define SND_SOC_DAI_BFS_DIV 0x1
157
158/*
159 * AC97 codec ID's bitmask
160 */
161#define SND_SOC_DAI_AC97_ID0 (1 << 0)
162#define SND_SOC_DAI_AC97_ID1 (1 << 1)
163#define SND_SOC_DAI_AC97_ID2 (1 << 2)
164#define SND_SOC_DAI_AC97_ID3 (1 << 3)
165
166struct snd_soc_device;
167struct snd_soc_pcm_stream;
168struct snd_soc_ops;
169struct snd_soc_dai_mode;
170struct snd_soc_pcm_runtime;
171struct snd_soc_codec_dai;
172struct snd_soc_cpu_dai;
173struct snd_soc_codec;
174struct snd_soc_machine_config;
175struct soc_enum;
176struct snd_soc_ac97_ops;
177struct snd_soc_clock_info;
178
179typedef int (*hw_write_t)(void *,const char* ,int);
180typedef int (*hw_read_t)(void *,char* ,int);
181
182extern struct snd_ac97_bus_ops soc_ac97_ops;
183
184/* pcm <-> DAI connect */
185void snd_soc_free_pcms(struct snd_soc_device *socdev);
186int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid);
187int snd_soc_register_card(struct snd_soc_device *socdev);
188
189/* set runtime hw params */
190int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
191 const struct snd_pcm_hardware *hw);
192int snd_soc_get_rate(int rate);
193
194/* codec IO */
195#define snd_soc_read(codec, reg) codec->read(codec, reg)
196#define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
197
198/* codec register bit access */
199int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
200 unsigned short mask, unsigned short value);
201int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
202 unsigned short mask, unsigned short value);
203
204int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
205 struct snd_ac97_bus_ops *ops, int num);
206void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
207
208/*
209 *Controls
210 */
211struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
212 void *data, char *long_name);
213int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
214 struct snd_ctl_elem_info *uinfo);
215int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
216 struct snd_ctl_elem_info *uinfo);
217int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
218 struct snd_ctl_elem_value *ucontrol);
219int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
220 struct snd_ctl_elem_value *ucontrol);
221int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
222 struct snd_ctl_elem_info *uinfo);
223int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
224 struct snd_ctl_elem_info *uinfo);
225int snd_soc_info_bool_ext(struct snd_kcontrol *kcontrol,
226 struct snd_ctl_elem_info *uinfo);
227int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
228 struct snd_ctl_elem_value *ucontrol);
229int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
230 struct snd_ctl_elem_value *ucontrol);
231int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
232 struct snd_ctl_elem_info *uinfo);
233int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
234 struct snd_ctl_elem_value *ucontrol);
235int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
236 struct snd_ctl_elem_value *ucontrol);
237
238/* SoC PCM stream information */
239struct snd_soc_pcm_stream {
240 char *stream_name;
241 unsigned int rate_min; /* min rate */
242 unsigned int rate_max; /* max rate */
243 unsigned int channels_min; /* min channels */
244 unsigned int channels_max; /* max channels */
245 unsigned int active:1; /* stream is in use */
246};
247
248/* SoC audio ops */
249struct snd_soc_ops {
250 int (*startup)(struct snd_pcm_substream *);
251 void (*shutdown)(struct snd_pcm_substream *);
252 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
253 int (*hw_free)(struct snd_pcm_substream *);
254 int (*prepare)(struct snd_pcm_substream *);
255 int (*trigger)(struct snd_pcm_substream *, int);
256};
257
258/* SoC DAI hardware mode */
259struct snd_soc_dai_mode {
260 u16 fmt; /* SND_SOC_DAIFMT_* */
261 u16 tdm; /* SND_SOC_HWTDM_* */
262 u64 pcmfmt; /* SNDRV_PCM_FMTBIT_* */
263 u16 pcmrate; /* SND_SOC_HWRATE_* */
264 u16 pcmdir:2; /* SND_SOC_HWDIR_* */
265 u16 flags:8; /* hw flags */
266 u16 fs; /* mclk to rate divider */
267 u32 bfs; /* mclk to bclk dividers */
268 unsigned long priv; /* private mode data */
269};
270
271/* DAI capabilities */
272struct snd_soc_dai_cap {
273 int num_modes; /* number of DAI modes */
274 struct snd_soc_dai_mode *mode; /* array of supported DAI modes */
275};
276
277/* SoC Codec DAI */
278struct snd_soc_codec_dai {
279 char *name;
280 int id;
281
282 /* DAI capabilities */
283 struct snd_soc_pcm_stream playback;
284 struct snd_soc_pcm_stream capture;
285 struct snd_soc_dai_cap caps;
286
287 /* DAI runtime info */
288 struct snd_soc_dai_mode dai_runtime;
289 struct snd_soc_ops ops;
290 unsigned int (*config_sysclk)(struct snd_soc_codec_dai*,
291 struct snd_soc_clock_info *info, unsigned int clk);
292 int (*digital_mute)(struct snd_soc_codec *,
293 struct snd_soc_codec_dai*, int);
294 unsigned int mclk; /* the audio master clock */
295 unsigned int pll_in; /* the PLL input clock */
296 unsigned int pll_out; /* the PLL output clock */
297 unsigned int clk_div; /* internal clock divider << 1 (for fractions) */
298 unsigned int active;
299 unsigned char pop_wait:1;
300
301 /* DAI private data */
302 void *private_data;
303};
304
305/* SoC CPU DAI */
306struct snd_soc_cpu_dai {
307
308 /* DAI description */
309 char *name;
310 unsigned int id;
311 unsigned char type;
312
313 /* DAI callbacks */
314 int (*probe)(struct platform_device *pdev);
315 void (*remove)(struct platform_device *pdev);
316 int (*suspend)(struct platform_device *pdev,
317 struct snd_soc_cpu_dai *cpu_dai);
318 int (*resume)(struct platform_device *pdev,
319 struct snd_soc_cpu_dai *cpu_dai);
320 unsigned int (*config_sysclk)(struct snd_soc_cpu_dai *cpu_dai,
321 struct snd_soc_clock_info *info, unsigned int clk);
322
323 /* DAI capabilities */
324 struct snd_soc_pcm_stream capture;
325 struct snd_soc_pcm_stream playback;
326 struct snd_soc_dai_cap caps;
327
328 /* DAI runtime info */
329 struct snd_soc_dai_mode dai_runtime;
330 struct snd_soc_ops ops;
331 struct snd_pcm_runtime *runtime;
332 unsigned char active:1;
333 unsigned int mclk;
334 void *dma_data;
335
336 /* DAI private data */
337 void *private_data;
338};
339
340/* SoC Audio Codec */
341struct snd_soc_codec {
342 char *name;
343 struct module *owner;
344 struct mutex mutex;
345
346 /* callbacks */
347 int (*dapm_event)(struct snd_soc_codec *codec, int event);
348
349 /* runtime */
350 struct snd_card *card;
351 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
352 unsigned int active;
353 unsigned int pcm_devs;
354 void *private_data;
355
356 /* codec IO */
357 void *control_data; /* codec control (i2c/3wire) data */
358 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
359 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
360 hw_write_t hw_write;
361 hw_read_t hw_read;
362 void *reg_cache;
363 short reg_cache_size;
364 short reg_cache_step;
365
366 /* dapm */
367 struct list_head dapm_widgets;
368 struct list_head dapm_paths;
369 unsigned int dapm_state;
370 unsigned int suspend_dapm_state;
371
372 /* codec DAI's */
373 struct snd_soc_codec_dai *dai;
374 unsigned int num_dai;
375};
376
377/* codec device */
378struct snd_soc_codec_device {
379 int (*probe)(struct platform_device *pdev);
380 int (*remove)(struct platform_device *pdev);
381 int (*suspend)(struct platform_device *pdev, pm_message_t state);
382 int (*resume)(struct platform_device *pdev);
383};
384
385/* SoC platform interface */
386struct snd_soc_platform {
387 char *name;
388
389 int (*probe)(struct platform_device *pdev);
390 int (*remove)(struct platform_device *pdev);
391 int (*suspend)(struct platform_device *pdev,
392 struct snd_soc_cpu_dai *cpu_dai);
393 int (*resume)(struct platform_device *pdev,
394 struct snd_soc_cpu_dai *cpu_dai);
395
396 /* pcm creation and destruction */
397 int (*pcm_new)(struct snd_card *, struct snd_soc_codec_dai *,
398 struct snd_pcm *);
399 void (*pcm_free)(struct snd_pcm *);
400
401 /* platform stream ops */
402 struct snd_pcm_ops *pcm_ops;
403};
404
405/* SoC machine DAI configuration, glues a codec and cpu DAI together */
406struct snd_soc_dai_link {
407 char *name; /* Codec name */
408 char *stream_name; /* Stream name */
409
410 /* DAI */
411 struct snd_soc_codec_dai *codec_dai;
412 struct snd_soc_cpu_dai *cpu_dai;
413 u32 flags; /* DAI config preference flags */
414
415 /* codec/machine specific init - e.g. add machine controls */
416 int (*init)(struct snd_soc_codec *codec);
417
418 /* audio sysclock configuration */
419 unsigned int (*config_sysclk)(struct snd_soc_pcm_runtime *rtd,
420 struct snd_soc_clock_info *info);
421};
422
423/* SoC machine */
424struct snd_soc_machine {
425 char *name;
426
427 int (*probe)(struct platform_device *pdev);
428 int (*remove)(struct platform_device *pdev);
429
430 /* the pre and post PM functions are used to do any PM work before and
431 * after the codec and DAI's do any PM work. */
432 int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
433 int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
434 int (*resume_pre)(struct platform_device *pdev);
435 int (*resume_post)(struct platform_device *pdev);
436
437 /* machine stream operations */
438 struct snd_soc_ops *ops;
439
440 /* CPU <--> Codec DAI links */
441 struct snd_soc_dai_link *dai_link;
442 int num_links;
443};
444
445/* SoC Device - the audio subsystem */
446struct snd_soc_device {
447 struct device *dev;
448 struct snd_soc_machine *machine;
449 struct snd_soc_platform *platform;
450 struct snd_soc_codec *codec;
451 struct snd_soc_codec_device *codec_dev;
452 void *codec_data;
453};
454
455/* runtime channel data */
456struct snd_soc_pcm_runtime {
457 struct snd_soc_codec_dai *codec_dai;
458 struct snd_soc_cpu_dai *cpu_dai;
459 struct snd_soc_device *socdev;
460};
461
462/* enumerated kcontrol */
463struct soc_enum {
464 unsigned short reg;
465 unsigned short reg2;
466 unsigned char shift_l;
467 unsigned char shift_r;
468 unsigned int mask;
469 const char **texts;
470 void *dapm;
471};
472
473/* clocking configuration data */
474struct snd_soc_clock_info {
475 unsigned int rate;
476 unsigned int fs;
477 unsigned int bclk_master;
478};
479
480#endif