2 * linux/sound/soc.h -- ALSA SoC Layer
4 * Author: Liam Girdwood
5 * Created: Aug 11th 2005
6 * Copyright: Wolfson Microelectronics. PLC.
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.
13 #ifndef __LINUX_SND_SOC_H
14 #define __LINUX_SND_SOC_H
16 #include <linux/platform_device.h>
17 #include <linux/types.h>
18 #include <linux/workqueue.h>
19 #include <sound/driver.h>
20 #include <sound/core.h>
21 #include <sound/pcm.h>
22 #include <sound/control.h>
23 #include <sound/ac97_codec.h>
25 #define SND_SOC_VERSION "0.13.1"
28 * Convenience kcontrol builders
30 #define SOC_SINGLE_VALUE(reg,shift,mask,invert) ((reg) | ((shift) << 8) |\
31 ((shift) << 12) | ((mask) << 16) | ((invert) << 24))
32 #define SOC_SINGLE_VALUE_EXT(reg,mask,invert) ((reg) | ((mask) << 16) |\
34 #define SOC_SINGLE(xname, reg, shift, mask, invert) \
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, \
38 .private_value = SOC_SINGLE_VALUE(reg, shift, mask, invert) }
39 #define SOC_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
40 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
41 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
42 .put = snd_soc_put_volsw, \
43 .private_value = (reg) | ((shift_left) << 8) | \
44 ((shift_right) << 12) | ((mask) << 16) | ((invert) << 24) }
45 #define SOC_DOUBLE_R(xname, reg_left, reg_right, shift, mask, invert) \
46 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
47 .info = snd_soc_info_volsw_2r, \
48 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
49 .private_value = (reg_left) | ((shift) << 8) | \
50 ((mask) << 12) | ((invert) << 20) | ((reg_right) << 24) }
51 #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts) \
52 { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
53 .mask = xmask, .texts = xtexts }
54 #define SOC_ENUM_SINGLE(xreg, xshift, xmask, xtexts) \
55 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xtexts)
56 #define SOC_ENUM_SINGLE_EXT(xmask, xtexts) \
57 { .mask = xmask, .texts = xtexts }
58 #define SOC_ENUM(xname, xenum) \
59 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
60 .info = snd_soc_info_enum_double, \
61 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
62 .private_value = (unsigned long)&xenum }
63 #define SOC_SINGLE_EXT(xname, xreg, xshift, xmask, xinvert,\
64 xhandler_get, xhandler_put) \
65 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
66 .info = snd_soc_info_volsw, \
67 .get = xhandler_get, .put = xhandler_put, \
68 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmask, xinvert) }
69 #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
70 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
71 .info = snd_soc_info_bool_ext, \
72 .get = xhandler_get, .put = xhandler_put, \
73 .private_value = xdata }
74 #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
75 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
76 .info = snd_soc_info_enum_ext, \
77 .get = xhandler_get, .put = xhandler_put, \
78 .private_value = (unsigned long)&xenum }
81 * Digital Audio Interface (DAI) types
83 #define SND_SOC_DAI_AC97 0x1
84 #define SND_SOC_DAI_I2S 0x2
85 #define SND_SOC_DAI_PCM 0x4
86 #define SND_SOC_DAI_AC97_BUS 0x8 /* for custom i.e. non ac97_codec.c */
89 * DAI hardware audio formats
91 #define SND_SOC_DAIFMT_I2S 0 /* I2S mode */
92 #define SND_SOC_DAIFMT_RIGHT_J 1 /* Right justified mode */
93 #define SND_SOC_DAIFMT_LEFT_J 2 /* Left Justified mode */
94 #define SND_SOC_DAIFMT_DSP_A 3 /* L data msb after FRM or LRC */
95 #define SND_SOC_DAIFMT_DSP_B 4 /* L data msb during FRM or LRC */
96 #define SND_SOC_DAIFMT_AC97 5 /* AC97 */
98 #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
99 #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
104 #define SND_SOC_DAIFMT_CONT (0 << 4) /* continuous clock */
105 #define SND_SOC_DAIFMT_GATED (1 << 4) /* clock is gated when not Tx/Rx */
108 * DAI hardware signal inversions
110 #define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bit clock + frame */
111 #define SND_SOC_DAIFMT_NB_IF (1 << 8) /* normal bclk + inv frm */
112 #define SND_SOC_DAIFMT_IB_NF (2 << 8) /* invert bclk + nor frm */
113 #define SND_SOC_DAIFMT_IB_IF (3 << 8) /* invert bclk + frm */
116 * DAI hardware clock masters
117 * This is wrt the codec, the inverse is true for the interface
118 * i.e. if the codec is clk and frm master then the interface is
119 * clk and frame slave.
121 #define SND_SOC_DAIFMT_CBM_CFM (0 << 12) /* codec clk & frm master */
122 #define SND_SOC_DAIFMT_CBS_CFM (1 << 12) /* codec clk slave & frm master */
123 #define SND_SOC_DAIFMT_CBM_CFS (2 << 12) /* codec clk master & frame slave */
124 #define SND_SOC_DAIFMT_CBS_CFS (3 << 12) /* codec clk & frm slave */
126 #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
127 #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
128 #define SND_SOC_DAIFMT_INV_MASK 0x0f00
129 #define SND_SOC_DAIFMT_MASTER_MASK 0xf000
133 * Master Clock Directions
135 #define SND_SOC_CLOCK_IN 0
136 #define SND_SOC_CLOCK_OUT 1
139 * AC97 codec ID's bitmask
141 #define SND_SOC_DAI_AC97_ID0 (1 << 0)
142 #define SND_SOC_DAI_AC97_ID1 (1 << 1)
143 #define SND_SOC_DAI_AC97_ID2 (1 << 2)
144 #define SND_SOC_DAI_AC97_ID3 (1 << 3)
146 struct snd_soc_device
;
147 struct snd_soc_pcm_stream
;
149 struct snd_soc_dai_mode
;
150 struct snd_soc_pcm_runtime
;
151 struct snd_soc_codec_dai
;
152 struct snd_soc_cpu_dai
;
153 struct snd_soc_codec
;
154 struct snd_soc_machine_config
;
156 struct snd_soc_ac97_ops
;
157 struct snd_soc_clock_info
;
159 typedef int (*hw_write_t
)(void *,const char* ,int);
160 typedef int (*hw_read_t
)(void *,char* ,int);
162 extern struct snd_ac97_bus_ops soc_ac97_ops
;
164 /* pcm <-> DAI connect */
165 void snd_soc_free_pcms(struct snd_soc_device
*socdev
);
166 int snd_soc_new_pcms(struct snd_soc_device
*socdev
, int idx
, const char *xid
);
167 int snd_soc_register_card(struct snd_soc_device
*socdev
);
169 /* set runtime hw params */
170 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream
*substream
,
171 const struct snd_pcm_hardware
*hw
);
174 #define snd_soc_read(codec, reg) codec->read(codec, reg)
175 #define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
177 /* codec register bit access */
178 int snd_soc_update_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
179 unsigned short mask
, unsigned short value
);
180 int snd_soc_test_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
181 unsigned short mask
, unsigned short value
);
183 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
184 struct snd_ac97_bus_ops
*ops
, int num
);
185 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
);
190 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
191 void *data
, char *long_name
);
192 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
193 struct snd_ctl_elem_info
*uinfo
);
194 int snd_soc_info_enum_ext(struct snd_kcontrol
*kcontrol
,
195 struct snd_ctl_elem_info
*uinfo
);
196 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
197 struct snd_ctl_elem_value
*ucontrol
);
198 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
199 struct snd_ctl_elem_value
*ucontrol
);
200 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
201 struct snd_ctl_elem_info
*uinfo
);
202 int snd_soc_info_volsw_ext(struct snd_kcontrol
*kcontrol
,
203 struct snd_ctl_elem_info
*uinfo
);
204 int snd_soc_info_bool_ext(struct snd_kcontrol
*kcontrol
,
205 struct snd_ctl_elem_info
*uinfo
);
206 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
207 struct snd_ctl_elem_value
*ucontrol
);
208 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
209 struct snd_ctl_elem_value
*ucontrol
);
210 int snd_soc_info_volsw_2r(struct snd_kcontrol
*kcontrol
,
211 struct snd_ctl_elem_info
*uinfo
);
212 int snd_soc_get_volsw_2r(struct snd_kcontrol
*kcontrol
,
213 struct snd_ctl_elem_value
*ucontrol
);
214 int snd_soc_put_volsw_2r(struct snd_kcontrol
*kcontrol
,
215 struct snd_ctl_elem_value
*ucontrol
);
217 /* SoC PCM stream information */
218 struct snd_soc_pcm_stream
{
220 u64 formats
; /* SNDRV_PCM_FMTBIT_* */
221 unsigned int rates
; /* SNDRV_PCM_RATE_* */
222 unsigned int rate_min
; /* min rate */
223 unsigned int rate_max
; /* max rate */
224 unsigned int channels_min
; /* min channels */
225 unsigned int channels_max
; /* max channels */
226 unsigned int active
:1; /* stream is in use */
231 int (*startup
)(struct snd_pcm_substream
*);
232 void (*shutdown
)(struct snd_pcm_substream
*);
233 int (*hw_params
)(struct snd_pcm_substream
*, struct snd_pcm_hw_params
*);
234 int (*hw_free
)(struct snd_pcm_substream
*);
235 int (*prepare
)(struct snd_pcm_substream
*);
236 int (*trigger
)(struct snd_pcm_substream
*, int);
239 /* ASoC codec DAI ops */
240 struct snd_soc_codec_ops
{
241 /* codec DAI clocking configuration */
242 int (*set_sysclk
)(struct snd_soc_codec_dai
*codec_dai
,
243 int clk_id
, unsigned int freq
, int dir
);
244 int (*set_pll
)(struct snd_soc_codec_dai
*codec_dai
,
245 int pll_id
, unsigned int freq_in
, unsigned int freq_out
);
246 int (*set_clkdiv
)(struct snd_soc_codec_dai
*codec_dai
,
247 int div_id
, int div
);
249 /* CPU DAI format configuration */
250 int (*set_fmt
)(struct snd_soc_codec_dai
*codec_dai
,
252 int (*set_tdm_slot
)(struct snd_soc_codec_dai
*codec_dai
,
253 unsigned int mask
, int slots
);
254 int (*set_tristate
)(struct snd_soc_codec_dai
*, int tristate
);
257 int (*digital_mute
)(struct snd_soc_codec_dai
*, int mute
);
260 /* ASoC cpu DAI ops */
261 struct snd_soc_cpu_ops
{
262 /* CPU DAI clocking configuration */
263 int (*set_sysclk
)(struct snd_soc_cpu_dai
*cpu_dai
,
264 int clk_id
, unsigned int freq
, int dir
);
265 int (*set_clkdiv
)(struct snd_soc_cpu_dai
*cpu_dai
,
266 int div_id
, int div
);
267 int (*set_pll
)(struct snd_soc_cpu_dai
*cpu_dai
,
268 int pll_id
, unsigned int freq_in
, unsigned int freq_out
);
270 /* CPU DAI format configuration */
271 int (*set_fmt
)(struct snd_soc_cpu_dai
*cpu_dai
,
273 int (*set_tdm_slot
)(struct snd_soc_cpu_dai
*cpu_dai
,
274 unsigned int mask
, int slots
);
275 int (*set_tristate
)(struct snd_soc_cpu_dai
*, int tristate
);
279 struct snd_soc_codec_dai
{
284 /* DAI capabilities */
285 struct snd_soc_pcm_stream playback
;
286 struct snd_soc_pcm_stream capture
;
288 /* DAI runtime info */
289 struct snd_soc_codec
*codec
;
291 unsigned char pop_wait
:1;
294 struct snd_soc_ops ops
;
295 struct snd_soc_codec_ops dai_ops
;
297 /* DAI private data */
302 struct snd_soc_cpu_dai
{
304 /* DAI description */
310 int (*probe
)(struct platform_device
*pdev
);
311 void (*remove
)(struct platform_device
*pdev
);
312 int (*suspend
)(struct platform_device
*pdev
,
313 struct snd_soc_cpu_dai
*cpu_dai
);
314 int (*resume
)(struct platform_device
*pdev
,
315 struct snd_soc_cpu_dai
*cpu_dai
);
318 struct snd_soc_ops ops
;
319 struct snd_soc_cpu_ops dai_ops
;
321 /* DAI capabilities */
322 struct snd_soc_pcm_stream capture
;
323 struct snd_soc_pcm_stream playback
;
325 /* DAI runtime info */
326 struct snd_pcm_runtime
*runtime
;
327 unsigned char active
:1;
330 /* DAI private data */
334 /* SoC Audio Codec */
335 struct snd_soc_codec
{
337 struct module
*owner
;
341 int (*dapm_event
)(struct snd_soc_codec
*codec
, int event
);
344 struct snd_card
*card
;
345 struct snd_ac97
*ac97
; /* for ad-hoc ac97 devices */
347 unsigned int pcm_devs
;
351 void *control_data
; /* codec control (i2c/3wire) data */
352 unsigned int (*read
)(struct snd_soc_codec
*, unsigned int);
353 int (*write
)(struct snd_soc_codec
*, unsigned int, unsigned int);
357 short reg_cache_size
;
358 short reg_cache_step
;
361 struct list_head dapm_widgets
;
362 struct list_head dapm_paths
;
363 unsigned int dapm_state
;
364 unsigned int suspend_dapm_state
;
365 struct delayed_work delayed_work
;
368 struct snd_soc_codec_dai
*dai
;
369 unsigned int num_dai
;
373 struct snd_soc_codec_device
{
374 int (*probe
)(struct platform_device
*pdev
);
375 int (*remove
)(struct platform_device
*pdev
);
376 int (*suspend
)(struct platform_device
*pdev
, pm_message_t state
);
377 int (*resume
)(struct platform_device
*pdev
);
380 /* SoC platform interface */
381 struct snd_soc_platform
{
384 int (*probe
)(struct platform_device
*pdev
);
385 int (*remove
)(struct platform_device
*pdev
);
386 int (*suspend
)(struct platform_device
*pdev
,
387 struct snd_soc_cpu_dai
*cpu_dai
);
388 int (*resume
)(struct platform_device
*pdev
,
389 struct snd_soc_cpu_dai
*cpu_dai
);
391 /* pcm creation and destruction */
392 int (*pcm_new
)(struct snd_card
*, struct snd_soc_codec_dai
*,
394 void (*pcm_free
)(struct snd_pcm
*);
396 /* platform stream ops */
397 struct snd_pcm_ops
*pcm_ops
;
400 /* SoC machine DAI configuration, glues a codec and cpu DAI together */
401 struct snd_soc_dai_link
{
402 char *name
; /* Codec name */
403 char *stream_name
; /* Stream name */
406 struct snd_soc_codec_dai
*codec_dai
;
407 struct snd_soc_cpu_dai
*cpu_dai
;
409 /* machine stream operations */
410 struct snd_soc_ops
*ops
;
412 /* codec/machine specific init - e.g. add machine controls */
413 int (*init
)(struct snd_soc_codec
*codec
);
417 struct snd_soc_machine
{
420 int (*probe
)(struct platform_device
*pdev
);
421 int (*remove
)(struct platform_device
*pdev
);
423 /* the pre and post PM functions are used to do any PM work before and
424 * after the codec and DAI's do any PM work. */
425 int (*suspend_pre
)(struct platform_device
*pdev
, pm_message_t state
);
426 int (*suspend_post
)(struct platform_device
*pdev
, pm_message_t state
);
427 int (*resume_pre
)(struct platform_device
*pdev
);
428 int (*resume_post
)(struct platform_device
*pdev
);
430 /* CPU <--> Codec DAI links */
431 struct snd_soc_dai_link
*dai_link
;
435 /* SoC Device - the audio subsystem */
436 struct snd_soc_device
{
438 struct snd_soc_machine
*machine
;
439 struct snd_soc_platform
*platform
;
440 struct snd_soc_codec
*codec
;
441 struct snd_soc_codec_device
*codec_dev
;
442 struct delayed_work delayed_work
;
446 /* runtime channel data */
447 struct snd_soc_pcm_runtime
{
448 struct snd_soc_dai_link
*dai
;
449 struct snd_soc_device
*socdev
;
452 /* enumerated kcontrol */
456 unsigned char shift_l
;
457 unsigned char shift_r
;