blob: c22c65650405351f5241b2f13eba7d303cb8ac4c [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
Liam Girdwooda68660e2007-05-10 19:27:27 +020024#define SND_SOC_VERSION "0.13.1"
Richard Purdie808db4a2006-10-06 18:20:14 +020025
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 }
Graeme Gregory1c433fb2007-02-02 17:13:05 +010062#define SOC_SINGLE_EXT(xname, xreg, xshift, xmask, xinvert,\
Richard Purdie808db4a2006-10-06 18:20:14 +020063 xhandler_get, xhandler_put) \
64{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
Graeme Gregory1c433fb2007-02-02 17:13:05 +010065 .info = snd_soc_info_volsw, \
Richard Purdie808db4a2006-10-06 18:20:14 +020066 .get = xhandler_get, .put = xhandler_put, \
Graeme Gregory1c433fb2007-02-02 17:13:05 +010067 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmask, xinvert) }
Richard Purdie808db4a2006-10-06 18:20:14 +020068#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
Liam Girdwooda68660e2007-05-10 19:27:27 +020085#define SND_SOC_DAI_AC97_BUS 0x8 /* for custom i.e. non ac97_codec.c */
Richard Purdie808db4a2006-10-06 18:20:14 +020086
87/*
88 * DAI hardware audio formats
89 */
Graeme Gregory1c433fb2007-02-02 17:13:05 +010090#define SND_SOC_DAIFMT_I2S 0 /* I2S mode */
91#define SND_SOC_DAIFMT_RIGHT_J 1 /* Right justified mode */
92#define SND_SOC_DAIFMT_LEFT_J 2 /* Left Justified mode */
93#define SND_SOC_DAIFMT_DSP_A 3 /* L data msb after FRM or LRC */
94#define SND_SOC_DAIFMT_DSP_B 4 /* L data msb during FRM or LRC */
95#define SND_SOC_DAIFMT_AC97 5 /* AC97 */
96
97#define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
98#define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
99
100/*
101 * DAI Gating
102 */
103#define SND_SOC_DAIFMT_CONT (0 << 4) /* continuous clock */
104#define SND_SOC_DAIFMT_GATED (1 << 4) /* clock is gated when not Tx/Rx */
Richard Purdie808db4a2006-10-06 18:20:14 +0200105
106/*
107 * DAI hardware signal inversions
108 */
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100109#define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bit clock + frame */
110#define SND_SOC_DAIFMT_NB_IF (1 << 8) /* normal bclk + inv frm */
111#define SND_SOC_DAIFMT_IB_NF (2 << 8) /* invert bclk + nor frm */
112#define SND_SOC_DAIFMT_IB_IF (3 << 8) /* invert bclk + frm */
Richard Purdie808db4a2006-10-06 18:20:14 +0200113
114/*
115 * DAI hardware clock masters
116 * This is wrt the codec, the inverse is true for the interface
117 * i.e. if the codec is clk and frm master then the interface is
118 * clk and frame slave.
119 */
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100120#define SND_SOC_DAIFMT_CBM_CFM (0 << 12) /* codec clk & frm master */
121#define SND_SOC_DAIFMT_CBS_CFM (1 << 12) /* codec clk slave & frm master */
122#define SND_SOC_DAIFMT_CBM_CFS (2 << 12) /* codec clk master & frame slave */
123#define SND_SOC_DAIFMT_CBS_CFS (3 << 12) /* codec clk & frm slave */
Richard Purdie808db4a2006-10-06 18:20:14 +0200124
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100125#define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
126#define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
Richard Purdie808db4a2006-10-06 18:20:14 +0200127#define SND_SOC_DAIFMT_INV_MASK 0x0f00
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100128#define SND_SOC_DAIFMT_MASTER_MASK 0xf000
129
Richard Purdie808db4a2006-10-06 18:20:14 +0200130
131/*
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100132 * Master Clock Directions
Richard Purdie808db4a2006-10-06 18:20:14 +0200133 */
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100134#define SND_SOC_CLOCK_IN 0
135#define SND_SOC_CLOCK_OUT 1
Richard Purdie808db4a2006-10-06 18:20:14 +0200136
137/*
138 * AC97 codec ID's bitmask
139 */
140#define SND_SOC_DAI_AC97_ID0 (1 << 0)
141#define SND_SOC_DAI_AC97_ID1 (1 << 1)
142#define SND_SOC_DAI_AC97_ID2 (1 << 2)
143#define SND_SOC_DAI_AC97_ID3 (1 << 3)
144
145struct snd_soc_device;
146struct snd_soc_pcm_stream;
147struct snd_soc_ops;
148struct snd_soc_dai_mode;
149struct snd_soc_pcm_runtime;
150struct snd_soc_codec_dai;
151struct snd_soc_cpu_dai;
152struct snd_soc_codec;
153struct snd_soc_machine_config;
154struct soc_enum;
155struct snd_soc_ac97_ops;
156struct snd_soc_clock_info;
157
158typedef int (*hw_write_t)(void *,const char* ,int);
159typedef int (*hw_read_t)(void *,char* ,int);
160
161extern struct snd_ac97_bus_ops soc_ac97_ops;
162
163/* pcm <-> DAI connect */
164void snd_soc_free_pcms(struct snd_soc_device *socdev);
165int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid);
166int snd_soc_register_card(struct snd_soc_device *socdev);
167
168/* set runtime hw params */
169int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
170 const struct snd_pcm_hardware *hw);
Richard Purdie808db4a2006-10-06 18:20:14 +0200171
172/* codec IO */
173#define snd_soc_read(codec, reg) codec->read(codec, reg)
174#define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
175
176/* codec register bit access */
177int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
178 unsigned short mask, unsigned short value);
179int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
180 unsigned short mask, unsigned short value);
181
182int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
183 struct snd_ac97_bus_ops *ops, int num);
184void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
185
186/*
187 *Controls
188 */
189struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
190 void *data, char *long_name);
191int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
192 struct snd_ctl_elem_info *uinfo);
193int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
194 struct snd_ctl_elem_info *uinfo);
195int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
196 struct snd_ctl_elem_value *ucontrol);
197int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
198 struct snd_ctl_elem_value *ucontrol);
199int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
200 struct snd_ctl_elem_info *uinfo);
201int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
202 struct snd_ctl_elem_info *uinfo);
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200203#define snd_soc_info_bool_ext snd_ctl_boolean_mono
Richard Purdie808db4a2006-10-06 18:20:14 +0200204int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
205 struct snd_ctl_elem_value *ucontrol);
206int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
207 struct snd_ctl_elem_value *ucontrol);
208int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
209 struct snd_ctl_elem_info *uinfo);
210int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
211 struct snd_ctl_elem_value *ucontrol);
212int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
213 struct snd_ctl_elem_value *ucontrol);
214
215/* SoC PCM stream information */
216struct snd_soc_pcm_stream {
217 char *stream_name;
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100218 u64 formats; /* SNDRV_PCM_FMTBIT_* */
219 unsigned int rates; /* SNDRV_PCM_RATE_* */
Richard Purdie808db4a2006-10-06 18:20:14 +0200220 unsigned int rate_min; /* min rate */
221 unsigned int rate_max; /* max rate */
222 unsigned int channels_min; /* min channels */
223 unsigned int channels_max; /* max channels */
224 unsigned int active:1; /* stream is in use */
225};
226
227/* SoC audio ops */
228struct snd_soc_ops {
229 int (*startup)(struct snd_pcm_substream *);
230 void (*shutdown)(struct snd_pcm_substream *);
231 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
232 int (*hw_free)(struct snd_pcm_substream *);
233 int (*prepare)(struct snd_pcm_substream *);
234 int (*trigger)(struct snd_pcm_substream *, int);
235};
236
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100237/* ASoC codec DAI ops */
238struct snd_soc_codec_ops {
239 /* codec DAI clocking configuration */
240 int (*set_sysclk)(struct snd_soc_codec_dai *codec_dai,
241 int clk_id, unsigned int freq, int dir);
242 int (*set_pll)(struct snd_soc_codec_dai *codec_dai,
243 int pll_id, unsigned int freq_in, unsigned int freq_out);
244 int (*set_clkdiv)(struct snd_soc_codec_dai *codec_dai,
245 int div_id, int div);
246
247 /* CPU DAI format configuration */
248 int (*set_fmt)(struct snd_soc_codec_dai *codec_dai,
249 unsigned int fmt);
250 int (*set_tdm_slot)(struct snd_soc_codec_dai *codec_dai,
251 unsigned int mask, int slots);
252 int (*set_tristate)(struct snd_soc_codec_dai *, int tristate);
253
254 /* digital mute */
255 int (*digital_mute)(struct snd_soc_codec_dai *, int mute);
Richard Purdie808db4a2006-10-06 18:20:14 +0200256};
257
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100258/* ASoC cpu DAI ops */
259struct snd_soc_cpu_ops {
260 /* CPU DAI clocking configuration */
261 int (*set_sysclk)(struct snd_soc_cpu_dai *cpu_dai,
262 int clk_id, unsigned int freq, int dir);
263 int (*set_clkdiv)(struct snd_soc_cpu_dai *cpu_dai,
264 int div_id, int div);
265 int (*set_pll)(struct snd_soc_cpu_dai *cpu_dai,
266 int pll_id, unsigned int freq_in, unsigned int freq_out);
267
268 /* CPU DAI format configuration */
269 int (*set_fmt)(struct snd_soc_cpu_dai *cpu_dai,
270 unsigned int fmt);
271 int (*set_tdm_slot)(struct snd_soc_cpu_dai *cpu_dai,
272 unsigned int mask, int slots);
273 int (*set_tristate)(struct snd_soc_cpu_dai *, int tristate);
Richard Purdie808db4a2006-10-06 18:20:14 +0200274};
275
276/* SoC Codec DAI */
277struct snd_soc_codec_dai {
278 char *name;
279 int id;
Liam Girdwooda68660e2007-05-10 19:27:27 +0200280 unsigned char type;
Richard Purdie808db4a2006-10-06 18:20:14 +0200281
282 /* DAI capabilities */
283 struct snd_soc_pcm_stream playback;
284 struct snd_soc_pcm_stream capture;
Richard Purdie808db4a2006-10-06 18:20:14 +0200285
286 /* DAI runtime info */
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100287 struct snd_soc_codec *codec;
Richard Purdie808db4a2006-10-06 18:20:14 +0200288 unsigned int active;
289 unsigned char pop_wait:1;
290
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100291 /* ops */
292 struct snd_soc_ops ops;
293 struct snd_soc_codec_ops dai_ops;
294
Richard Purdie808db4a2006-10-06 18:20:14 +0200295 /* DAI private data */
296 void *private_data;
297};
298
299/* SoC CPU DAI */
300struct snd_soc_cpu_dai {
301
302 /* DAI description */
303 char *name;
304 unsigned int id;
305 unsigned char type;
306
307 /* DAI callbacks */
308 int (*probe)(struct platform_device *pdev);
309 void (*remove)(struct platform_device *pdev);
310 int (*suspend)(struct platform_device *pdev,
311 struct snd_soc_cpu_dai *cpu_dai);
312 int (*resume)(struct platform_device *pdev,
313 struct snd_soc_cpu_dai *cpu_dai);
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100314
315 /* ops */
316 struct snd_soc_ops ops;
317 struct snd_soc_cpu_ops dai_ops;
Richard Purdie808db4a2006-10-06 18:20:14 +0200318
319 /* DAI capabilities */
320 struct snd_soc_pcm_stream capture;
321 struct snd_soc_pcm_stream playback;
Richard Purdie808db4a2006-10-06 18:20:14 +0200322
323 /* DAI runtime info */
Richard Purdie808db4a2006-10-06 18:20:14 +0200324 struct snd_pcm_runtime *runtime;
325 unsigned char active:1;
Richard Purdie808db4a2006-10-06 18:20:14 +0200326 void *dma_data;
327
328 /* DAI private data */
329 void *private_data;
330};
331
332/* SoC Audio Codec */
333struct snd_soc_codec {
334 char *name;
335 struct module *owner;
336 struct mutex mutex;
337
338 /* callbacks */
339 int (*dapm_event)(struct snd_soc_codec *codec, int event);
340
341 /* runtime */
342 struct snd_card *card;
343 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
344 unsigned int active;
345 unsigned int pcm_devs;
346 void *private_data;
347
348 /* codec IO */
349 void *control_data; /* codec control (i2c/3wire) data */
350 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
351 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
352 hw_write_t hw_write;
353 hw_read_t hw_read;
354 void *reg_cache;
355 short reg_cache_size;
356 short reg_cache_step;
357
358 /* dapm */
359 struct list_head dapm_widgets;
360 struct list_head dapm_paths;
361 unsigned int dapm_state;
362 unsigned int suspend_dapm_state;
Takashi Iwai1321b162006-12-21 11:02:06 +0100363 struct delayed_work delayed_work;
Richard Purdie808db4a2006-10-06 18:20:14 +0200364
365 /* codec DAI's */
366 struct snd_soc_codec_dai *dai;
367 unsigned int num_dai;
368};
369
370/* codec device */
371struct snd_soc_codec_device {
372 int (*probe)(struct platform_device *pdev);
373 int (*remove)(struct platform_device *pdev);
374 int (*suspend)(struct platform_device *pdev, pm_message_t state);
375 int (*resume)(struct platform_device *pdev);
376};
377
378/* SoC platform interface */
379struct snd_soc_platform {
380 char *name;
381
382 int (*probe)(struct platform_device *pdev);
383 int (*remove)(struct platform_device *pdev);
384 int (*suspend)(struct platform_device *pdev,
385 struct snd_soc_cpu_dai *cpu_dai);
386 int (*resume)(struct platform_device *pdev,
387 struct snd_soc_cpu_dai *cpu_dai);
388
389 /* pcm creation and destruction */
390 int (*pcm_new)(struct snd_card *, struct snd_soc_codec_dai *,
391 struct snd_pcm *);
392 void (*pcm_free)(struct snd_pcm *);
393
394 /* platform stream ops */
395 struct snd_pcm_ops *pcm_ops;
396};
397
398/* SoC machine DAI configuration, glues a codec and cpu DAI together */
399struct snd_soc_dai_link {
400 char *name; /* Codec name */
401 char *stream_name; /* Stream name */
402
403 /* DAI */
404 struct snd_soc_codec_dai *codec_dai;
405 struct snd_soc_cpu_dai *cpu_dai;
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100406
407 /* machine stream operations */
408 struct snd_soc_ops *ops;
Richard Purdie808db4a2006-10-06 18:20:14 +0200409
410 /* codec/machine specific init - e.g. add machine controls */
411 int (*init)(struct snd_soc_codec *codec);
Richard Purdie808db4a2006-10-06 18:20:14 +0200412};
413
414/* SoC machine */
415struct snd_soc_machine {
416 char *name;
417
418 int (*probe)(struct platform_device *pdev);
419 int (*remove)(struct platform_device *pdev);
420
421 /* the pre and post PM functions are used to do any PM work before and
422 * after the codec and DAI's do any PM work. */
423 int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
424 int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
425 int (*resume_pre)(struct platform_device *pdev);
426 int (*resume_post)(struct platform_device *pdev);
427
Richard Purdie808db4a2006-10-06 18:20:14 +0200428 /* CPU <--> Codec DAI links */
429 struct snd_soc_dai_link *dai_link;
430 int num_links;
431};
432
433/* SoC Device - the audio subsystem */
434struct snd_soc_device {
435 struct device *dev;
436 struct snd_soc_machine *machine;
437 struct snd_soc_platform *platform;
438 struct snd_soc_codec *codec;
439 struct snd_soc_codec_device *codec_dev;
Andrew Morton4484bb22006-12-15 09:30:07 +0100440 struct delayed_work delayed_work;
Richard Purdie808db4a2006-10-06 18:20:14 +0200441 void *codec_data;
442};
443
444/* runtime channel data */
445struct snd_soc_pcm_runtime {
Graeme Gregory1c433fb2007-02-02 17:13:05 +0100446 struct snd_soc_dai_link *dai;
Richard Purdie808db4a2006-10-06 18:20:14 +0200447 struct snd_soc_device *socdev;
448};
449
450/* enumerated kcontrol */
451struct soc_enum {
452 unsigned short reg;
453 unsigned short reg2;
454 unsigned char shift_l;
455 unsigned char shift_r;
456 unsigned int mask;
457 const char **texts;
458 void *dapm;
459};
460
Richard Purdie808db4a2006-10-06 18:20:14 +0200461#endif