blob: 5ca231f080a0a80ec0c11cb9b462edab81526dc1 [file] [log] [blame]
Richard Purdie808db4a2006-10-06 18:20:14 +02001/*
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>
Andrew Morton4484bb22006-12-15 09:30:07 +010018#include <linux/workqueue.h>
Richard Purdie808db4a2006-10-06 18:20:14 +020019#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/control.h>
22#include <sound/ac97_codec.h>
23
Mark Brown0a22b872008-01-10 14:53:48 +010024#define SND_SOC_VERSION "0.13.2"
Richard Purdie808db4a2006-10-06 18:20:14 +020025
26/*
27 * Convenience kcontrol builders
28 */
Jon Smirl4eaa9812008-07-29 11:42:26 +010029#define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) \
30 ((unsigned long)&(struct soc_mixer_control) \
31 {.reg = xreg, .shift = xshift, .max = xmax, .invert = xinvert})
32#define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
33 ((unsigned long)&(struct soc_mixer_control) \
34 {.reg = xreg, .max = xmax, .invert = xinvert})
Philipp Zabela7a4ac82008-01-10 14:37:42 +010035#define SOC_SINGLE(xname, reg, shift, max, invert) \
Richard Purdie808db4a2006-10-06 18:20:14 +020036{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
37 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
38 .put = snd_soc_put_volsw, \
Philipp Zabela7a4ac82008-01-10 14:37:42 +010039 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
40#define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
41{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
42 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
43 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
44 .tlv.p = (tlv_array), \
45 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
46 .put = snd_soc_put_volsw, \
47 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
Jon Smirl4eaa9812008-07-29 11:42:26 +010048#define SOC_DOUBLE(xname, xreg, shift_left, shift_right, xmax, xinvert) \
Richard Purdie808db4a2006-10-06 18:20:14 +020049{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
50 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
51 .put = snd_soc_put_volsw, \
Jon Smirl4eaa9812008-07-29 11:42:26 +010052 .private_value = (unsigned long)&(struct soc_mixer_control) \
53 {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
54 .max = xmax, .invert = xinvert} }
55#define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
Richard Purdie808db4a2006-10-06 18:20:14 +020056{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
57 .info = snd_soc_info_volsw_2r, \
58 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
Jon Smirl4eaa9812008-07-29 11:42:26 +010059 .private_value = (unsigned long)&(struct soc_mixer_control) \
60 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
61 .max = xmax, .invert = xinvert} }
62#define SOC_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert, tlv_array) \
Philipp Zabela7a4ac82008-01-10 14:37:42 +010063{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
64 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
65 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
66 .tlv.p = (tlv_array), \
67 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
68 .put = snd_soc_put_volsw, \
Jon Smirl4eaa9812008-07-29 11:42:26 +010069 .private_value = (unsigned long)&(struct soc_mixer_control) \
70 {.reg = xreg, .shift = shift_left, .rshift = shift_right,\
71 .max = xmax, .invert = xinvert} }
72#define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
Philipp Zabela7a4ac82008-01-10 14:37:42 +010073{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
74 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
75 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
76 .tlv.p = (tlv_array), \
77 .info = snd_soc_info_volsw_2r, \
78 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
Jon Smirl4eaa9812008-07-29 11:42:26 +010079 .private_value = (unsigned long)&(struct soc_mixer_control) \
80 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
81 .max = xmax, .invert = xinvert} }
82#define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
Mark Browne13ac2e2008-05-28 17:58:05 +010083{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
84 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
85 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
86 .tlv.p = (tlv_array), \
87 .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
88 .put = snd_soc_put_volsw_s8, \
Jon Smirl4eaa9812008-07-29 11:42:26 +010089 .private_value = (unsigned long)&(struct soc_mixer_control) \
90 {.reg = xreg, .min = xmin, .max = xmax} }
Jon Smirlf8ba0b72008-07-29 11:42:27 +010091#define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmax, xtexts) \
Richard Purdie808db4a2006-10-06 18:20:14 +020092{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
Jon Smirlf8ba0b72008-07-29 11:42:27 +010093 .max = xmax, .texts = xtexts }
94#define SOC_ENUM_SINGLE(xreg, xshift, xmax, xtexts) \
95 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmax, xtexts)
96#define SOC_ENUM_SINGLE_EXT(xmax, xtexts) \
97{ .max = xmax, .texts = xtexts }
Richard Purdie808db4a2006-10-06 18:20:14 +020098#define SOC_ENUM(xname, xenum) \
99{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
100 .info = snd_soc_info_enum_double, \
101 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
102 .private_value = (unsigned long)&xenum }
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100103#define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
Richard Purdie808db4a2006-10-06 18:20:14 +0200104 xhandler_get, xhandler_put) \
105{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100106 .info = snd_soc_info_volsw, \
Richard Purdie808db4a2006-10-06 18:20:14 +0200107 .get = xhandler_get, .put = xhandler_put, \
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100108 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
109#define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
Mike Montour10144c02008-06-11 13:47:13 +0100110 xhandler_get, xhandler_put, tlv_array) \
111{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
112 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
113 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
114 .tlv.p = (tlv_array), \
115 .info = snd_soc_info_volsw, \
116 .get = xhandler_get, .put = xhandler_put, \
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100117 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
Richard Purdie808db4a2006-10-06 18:20:14 +0200118#define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
119{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
120 .info = snd_soc_info_bool_ext, \
121 .get = xhandler_get, .put = xhandler_put, \
122 .private_value = xdata }
123#define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
124{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
125 .info = snd_soc_info_enum_ext, \
126 .get = xhandler_get, .put = xhandler_put, \
127 .private_value = (unsigned long)&xenum }
128
129/*
Mark Brown0be98982008-05-19 12:31:28 +0200130 * Bias levels
131 *
132 * @ON: Bias is fully on for audio playback and capture operations.
133 * @PREPARE: Prepare for audio operations. Called before DAPM switching for
134 * stream start and stop operations.
135 * @STANDBY: Low power standby state when no playback/capture operations are
136 * in progress. NOTE: The transition time between STANDBY and ON
137 * should be as fast as possible and no longer than 10ms.
138 * @OFF: Power Off. No restrictions on transition times.
139 */
140enum snd_soc_bias_level {
141 SND_SOC_BIAS_ON,
142 SND_SOC_BIAS_PREPARE,
143 SND_SOC_BIAS_STANDBY,
144 SND_SOC_BIAS_OFF,
145};
146
147/*
Richard Purdie808db4a2006-10-06 18:20:14 +0200148 * Digital Audio Interface (DAI) types
149 */
150#define SND_SOC_DAI_AC97 0x1
151#define SND_SOC_DAI_I2S 0x2
152#define SND_SOC_DAI_PCM 0x4
Liam Girdwooda68660e2007-05-10 19:27:27 +0200153#define SND_SOC_DAI_AC97_BUS 0x8 /* for custom i.e. non ac97_codec.c */
Richard Purdie808db4a2006-10-06 18:20:14 +0200154
155/*
156 * DAI hardware audio formats
157 */
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100158#define SND_SOC_DAIFMT_I2S 0 /* I2S mode */
159#define SND_SOC_DAIFMT_RIGHT_J 1 /* Right justified mode */
160#define SND_SOC_DAIFMT_LEFT_J 2 /* Left Justified mode */
161#define SND_SOC_DAIFMT_DSP_A 3 /* L data msb after FRM or LRC */
162#define SND_SOC_DAIFMT_DSP_B 4 /* L data msb during FRM or LRC */
163#define SND_SOC_DAIFMT_AC97 5 /* AC97 */
164
165#define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
166#define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
167
168/*
169 * DAI Gating
170 */
171#define SND_SOC_DAIFMT_CONT (0 << 4) /* continuous clock */
172#define SND_SOC_DAIFMT_GATED (1 << 4) /* clock is gated when not Tx/Rx */
Richard Purdie808db4a2006-10-06 18:20:14 +0200173
174/*
Philipp Zabela7a4ac82008-01-10 14:37:42 +0100175 * DAI Sync
176 * Synchronous LR (Left Right) clocks and Frame signals.
177 */
178#define SND_SOC_DAIFMT_SYNC (0 << 5) /* Tx FRM = Rx FRM */
179#define SND_SOC_DAIFMT_ASYNC (1 << 5) /* Tx FRM ~ Rx FRM */
180
181/*
182 * TDM
183 */
184#define SND_SOC_DAIFMT_TDM (1 << 6)
185
186/*
Richard Purdie808db4a2006-10-06 18:20:14 +0200187 * DAI hardware signal inversions
188 */
Philipp Zabela7a4ac82008-01-10 14:37:42 +0100189#define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bclk + frm */
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100190#define SND_SOC_DAIFMT_NB_IF (1 << 8) /* normal bclk + inv frm */
191#define SND_SOC_DAIFMT_IB_NF (2 << 8) /* invert bclk + nor frm */
192#define SND_SOC_DAIFMT_IB_IF (3 << 8) /* invert bclk + frm */
Richard Purdie808db4a2006-10-06 18:20:14 +0200193
194/*
195 * DAI hardware clock masters
196 * This is wrt the codec, the inverse is true for the interface
197 * i.e. if the codec is clk and frm master then the interface is
198 * clk and frame slave.
199 */
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100200#define SND_SOC_DAIFMT_CBM_CFM (0 << 12) /* codec clk & frm master */
201#define SND_SOC_DAIFMT_CBS_CFM (1 << 12) /* codec clk slave & frm master */
202#define SND_SOC_DAIFMT_CBM_CFS (2 << 12) /* codec clk master & frame slave */
203#define SND_SOC_DAIFMT_CBS_CFS (3 << 12) /* codec clk & frm slave */
Richard Purdie808db4a2006-10-06 18:20:14 +0200204
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100205#define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
206#define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
Richard Purdie808db4a2006-10-06 18:20:14 +0200207#define SND_SOC_DAIFMT_INV_MASK 0x0f00
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100208#define SND_SOC_DAIFMT_MASTER_MASK 0xf000
209
Richard Purdie808db4a2006-10-06 18:20:14 +0200210
211/*
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100212 * Master Clock Directions
Richard Purdie808db4a2006-10-06 18:20:14 +0200213 */
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100214#define SND_SOC_CLOCK_IN 0
215#define SND_SOC_CLOCK_OUT 1
Richard Purdie808db4a2006-10-06 18:20:14 +0200216
217/*
218 * AC97 codec ID's bitmask
219 */
220#define SND_SOC_DAI_AC97_ID0 (1 << 0)
221#define SND_SOC_DAI_AC97_ID1 (1 << 1)
222#define SND_SOC_DAI_AC97_ID2 (1 << 2)
223#define SND_SOC_DAI_AC97_ID3 (1 << 3)
224
225struct snd_soc_device;
226struct snd_soc_pcm_stream;
227struct snd_soc_ops;
228struct snd_soc_dai_mode;
229struct snd_soc_pcm_runtime;
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100230struct snd_soc_dai;
Richard Purdie808db4a2006-10-06 18:20:14 +0200231struct snd_soc_codec;
232struct snd_soc_machine_config;
233struct soc_enum;
234struct snd_soc_ac97_ops;
235struct snd_soc_clock_info;
236
237typedef int (*hw_write_t)(void *,const char* ,int);
238typedef int (*hw_read_t)(void *,char* ,int);
239
240extern struct snd_ac97_bus_ops soc_ac97_ops;
241
242/* pcm <-> DAI connect */
243void snd_soc_free_pcms(struct snd_soc_device *socdev);
244int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid);
245int snd_soc_register_card(struct snd_soc_device *socdev);
246
247/* set runtime hw params */
248int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
249 const struct snd_pcm_hardware *hw);
Richard Purdie808db4a2006-10-06 18:20:14 +0200250
251/* codec IO */
252#define snd_soc_read(codec, reg) codec->read(codec, reg)
253#define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
254
255/* codec register bit access */
256int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
257 unsigned short mask, unsigned short value);
258int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
259 unsigned short mask, unsigned short value);
260
261int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
262 struct snd_ac97_bus_ops *ops, int num);
263void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
264
Liam Girdwood8c6529d2008-07-08 13:19:13 +0100265/* Digital Audio Interface clocking API.*/
266int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
267 unsigned int freq, int dir);
268
269int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
270 int div_id, int div);
271
272int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
273 int pll_id, unsigned int freq_in, unsigned int freq_out);
274
275/* Digital Audio interface formatting */
276int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
277
278int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
279 unsigned int mask, int slots);
280
281int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);
282
283/* Digital Audio Interface mute */
284int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute);
285
Richard Purdie808db4a2006-10-06 18:20:14 +0200286/*
287 *Controls
288 */
289struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
290 void *data, char *long_name);
291int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
292 struct snd_ctl_elem_info *uinfo);
293int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
294 struct snd_ctl_elem_info *uinfo);
295int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
296 struct snd_ctl_elem_value *ucontrol);
297int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
298 struct snd_ctl_elem_value *ucontrol);
299int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
300 struct snd_ctl_elem_info *uinfo);
301int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
302 struct snd_ctl_elem_info *uinfo);
Philipp Zabel392abe92008-05-13 14:03:40 +0200303#define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
Richard Purdie808db4a2006-10-06 18:20:14 +0200304int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
305 struct snd_ctl_elem_value *ucontrol);
306int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
307 struct snd_ctl_elem_value *ucontrol);
308int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
309 struct snd_ctl_elem_info *uinfo);
310int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
311 struct snd_ctl_elem_value *ucontrol);
312int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
313 struct snd_ctl_elem_value *ucontrol);
Mark Browne13ac2e2008-05-28 17:58:05 +0100314int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
315 struct snd_ctl_elem_info *uinfo);
316int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
317 struct snd_ctl_elem_value *ucontrol);
318int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
319 struct snd_ctl_elem_value *ucontrol);
Richard Purdie808db4a2006-10-06 18:20:14 +0200320
321/* SoC PCM stream information */
322struct snd_soc_pcm_stream {
323 char *stream_name;
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100324 u64 formats; /* SNDRV_PCM_FMTBIT_* */
325 unsigned int rates; /* SNDRV_PCM_RATE_* */
Richard Purdie808db4a2006-10-06 18:20:14 +0200326 unsigned int rate_min; /* min rate */
327 unsigned int rate_max; /* max rate */
328 unsigned int channels_min; /* min channels */
329 unsigned int channels_max; /* max channels */
330 unsigned int active:1; /* stream is in use */
331};
332
333/* SoC audio ops */
334struct snd_soc_ops {
335 int (*startup)(struct snd_pcm_substream *);
336 void (*shutdown)(struct snd_pcm_substream *);
337 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
338 int (*hw_free)(struct snd_pcm_substream *);
339 int (*prepare)(struct snd_pcm_substream *);
340 int (*trigger)(struct snd_pcm_substream *, int);
341};
342
Mark Brown1ef6ab72008-05-19 12:31:55 +0200343/* ASoC DAI ops */
344struct snd_soc_dai_ops {
345 /* DAI clocking configuration */
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100346 int (*set_sysclk)(struct snd_soc_dai *dai,
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100347 int clk_id, unsigned int freq, int dir);
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100348 int (*set_pll)(struct snd_soc_dai *dai,
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100349 int pll_id, unsigned int freq_in, unsigned int freq_out);
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100350 int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100351
Mark Brown1ef6ab72008-05-19 12:31:55 +0200352 /* DAI format configuration */
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100353 int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
354 int (*set_tdm_slot)(struct snd_soc_dai *dai,
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100355 unsigned int mask, int slots);
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100356 int (*set_tristate)(struct snd_soc_dai *dai, int tristate);
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100357
358 /* digital mute */
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100359 int (*digital_mute)(struct snd_soc_dai *dai, int mute);
Richard Purdie808db4a2006-10-06 18:20:14 +0200360};
361
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100362/* SoC DAI (Digital Audio Interface) */
363struct snd_soc_dai {
Richard Purdie808db4a2006-10-06 18:20:14 +0200364 /* DAI description */
365 char *name;
366 unsigned int id;
367 unsigned char type;
368
369 /* DAI callbacks */
Mark Brownbdb92872008-06-11 13:47:10 +0100370 int (*probe)(struct platform_device *pdev,
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100371 struct snd_soc_dai *dai);
Mark Brownbdb92872008-06-11 13:47:10 +0100372 void (*remove)(struct platform_device *pdev,
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100373 struct snd_soc_dai *dai);
Richard Purdie808db4a2006-10-06 18:20:14 +0200374 int (*suspend)(struct platform_device *pdev,
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100375 struct snd_soc_dai *dai);
Richard Purdie808db4a2006-10-06 18:20:14 +0200376 int (*resume)(struct platform_device *pdev,
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100377 struct snd_soc_dai *dai);
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100378
379 /* ops */
380 struct snd_soc_ops ops;
Mark Brown1ef6ab72008-05-19 12:31:55 +0200381 struct snd_soc_dai_ops dai_ops;
Richard Purdie808db4a2006-10-06 18:20:14 +0200382
383 /* DAI capabilities */
384 struct snd_soc_pcm_stream capture;
385 struct snd_soc_pcm_stream playback;
Richard Purdie808db4a2006-10-06 18:20:14 +0200386
387 /* DAI runtime info */
Richard Purdie808db4a2006-10-06 18:20:14 +0200388 struct snd_pcm_runtime *runtime;
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100389 struct snd_soc_codec *codec;
390 unsigned int active;
391 unsigned char pop_wait:1;
Richard Purdie808db4a2006-10-06 18:20:14 +0200392 void *dma_data;
393
394 /* DAI private data */
395 void *private_data;
396};
397
398/* SoC Audio Codec */
399struct snd_soc_codec {
400 char *name;
401 struct module *owner;
402 struct mutex mutex;
403
404 /* callbacks */
Mark Brown0be98982008-05-19 12:31:28 +0200405 int (*set_bias_level)(struct snd_soc_codec *,
406 enum snd_soc_bias_level level);
Richard Purdie808db4a2006-10-06 18:20:14 +0200407
408 /* runtime */
409 struct snd_card *card;
410 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
411 unsigned int active;
412 unsigned int pcm_devs;
413 void *private_data;
414
415 /* codec IO */
416 void *control_data; /* codec control (i2c/3wire) data */
417 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
418 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
Mark Brown58cd33c2008-07-29 11:42:25 +0100419 int (*display_register)(struct snd_soc_codec *, char *,
420 size_t, unsigned int);
Richard Purdie808db4a2006-10-06 18:20:14 +0200421 hw_write_t hw_write;
422 hw_read_t hw_read;
423 void *reg_cache;
424 short reg_cache_size;
425 short reg_cache_step;
426
427 /* dapm */
428 struct list_head dapm_widgets;
429 struct list_head dapm_paths;
Mark Brown0be98982008-05-19 12:31:28 +0200430 enum snd_soc_bias_level bias_level;
431 enum snd_soc_bias_level suspend_bias_level;
Takashi Iwai1321b162006-12-21 11:02:06 +0100432 struct delayed_work delayed_work;
Richard Purdie808db4a2006-10-06 18:20:14 +0200433
434 /* codec DAI's */
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100435 struct snd_soc_dai *dai;
Richard Purdie808db4a2006-10-06 18:20:14 +0200436 unsigned int num_dai;
437};
438
439/* codec device */
440struct snd_soc_codec_device {
441 int (*probe)(struct platform_device *pdev);
442 int (*remove)(struct platform_device *pdev);
443 int (*suspend)(struct platform_device *pdev, pm_message_t state);
444 int (*resume)(struct platform_device *pdev);
445};
446
447/* SoC platform interface */
448struct snd_soc_platform {
449 char *name;
450
451 int (*probe)(struct platform_device *pdev);
452 int (*remove)(struct platform_device *pdev);
453 int (*suspend)(struct platform_device *pdev,
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100454 struct snd_soc_dai *dai);
Richard Purdie808db4a2006-10-06 18:20:14 +0200455 int (*resume)(struct platform_device *pdev,
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100456 struct snd_soc_dai *dai);
Richard Purdie808db4a2006-10-06 18:20:14 +0200457
458 /* pcm creation and destruction */
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100459 int (*pcm_new)(struct snd_card *, struct snd_soc_dai *,
Richard Purdie808db4a2006-10-06 18:20:14 +0200460 struct snd_pcm *);
461 void (*pcm_free)(struct snd_pcm *);
462
463 /* platform stream ops */
464 struct snd_pcm_ops *pcm_ops;
465};
466
467/* SoC machine DAI configuration, glues a codec and cpu DAI together */
468struct snd_soc_dai_link {
469 char *name; /* Codec name */
470 char *stream_name; /* Stream name */
471
472 /* DAI */
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100473 struct snd_soc_dai *codec_dai;
474 struct snd_soc_dai *cpu_dai;
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100475
476 /* machine stream operations */
477 struct snd_soc_ops *ops;
Richard Purdie808db4a2006-10-06 18:20:14 +0200478
479 /* codec/machine specific init - e.g. add machine controls */
480 int (*init)(struct snd_soc_codec *codec);
Liam Girdwood4ccab3e2008-01-10 14:39:01 +0100481
482 /* DAI pcm */
483 struct snd_pcm *pcm;
Richard Purdie808db4a2006-10-06 18:20:14 +0200484};
485
486/* SoC machine */
487struct snd_soc_machine {
488 char *name;
489
490 int (*probe)(struct platform_device *pdev);
491 int (*remove)(struct platform_device *pdev);
492
493 /* the pre and post PM functions are used to do any PM work before and
494 * after the codec and DAI's do any PM work. */
495 int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
496 int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
497 int (*resume_pre)(struct platform_device *pdev);
498 int (*resume_post)(struct platform_device *pdev);
499
Liam Girdwood0b4d2212008-01-10 14:36:20 +0100500 /* callbacks */
Mark Brown0be98982008-05-19 12:31:28 +0200501 int (*set_bias_level)(struct snd_soc_machine *,
502 enum snd_soc_bias_level level);
Liam Girdwood0b4d2212008-01-10 14:36:20 +0100503
Richard Purdie808db4a2006-10-06 18:20:14 +0200504 /* CPU <--> Codec DAI links */
505 struct snd_soc_dai_link *dai_link;
506 int num_links;
507};
508
509/* SoC Device - the audio subsystem */
510struct snd_soc_device {
511 struct device *dev;
512 struct snd_soc_machine *machine;
513 struct snd_soc_platform *platform;
514 struct snd_soc_codec *codec;
515 struct snd_soc_codec_device *codec_dev;
Andrew Morton4484bb22006-12-15 09:30:07 +0100516 struct delayed_work delayed_work;
Andy Green6ed25972008-06-13 16:24:05 +0100517 struct work_struct deferred_resume_work;
Richard Purdie808db4a2006-10-06 18:20:14 +0200518 void *codec_data;
519};
520
521/* runtime channel data */
522struct snd_soc_pcm_runtime {
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100523 struct snd_soc_dai_link *dai;
Richard Purdie808db4a2006-10-06 18:20:14 +0200524 struct snd_soc_device *socdev;
525};
526
Jon Smirl4eaa9812008-07-29 11:42:26 +0100527/* mixer control */
528struct soc_mixer_control {
529 int min, max;
530 uint reg, rreg, shift, rshift, invert;
531};
532
Richard Purdie808db4a2006-10-06 18:20:14 +0200533/* enumerated kcontrol */
534struct soc_enum {
535 unsigned short reg;
536 unsigned short reg2;
537 unsigned char shift_l;
538 unsigned char shift_r;
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100539 unsigned int max;
Richard Purdie808db4a2006-10-06 18:20:14 +0200540 const char **texts;
541 void *dapm;
542};
543
Richard Purdie808db4a2006-10-06 18:20:14 +0200544#endif