blob: 5e0189876afda7a9d523ae705a113cce1be2c69d [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) \
Mark Brown762b8df2008-10-30 12:37:08 +000031 {.reg = xreg, .shift = xshift, .rshift = xshift, .max = xmax, \
32 .invert = xinvert})
Jon Smirl4eaa9812008-07-29 11:42:26 +010033#define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
34 ((unsigned long)&(struct soc_mixer_control) \
35 {.reg = xreg, .max = xmax, .invert = xinvert})
Philipp Zabela7a4ac82008-01-10 14:37:42 +010036#define SOC_SINGLE(xname, reg, shift, max, invert) \
Richard Purdie808db4a2006-10-06 18:20:14 +020037{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
38 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
39 .put = snd_soc_put_volsw, \
Philipp Zabela7a4ac82008-01-10 14:37:42 +010040 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
41#define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
42{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
43 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
44 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
45 .tlv.p = (tlv_array), \
46 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
47 .put = snd_soc_put_volsw, \
48 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
Jon Smirl4eaa9812008-07-29 11:42:26 +010049#define SOC_DOUBLE(xname, xreg, shift_left, shift_right, xmax, xinvert) \
Richard Purdie808db4a2006-10-06 18:20:14 +020050{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
51 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
52 .put = snd_soc_put_volsw, \
Jon Smirl4eaa9812008-07-29 11:42:26 +010053 .private_value = (unsigned long)&(struct soc_mixer_control) \
54 {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
55 .max = xmax, .invert = xinvert} }
56#define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
Richard Purdie808db4a2006-10-06 18:20:14 +020057{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
58 .info = snd_soc_info_volsw_2r, \
59 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
Jon Smirl4eaa9812008-07-29 11:42:26 +010060 .private_value = (unsigned long)&(struct soc_mixer_control) \
61 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
62 .max = xmax, .invert = xinvert} }
63#define SOC_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert, tlv_array) \
Philipp Zabela7a4ac82008-01-10 14:37:42 +010064{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
65 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
66 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
67 .tlv.p = (tlv_array), \
68 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
69 .put = snd_soc_put_volsw, \
Jon Smirl4eaa9812008-07-29 11:42:26 +010070 .private_value = (unsigned long)&(struct soc_mixer_control) \
71 {.reg = xreg, .shift = shift_left, .rshift = shift_right,\
72 .max = xmax, .invert = xinvert} }
73#define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
Philipp Zabela7a4ac82008-01-10 14:37:42 +010074{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
75 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
76 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
77 .tlv.p = (tlv_array), \
78 .info = snd_soc_info_volsw_2r, \
79 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
Jon Smirl4eaa9812008-07-29 11:42:26 +010080 .private_value = (unsigned long)&(struct soc_mixer_control) \
81 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
82 .max = xmax, .invert = xinvert} }
83#define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
Mark Browne13ac2e2008-05-28 17:58:05 +010084{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
85 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
86 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
87 .tlv.p = (tlv_array), \
88 .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
89 .put = snd_soc_put_volsw_s8, \
Jon Smirl4eaa9812008-07-29 11:42:26 +010090 .private_value = (unsigned long)&(struct soc_mixer_control) \
91 {.reg = xreg, .min = xmin, .max = xmax} }
Jon Smirlf8ba0b72008-07-29 11:42:27 +010092#define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmax, xtexts) \
Richard Purdie808db4a2006-10-06 18:20:14 +020093{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
Jon Smirlf8ba0b72008-07-29 11:42:27 +010094 .max = xmax, .texts = xtexts }
95#define SOC_ENUM_SINGLE(xreg, xshift, xmax, xtexts) \
96 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmax, xtexts)
97#define SOC_ENUM_SINGLE_EXT(xmax, xtexts) \
98{ .max = xmax, .texts = xtexts }
Richard Purdie808db4a2006-10-06 18:20:14 +020099#define SOC_ENUM(xname, xenum) \
100{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
101 .info = snd_soc_info_enum_double, \
102 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
103 .private_value = (unsigned long)&xenum }
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100104#define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
Richard Purdie808db4a2006-10-06 18:20:14 +0200105 xhandler_get, xhandler_put) \
106{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100107 .info = snd_soc_info_volsw, \
Richard Purdie808db4a2006-10-06 18:20:14 +0200108 .get = xhandler_get, .put = xhandler_put, \
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100109 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
110#define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
Mike Montour10144c02008-06-11 13:47:13 +0100111 xhandler_get, xhandler_put, tlv_array) \
112{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
113 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
114 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
115 .tlv.p = (tlv_array), \
116 .info = snd_soc_info_volsw, \
117 .get = xhandler_get, .put = xhandler_put, \
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100118 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
Richard Purdie808db4a2006-10-06 18:20:14 +0200119#define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
120{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
121 .info = snd_soc_info_bool_ext, \
122 .get = xhandler_get, .put = xhandler_put, \
123 .private_value = xdata }
124#define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
125{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
126 .info = snd_soc_info_enum_ext, \
127 .get = xhandler_get, .put = xhandler_put, \
128 .private_value = (unsigned long)&xenum }
129
130/*
Mark Brown0be98982008-05-19 12:31:28 +0200131 * Bias levels
132 *
133 * @ON: Bias is fully on for audio playback and capture operations.
134 * @PREPARE: Prepare for audio operations. Called before DAPM switching for
135 * stream start and stop operations.
136 * @STANDBY: Low power standby state when no playback/capture operations are
137 * in progress. NOTE: The transition time between STANDBY and ON
138 * should be as fast as possible and no longer than 10ms.
139 * @OFF: Power Off. No restrictions on transition times.
140 */
141enum snd_soc_bias_level {
142 SND_SOC_BIAS_ON,
143 SND_SOC_BIAS_PREPARE,
144 SND_SOC_BIAS_STANDBY,
145 SND_SOC_BIAS_OFF,
146};
147
148/*
Richard Purdie808db4a2006-10-06 18:20:14 +0200149 * Digital Audio Interface (DAI) types
150 */
151#define SND_SOC_DAI_AC97 0x1
152#define SND_SOC_DAI_I2S 0x2
153#define SND_SOC_DAI_PCM 0x4
Liam Girdwooda68660e2007-05-10 19:27:27 +0200154#define SND_SOC_DAI_AC97_BUS 0x8 /* for custom i.e. non ac97_codec.c */
Richard Purdie808db4a2006-10-06 18:20:14 +0200155
156/*
157 * DAI hardware audio formats
158 */
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100159#define SND_SOC_DAIFMT_I2S 0 /* I2S mode */
160#define SND_SOC_DAIFMT_RIGHT_J 1 /* Right justified mode */
161#define SND_SOC_DAIFMT_LEFT_J 2 /* Left Justified mode */
162#define SND_SOC_DAIFMT_DSP_A 3 /* L data msb after FRM or LRC */
163#define SND_SOC_DAIFMT_DSP_B 4 /* L data msb during FRM or LRC */
164#define SND_SOC_DAIFMT_AC97 5 /* AC97 */
165
166#define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
167#define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
168
169/*
170 * DAI Gating
171 */
172#define SND_SOC_DAIFMT_CONT (0 << 4) /* continuous clock */
173#define SND_SOC_DAIFMT_GATED (1 << 4) /* clock is gated when not Tx/Rx */
Richard Purdie808db4a2006-10-06 18:20:14 +0200174
175/*
Philipp Zabela7a4ac82008-01-10 14:37:42 +0100176 * DAI Sync
177 * Synchronous LR (Left Right) clocks and Frame signals.
178 */
179#define SND_SOC_DAIFMT_SYNC (0 << 5) /* Tx FRM = Rx FRM */
180#define SND_SOC_DAIFMT_ASYNC (1 << 5) /* Tx FRM ~ Rx FRM */
181
182/*
183 * TDM
184 */
185#define SND_SOC_DAIFMT_TDM (1 << 6)
186
187/*
Richard Purdie808db4a2006-10-06 18:20:14 +0200188 * DAI hardware signal inversions
189 */
Philipp Zabela7a4ac82008-01-10 14:37:42 +0100190#define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bclk + frm */
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100191#define SND_SOC_DAIFMT_NB_IF (1 << 8) /* normal bclk + inv frm */
192#define SND_SOC_DAIFMT_IB_NF (2 << 8) /* invert bclk + nor frm */
193#define SND_SOC_DAIFMT_IB_IF (3 << 8) /* invert bclk + frm */
Richard Purdie808db4a2006-10-06 18:20:14 +0200194
195/*
196 * DAI hardware clock masters
197 * This is wrt the codec, the inverse is true for the interface
198 * i.e. if the codec is clk and frm master then the interface is
199 * clk and frame slave.
200 */
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100201#define SND_SOC_DAIFMT_CBM_CFM (0 << 12) /* codec clk & frm master */
202#define SND_SOC_DAIFMT_CBS_CFM (1 << 12) /* codec clk slave & frm master */
203#define SND_SOC_DAIFMT_CBM_CFS (2 << 12) /* codec clk master & frame slave */
204#define SND_SOC_DAIFMT_CBS_CFS (3 << 12) /* codec clk & frm slave */
Richard Purdie808db4a2006-10-06 18:20:14 +0200205
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100206#define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
207#define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
Richard Purdie808db4a2006-10-06 18:20:14 +0200208#define SND_SOC_DAIFMT_INV_MASK 0x0f00
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100209#define SND_SOC_DAIFMT_MASTER_MASK 0xf000
210
Richard Purdie808db4a2006-10-06 18:20:14 +0200211
212/*
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100213 * Master Clock Directions
Richard Purdie808db4a2006-10-06 18:20:14 +0200214 */
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100215#define SND_SOC_CLOCK_IN 0
216#define SND_SOC_CLOCK_OUT 1
Richard Purdie808db4a2006-10-06 18:20:14 +0200217
218/*
219 * AC97 codec ID's bitmask
220 */
221#define SND_SOC_DAI_AC97_ID0 (1 << 0)
222#define SND_SOC_DAI_AC97_ID1 (1 << 1)
223#define SND_SOC_DAI_AC97_ID2 (1 << 2)
224#define SND_SOC_DAI_AC97_ID3 (1 << 3)
225
226struct snd_soc_device;
227struct snd_soc_pcm_stream;
228struct snd_soc_ops;
229struct snd_soc_dai_mode;
230struct snd_soc_pcm_runtime;
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100231struct snd_soc_dai;
Richard Purdie808db4a2006-10-06 18:20:14 +0200232struct snd_soc_codec;
233struct snd_soc_machine_config;
234struct soc_enum;
235struct snd_soc_ac97_ops;
236struct snd_soc_clock_info;
237
238typedef int (*hw_write_t)(void *,const char* ,int);
239typedef int (*hw_read_t)(void *,char* ,int);
240
241extern struct snd_ac97_bus_ops soc_ac97_ops;
242
243/* pcm <-> DAI connect */
244void snd_soc_free_pcms(struct snd_soc_device *socdev);
245int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid);
246int snd_soc_register_card(struct snd_soc_device *socdev);
247
248/* set runtime hw params */
249int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
250 const struct snd_pcm_hardware *hw);
Richard Purdie808db4a2006-10-06 18:20:14 +0200251
252/* codec IO */
253#define snd_soc_read(codec, reg) codec->read(codec, reg)
254#define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
255
256/* codec register bit access */
257int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
258 unsigned short mask, unsigned short value);
259int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
260 unsigned short mask, unsigned short value);
261
262int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
263 struct snd_ac97_bus_ops *ops, int num);
264void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
265
Liam Girdwood8c6529d2008-07-08 13:19:13 +0100266/* Digital Audio Interface clocking API.*/
267int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
268 unsigned int freq, int dir);
269
270int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
271 int div_id, int div);
272
273int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
274 int pll_id, unsigned int freq_in, unsigned int freq_out);
275
276/* Digital Audio interface formatting */
277int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
278
279int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
280 unsigned int mask, int slots);
281
282int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);
283
284/* Digital Audio Interface mute */
285int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute);
286
Richard Purdie808db4a2006-10-06 18:20:14 +0200287/*
288 *Controls
289 */
290struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
291 void *data, char *long_name);
292int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_info *uinfo);
294int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
295 struct snd_ctl_elem_info *uinfo);
296int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
297 struct snd_ctl_elem_value *ucontrol);
298int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
299 struct snd_ctl_elem_value *ucontrol);
300int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
301 struct snd_ctl_elem_info *uinfo);
302int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
303 struct snd_ctl_elem_info *uinfo);
Philipp Zabel392abe92008-05-13 14:03:40 +0200304#define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
Richard Purdie808db4a2006-10-06 18:20:14 +0200305int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
306 struct snd_ctl_elem_value *ucontrol);
307int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
308 struct snd_ctl_elem_value *ucontrol);
309int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
310 struct snd_ctl_elem_info *uinfo);
311int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
312 struct snd_ctl_elem_value *ucontrol);
313int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
314 struct snd_ctl_elem_value *ucontrol);
Mark Browne13ac2e2008-05-28 17:58:05 +0100315int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
316 struct snd_ctl_elem_info *uinfo);
317int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
318 struct snd_ctl_elem_value *ucontrol);
319int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
320 struct snd_ctl_elem_value *ucontrol);
Richard Purdie808db4a2006-10-06 18:20:14 +0200321
322/* SoC PCM stream information */
323struct snd_soc_pcm_stream {
324 char *stream_name;
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100325 u64 formats; /* SNDRV_PCM_FMTBIT_* */
326 unsigned int rates; /* SNDRV_PCM_RATE_* */
Richard Purdie808db4a2006-10-06 18:20:14 +0200327 unsigned int rate_min; /* min rate */
328 unsigned int rate_max; /* max rate */
329 unsigned int channels_min; /* min channels */
330 unsigned int channels_max; /* max channels */
331 unsigned int active:1; /* stream is in use */
332};
333
334/* SoC audio ops */
335struct snd_soc_ops {
336 int (*startup)(struct snd_pcm_substream *);
337 void (*shutdown)(struct snd_pcm_substream *);
338 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
339 int (*hw_free)(struct snd_pcm_substream *);
340 int (*prepare)(struct snd_pcm_substream *);
341 int (*trigger)(struct snd_pcm_substream *, int);
342};
343
Mark Brown1ef6ab72008-05-19 12:31:55 +0200344/* ASoC DAI ops */
345struct snd_soc_dai_ops {
346 /* DAI clocking configuration */
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100347 int (*set_sysclk)(struct snd_soc_dai *dai,
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100348 int clk_id, unsigned int freq, int dir);
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100349 int (*set_pll)(struct snd_soc_dai *dai,
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100350 int pll_id, unsigned int freq_in, unsigned int freq_out);
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100351 int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100352
Mark Brown1ef6ab72008-05-19 12:31:55 +0200353 /* DAI format configuration */
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100354 int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
355 int (*set_tdm_slot)(struct snd_soc_dai *dai,
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100356 unsigned int mask, int slots);
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100357 int (*set_tristate)(struct snd_soc_dai *dai, int tristate);
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100358
359 /* digital mute */
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100360 int (*digital_mute)(struct snd_soc_dai *dai, int mute);
Richard Purdie808db4a2006-10-06 18:20:14 +0200361};
362
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100363/* SoC DAI (Digital Audio Interface) */
364struct snd_soc_dai {
Richard Purdie808db4a2006-10-06 18:20:14 +0200365 /* DAI description */
366 char *name;
367 unsigned int id;
368 unsigned char type;
369
370 /* DAI callbacks */
Mark Brownbdb92872008-06-11 13:47:10 +0100371 int (*probe)(struct platform_device *pdev,
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100372 struct snd_soc_dai *dai);
Mark Brownbdb92872008-06-11 13:47:10 +0100373 void (*remove)(struct platform_device *pdev,
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100374 struct snd_soc_dai *dai);
Richard Purdie808db4a2006-10-06 18:20:14 +0200375 int (*suspend)(struct platform_device *pdev,
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100376 struct snd_soc_dai *dai);
Richard Purdie808db4a2006-10-06 18:20:14 +0200377 int (*resume)(struct platform_device *pdev,
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100378 struct snd_soc_dai *dai);
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100379
380 /* ops */
381 struct snd_soc_ops ops;
Mark Brown1ef6ab72008-05-19 12:31:55 +0200382 struct snd_soc_dai_ops dai_ops;
Richard Purdie808db4a2006-10-06 18:20:14 +0200383
384 /* DAI capabilities */
385 struct snd_soc_pcm_stream capture;
386 struct snd_soc_pcm_stream playback;
Richard Purdie808db4a2006-10-06 18:20:14 +0200387
388 /* DAI runtime info */
Richard Purdie808db4a2006-10-06 18:20:14 +0200389 struct snd_pcm_runtime *runtime;
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100390 struct snd_soc_codec *codec;
391 unsigned int active;
392 unsigned char pop_wait:1;
Richard Purdie808db4a2006-10-06 18:20:14 +0200393 void *dma_data;
394
395 /* DAI private data */
396 void *private_data;
397};
398
399/* SoC Audio Codec */
400struct snd_soc_codec {
401 char *name;
402 struct module *owner;
403 struct mutex mutex;
404
405 /* callbacks */
Mark Brown0be98982008-05-19 12:31:28 +0200406 int (*set_bias_level)(struct snd_soc_codec *,
407 enum snd_soc_bias_level level);
Richard Purdie808db4a2006-10-06 18:20:14 +0200408
409 /* runtime */
410 struct snd_card *card;
411 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
412 unsigned int active;
413 unsigned int pcm_devs;
414 void *private_data;
415
416 /* codec IO */
417 void *control_data; /* codec control (i2c/3wire) data */
418 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
419 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
Mark Brown58cd33c2008-07-29 11:42:25 +0100420 int (*display_register)(struct snd_soc_codec *, char *,
421 size_t, unsigned int);
Richard Purdie808db4a2006-10-06 18:20:14 +0200422 hw_write_t hw_write;
423 hw_read_t hw_read;
424 void *reg_cache;
425 short reg_cache_size;
426 short reg_cache_step;
427
428 /* dapm */
429 struct list_head dapm_widgets;
430 struct list_head dapm_paths;
Mark Brown0be98982008-05-19 12:31:28 +0200431 enum snd_soc_bias_level bias_level;
432 enum snd_soc_bias_level suspend_bias_level;
Takashi Iwai1321b162006-12-21 11:02:06 +0100433 struct delayed_work delayed_work;
Richard Purdie808db4a2006-10-06 18:20:14 +0200434
435 /* codec DAI's */
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100436 struct snd_soc_dai *dai;
Richard Purdie808db4a2006-10-06 18:20:14 +0200437 unsigned int num_dai;
438};
439
440/* codec device */
441struct snd_soc_codec_device {
442 int (*probe)(struct platform_device *pdev);
443 int (*remove)(struct platform_device *pdev);
444 int (*suspend)(struct platform_device *pdev, pm_message_t state);
445 int (*resume)(struct platform_device *pdev);
446};
447
448/* SoC platform interface */
449struct snd_soc_platform {
450 char *name;
451
452 int (*probe)(struct platform_device *pdev);
453 int (*remove)(struct platform_device *pdev);
454 int (*suspend)(struct platform_device *pdev,
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100455 struct snd_soc_dai *dai);
Richard Purdie808db4a2006-10-06 18:20:14 +0200456 int (*resume)(struct platform_device *pdev,
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100457 struct snd_soc_dai *dai);
Richard Purdie808db4a2006-10-06 18:20:14 +0200458
459 /* pcm creation and destruction */
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100460 int (*pcm_new)(struct snd_card *, struct snd_soc_dai *,
Richard Purdie808db4a2006-10-06 18:20:14 +0200461 struct snd_pcm *);
462 void (*pcm_free)(struct snd_pcm *);
463
464 /* platform stream ops */
465 struct snd_pcm_ops *pcm_ops;
466};
467
468/* SoC machine DAI configuration, glues a codec and cpu DAI together */
469struct snd_soc_dai_link {
470 char *name; /* Codec name */
471 char *stream_name; /* Stream name */
472
473 /* DAI */
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100474 struct snd_soc_dai *codec_dai;
475 struct snd_soc_dai *cpu_dai;
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100476
477 /* machine stream operations */
478 struct snd_soc_ops *ops;
Richard Purdie808db4a2006-10-06 18:20:14 +0200479
480 /* codec/machine specific init - e.g. add machine controls */
481 int (*init)(struct snd_soc_codec *codec);
Liam Girdwood4ccab3e2008-01-10 14:39:01 +0100482
483 /* DAI pcm */
484 struct snd_pcm *pcm;
Richard Purdie808db4a2006-10-06 18:20:14 +0200485};
486
487/* SoC machine */
488struct snd_soc_machine {
489 char *name;
490
491 int (*probe)(struct platform_device *pdev);
492 int (*remove)(struct platform_device *pdev);
493
494 /* the pre and post PM functions are used to do any PM work before and
495 * after the codec and DAI's do any PM work. */
496 int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
497 int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
498 int (*resume_pre)(struct platform_device *pdev);
499 int (*resume_post)(struct platform_device *pdev);
500
Liam Girdwood0b4d2212008-01-10 14:36:20 +0100501 /* callbacks */
Mark Brown0be98982008-05-19 12:31:28 +0200502 int (*set_bias_level)(struct snd_soc_machine *,
503 enum snd_soc_bias_level level);
Liam Girdwood0b4d2212008-01-10 14:36:20 +0100504
Richard Purdie808db4a2006-10-06 18:20:14 +0200505 /* CPU <--> Codec DAI links */
506 struct snd_soc_dai_link *dai_link;
507 int num_links;
508};
509
510/* SoC Device - the audio subsystem */
511struct snd_soc_device {
512 struct device *dev;
513 struct snd_soc_machine *machine;
514 struct snd_soc_platform *platform;
515 struct snd_soc_codec *codec;
516 struct snd_soc_codec_device *codec_dev;
Andrew Morton4484bb22006-12-15 09:30:07 +0100517 struct delayed_work delayed_work;
Andy Green6ed25972008-06-13 16:24:05 +0100518 struct work_struct deferred_resume_work;
Richard Purdie808db4a2006-10-06 18:20:14 +0200519 void *codec_data;
520};
521
522/* runtime channel data */
523struct snd_soc_pcm_runtime {
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100524 struct snd_soc_dai_link *dai;
Richard Purdie808db4a2006-10-06 18:20:14 +0200525 struct snd_soc_device *socdev;
526};
527
Jon Smirl4eaa9812008-07-29 11:42:26 +0100528/* mixer control */
529struct soc_mixer_control {
530 int min, max;
Jon Smirl815ecf8d2008-07-29 10:22:24 -0400531 unsigned int reg, rreg, shift, rshift, invert;
Jon Smirl4eaa9812008-07-29 11:42:26 +0100532};
533
Richard Purdie808db4a2006-10-06 18:20:14 +0200534/* enumerated kcontrol */
535struct soc_enum {
536 unsigned short reg;
537 unsigned short reg2;
538 unsigned char shift_l;
539 unsigned char shift_r;
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100540 unsigned int max;
Richard Purdie808db4a2006-10-06 18:20:14 +0200541 const char **texts;
542 void *dapm;
543};
544
Richard Purdie808db4a2006-10-06 18:20:14 +0200545#endif