ASoC: tlv320aic3x: headset/button press support
[linux-2.6-block.git] / include / sound / soc.h
CommitLineData
808db4a4
RP
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>
4484bb2e 18#include <linux/workqueue.h>
808db4a4
RP
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/control.h>
22#include <sound/ac97_codec.h>
23
808db4a4
RP
24/*
25 * Convenience kcontrol builders
26 */
4eaa9819
JS
27#define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) \
28 ((unsigned long)&(struct soc_mixer_control) \
762b8df7
MB
29 {.reg = xreg, .shift = xshift, .rshift = xshift, .max = xmax, \
30 .invert = xinvert})
4eaa9819
JS
31#define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
32 ((unsigned long)&(struct soc_mixer_control) \
33 {.reg = xreg, .max = xmax, .invert = xinvert})
a7a4ac86 34#define SOC_SINGLE(xname, reg, shift, max, invert) \
808db4a4
RP
35{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
36 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
37 .put = snd_soc_put_volsw, \
a7a4ac86
PZ
38 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
39#define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
40{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
41 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
42 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
43 .tlv.p = (tlv_array), \
44 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
45 .put = snd_soc_put_volsw, \
46 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
4eaa9819 47#define SOC_DOUBLE(xname, xreg, shift_left, shift_right, xmax, xinvert) \
808db4a4
RP
48{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
49 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
50 .put = snd_soc_put_volsw, \
4eaa9819
JS
51 .private_value = (unsigned long)&(struct soc_mixer_control) \
52 {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
53 .max = xmax, .invert = xinvert} }
54#define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
808db4a4
RP
55{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
56 .info = snd_soc_info_volsw_2r, \
57 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
4eaa9819
JS
58 .private_value = (unsigned long)&(struct soc_mixer_control) \
59 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
60 .max = xmax, .invert = xinvert} }
61#define SOC_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert, tlv_array) \
a7a4ac86
PZ
62{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
63 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
64 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
65 .tlv.p = (tlv_array), \
66 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
67 .put = snd_soc_put_volsw, \
4eaa9819
JS
68 .private_value = (unsigned long)&(struct soc_mixer_control) \
69 {.reg = xreg, .shift = shift_left, .rshift = shift_right,\
70 .max = xmax, .invert = xinvert} }
71#define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
a7a4ac86
PZ
72{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
73 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
74 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
75 .tlv.p = (tlv_array), \
76 .info = snd_soc_info_volsw_2r, \
77 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
4eaa9819
JS
78 .private_value = (unsigned long)&(struct soc_mixer_control) \
79 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
80 .max = xmax, .invert = xinvert} }
81#define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
e13ac2e9
MB
82{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
83 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
84 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
85 .tlv.p = (tlv_array), \
86 .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
87 .put = snd_soc_put_volsw_s8, \
4eaa9819
JS
88 .private_value = (unsigned long)&(struct soc_mixer_control) \
89 {.reg = xreg, .min = xmin, .max = xmax} }
f8ba0b7b 90#define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmax, xtexts) \
808db4a4 91{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
f8ba0b7b
JS
92 .max = xmax, .texts = xtexts }
93#define SOC_ENUM_SINGLE(xreg, xshift, xmax, xtexts) \
94 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmax, xtexts)
95#define SOC_ENUM_SINGLE_EXT(xmax, xtexts) \
96{ .max = xmax, .texts = xtexts }
808db4a4
RP
97#define SOC_ENUM(xname, xenum) \
98{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
99 .info = snd_soc_info_enum_double, \
100 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
101 .private_value = (unsigned long)&xenum }
f8ba0b7b 102#define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
808db4a4
RP
103 xhandler_get, xhandler_put) \
104{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1c433fbd 105 .info = snd_soc_info_volsw, \
808db4a4 106 .get = xhandler_get, .put = xhandler_put, \
f8ba0b7b
JS
107 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
108#define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
10144c09
MM
109 xhandler_get, xhandler_put, tlv_array) \
110{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
111 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
112 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
113 .tlv.p = (tlv_array), \
114 .info = snd_soc_info_volsw, \
115 .get = xhandler_get, .put = xhandler_put, \
f8ba0b7b 116 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
808db4a4
RP
117#define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
118{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
119 .info = snd_soc_info_bool_ext, \
120 .get = xhandler_get, .put = xhandler_put, \
121 .private_value = xdata }
122#define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
123{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
124 .info = snd_soc_info_enum_ext, \
125 .get = xhandler_get, .put = xhandler_put, \
126 .private_value = (unsigned long)&xenum }
127
0be9898a
MB
128/*
129 * Bias levels
130 *
131 * @ON: Bias is fully on for audio playback and capture operations.
132 * @PREPARE: Prepare for audio operations. Called before DAPM switching for
133 * stream start and stop operations.
134 * @STANDBY: Low power standby state when no playback/capture operations are
135 * in progress. NOTE: The transition time between STANDBY and ON
136 * should be as fast as possible and no longer than 10ms.
137 * @OFF: Power Off. No restrictions on transition times.
138 */
139enum snd_soc_bias_level {
140 SND_SOC_BIAS_ON,
141 SND_SOC_BIAS_PREPARE,
142 SND_SOC_BIAS_STANDBY,
143 SND_SOC_BIAS_OFF,
144};
145
808db4a4
RP
146struct snd_soc_device;
147struct snd_soc_pcm_stream;
148struct snd_soc_ops;
149struct snd_soc_dai_mode;
150struct snd_soc_pcm_runtime;
3c4b266f 151struct snd_soc_dai;
808db4a4 152struct snd_soc_codec;
808db4a4
RP
153struct soc_enum;
154struct snd_soc_ac97_ops;
155struct snd_soc_clock_info;
156
157typedef int (*hw_write_t)(void *,const char* ,int);
158typedef int (*hw_read_t)(void *,char* ,int);
159
160extern struct snd_ac97_bus_ops soc_ac97_ops;
161
162/* pcm <-> DAI connect */
163void snd_soc_free_pcms(struct snd_soc_device *socdev);
164int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid);
968a6025 165int snd_soc_init_card(struct snd_soc_device *socdev);
808db4a4
RP
166
167/* set runtime hw params */
168int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
169 const struct snd_pcm_hardware *hw);
808db4a4
RP
170
171/* codec IO */
172#define snd_soc_read(codec, reg) codec->read(codec, reg)
173#define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
174
175/* codec register bit access */
176int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
177 unsigned short mask, unsigned short value);
178int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
179 unsigned short mask, unsigned short value);
180
181int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
182 struct snd_ac97_bus_ops *ops, int num);
183void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
184
185/*
186 *Controls
187 */
188struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
189 void *data, char *long_name);
190int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
191 struct snd_ctl_elem_info *uinfo);
192int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
193 struct snd_ctl_elem_info *uinfo);
194int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
195 struct snd_ctl_elem_value *ucontrol);
196int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
197 struct snd_ctl_elem_value *ucontrol);
198int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
199 struct snd_ctl_elem_info *uinfo);
200int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
201 struct snd_ctl_elem_info *uinfo);
392abe9c 202#define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
808db4a4
RP
203int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
204 struct snd_ctl_elem_value *ucontrol);
205int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
206 struct snd_ctl_elem_value *ucontrol);
207int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
208 struct snd_ctl_elem_info *uinfo);
209int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
210 struct snd_ctl_elem_value *ucontrol);
211int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
212 struct snd_ctl_elem_value *ucontrol);
e13ac2e9
MB
213int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
214 struct snd_ctl_elem_info *uinfo);
215int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
216 struct snd_ctl_elem_value *ucontrol);
217int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
218 struct snd_ctl_elem_value *ucontrol);
808db4a4
RP
219
220/* SoC PCM stream information */
221struct snd_soc_pcm_stream {
222 char *stream_name;
1c433fbd
GG
223 u64 formats; /* SNDRV_PCM_FMTBIT_* */
224 unsigned int rates; /* SNDRV_PCM_RATE_* */
808db4a4
RP
225 unsigned int rate_min; /* min rate */
226 unsigned int rate_max; /* max rate */
227 unsigned int channels_min; /* min channels */
228 unsigned int channels_max; /* max channels */
229 unsigned int active:1; /* stream is in use */
230};
231
232/* SoC audio ops */
233struct snd_soc_ops {
234 int (*startup)(struct snd_pcm_substream *);
235 void (*shutdown)(struct snd_pcm_substream *);
236 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
237 int (*hw_free)(struct snd_pcm_substream *);
238 int (*prepare)(struct snd_pcm_substream *);
239 int (*trigger)(struct snd_pcm_substream *, int);
240};
241
808db4a4
RP
242/* SoC Audio Codec */
243struct snd_soc_codec {
244 char *name;
245 struct module *owner;
246 struct mutex mutex;
247
248 /* callbacks */
0be9898a
MB
249 int (*set_bias_level)(struct snd_soc_codec *,
250 enum snd_soc_bias_level level);
808db4a4
RP
251
252 /* runtime */
253 struct snd_card *card;
254 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
255 unsigned int active;
256 unsigned int pcm_devs;
257 void *private_data;
258
259 /* codec IO */
260 void *control_data; /* codec control (i2c/3wire) data */
261 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
262 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
58cd33c0
MB
263 int (*display_register)(struct snd_soc_codec *, char *,
264 size_t, unsigned int);
808db4a4
RP
265 hw_write_t hw_write;
266 hw_read_t hw_read;
267 void *reg_cache;
268 short reg_cache_size;
269 short reg_cache_step;
270
271 /* dapm */
12ef193d 272 u32 pop_time;
808db4a4
RP
273 struct list_head dapm_widgets;
274 struct list_head dapm_paths;
0be9898a
MB
275 enum snd_soc_bias_level bias_level;
276 enum snd_soc_bias_level suspend_bias_level;
1321b160 277 struct delayed_work delayed_work;
808db4a4
RP
278
279 /* codec DAI's */
3c4b266f 280 struct snd_soc_dai *dai;
808db4a4
RP
281 unsigned int num_dai;
282};
283
284/* codec device */
285struct snd_soc_codec_device {
286 int (*probe)(struct platform_device *pdev);
287 int (*remove)(struct platform_device *pdev);
288 int (*suspend)(struct platform_device *pdev, pm_message_t state);
289 int (*resume)(struct platform_device *pdev);
290};
291
292/* SoC platform interface */
293struct snd_soc_platform {
294 char *name;
295
296 int (*probe)(struct platform_device *pdev);
297 int (*remove)(struct platform_device *pdev);
298 int (*suspend)(struct platform_device *pdev,
3c4b266f 299 struct snd_soc_dai *dai);
808db4a4 300 int (*resume)(struct platform_device *pdev,
3c4b266f 301 struct snd_soc_dai *dai);
808db4a4
RP
302
303 /* pcm creation and destruction */
3c4b266f 304 int (*pcm_new)(struct snd_card *, struct snd_soc_dai *,
808db4a4
RP
305 struct snd_pcm *);
306 void (*pcm_free)(struct snd_pcm *);
307
308 /* platform stream ops */
309 struct snd_pcm_ops *pcm_ops;
310};
311
312/* SoC machine DAI configuration, glues a codec and cpu DAI together */
313struct snd_soc_dai_link {
314 char *name; /* Codec name */
315 char *stream_name; /* Stream name */
316
317 /* DAI */
3c4b266f
LG
318 struct snd_soc_dai *codec_dai;
319 struct snd_soc_dai *cpu_dai;
1c433fbd
GG
320
321 /* machine stream operations */
322 struct snd_soc_ops *ops;
808db4a4
RP
323
324 /* codec/machine specific init - e.g. add machine controls */
325 int (*init)(struct snd_soc_codec *codec);
4ccab3e7
LG
326
327 /* DAI pcm */
328 struct snd_pcm *pcm;
808db4a4
RP
329};
330
87506549
MB
331/* SoC card */
332struct snd_soc_card {
808db4a4
RP
333 char *name;
334
335 int (*probe)(struct platform_device *pdev);
336 int (*remove)(struct platform_device *pdev);
337
338 /* the pre and post PM functions are used to do any PM work before and
339 * after the codec and DAI's do any PM work. */
340 int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
341 int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
342 int (*resume_pre)(struct platform_device *pdev);
343 int (*resume_post)(struct platform_device *pdev);
344
0b4d221b 345 /* callbacks */
87506549 346 int (*set_bias_level)(struct snd_soc_card *,
0be9898a 347 enum snd_soc_bias_level level);
0b4d221b 348
808db4a4
RP
349 /* CPU <--> Codec DAI links */
350 struct snd_soc_dai_link *dai_link;
351 int num_links;
6308419a
MB
352
353 struct snd_soc_device *socdev;
354
87689d56 355 struct snd_soc_platform *platform;
6308419a
MB
356 struct delayed_work delayed_work;
357 struct work_struct deferred_resume_work;
808db4a4
RP
358};
359
360/* SoC Device - the audio subsystem */
361struct snd_soc_device {
362 struct device *dev;
87506549 363 struct snd_soc_card *card;
808db4a4
RP
364 struct snd_soc_codec *codec;
365 struct snd_soc_codec_device *codec_dev;
366 void *codec_data;
12ef193d
TK
367#ifdef CONFIG_DEBUG_FS
368 struct dentry *debugfs_root;
369#endif
808db4a4
RP
370};
371
372/* runtime channel data */
373struct snd_soc_pcm_runtime {
1c433fbd 374 struct snd_soc_dai_link *dai;
808db4a4
RP
375 struct snd_soc_device *socdev;
376};
377
4eaa9819
JS
378/* mixer control */
379struct soc_mixer_control {
380 int min, max;
815ecf8d 381 unsigned int reg, rreg, shift, rshift, invert;
4eaa9819
JS
382};
383
808db4a4
RP
384/* enumerated kcontrol */
385struct soc_enum {
386 unsigned short reg;
387 unsigned short reg2;
388 unsigned char shift_l;
389 unsigned char shift_r;
f8ba0b7b 390 unsigned int max;
808db4a4
RP
391 const char **texts;
392 void *dapm;
393};
394
a47cbe72
MB
395#include <sound/soc-dai.h>
396
808db4a4 397#endif