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/core.h>
20 #include <sound/pcm.h>
21 #include <sound/control.h>
22 #include <sound/ac97_codec.h>
25 * Convenience kcontrol builders
27 #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) \
28 ((unsigned long)&(struct soc_mixer_control) \
29 {.reg = xreg, .shift = xshift, .rshift = xshift, .max = xmax, \
31 #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
32 ((unsigned long)&(struct soc_mixer_control) \
33 {.reg = xreg, .max = xmax, .invert = xinvert})
34 #define SOC_SINGLE(xname, reg, shift, max, 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, 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) }
47 #define SOC_DOUBLE(xname, xreg, shift_left, shift_right, xmax, xinvert) \
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, \
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) \
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, \
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) \
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, \
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) \
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, \
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) \
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, \
88 .private_value = (unsigned long)&(struct soc_mixer_control) \
89 {.reg = xreg, .min = xmin, .max = xmax} }
90 #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmax, xtexts) \
91 { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
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 }
97 #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xmax, xtexts, xvalues) \
98 { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
99 .mask = xmask, .max = xmax, .texts = xtexts, .values = xvalues}
100 #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xmax, xtexts, xvalues) \
101 SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xmax, xtexts, xvalues)
102 #define SOC_ENUM(xname, xenum) \
103 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
104 .info = snd_soc_info_enum_double, \
105 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
106 .private_value = (unsigned long)&xenum }
107 #define SOC_VALUE_ENUM(xname, xenum) \
108 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
109 .info = snd_soc_info_enum_double, \
110 .get = snd_soc_get_value_enum_double, \
111 .put = snd_soc_put_value_enum_double, \
112 .private_value = (unsigned long)&xenum }
113 #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
114 xhandler_get, xhandler_put) \
115 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
116 .info = snd_soc_info_volsw, \
117 .get = xhandler_get, .put = xhandler_put, \
118 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
119 #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
120 xhandler_get, xhandler_put, tlv_array) \
121 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
122 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
123 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
124 .tlv.p = (tlv_array), \
125 .info = snd_soc_info_volsw, \
126 .get = xhandler_get, .put = xhandler_put, \
127 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
128 #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
129 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
130 .info = snd_soc_info_bool_ext, \
131 .get = xhandler_get, .put = xhandler_put, \
132 .private_value = xdata }
133 #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
134 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
135 .info = snd_soc_info_enum_ext, \
136 .get = xhandler_get, .put = xhandler_put, \
137 .private_value = (unsigned long)&xenum }
142 * @ON: Bias is fully on for audio playback and capture operations.
143 * @PREPARE: Prepare for audio operations. Called before DAPM switching for
144 * stream start and stop operations.
145 * @STANDBY: Low power standby state when no playback/capture operations are
146 * in progress. NOTE: The transition time between STANDBY and ON
147 * should be as fast as possible and no longer than 10ms.
148 * @OFF: Power Off. No restrictions on transition times.
150 enum snd_soc_bias_level {
152 SND_SOC_BIAS_PREPARE,
153 SND_SOC_BIAS_STANDBY,
157 struct snd_soc_device;
158 struct snd_soc_pcm_stream;
160 struct snd_soc_dai_mode;
161 struct snd_soc_pcm_runtime;
163 struct snd_soc_platform;
164 struct snd_soc_codec;
166 struct snd_soc_ac97_ops;
168 typedef int (*hw_write_t)(void *,const char* ,int);
169 typedef int (*hw_read_t)(void *,char* ,int);
171 extern struct snd_ac97_bus_ops soc_ac97_ops;
173 int snd_soc_register_platform(struct snd_soc_platform *platform);
174 void snd_soc_unregister_platform(struct snd_soc_platform *platform);
175 int snd_soc_register_codec(struct snd_soc_codec *codec);
176 void snd_soc_unregister_codec(struct snd_soc_codec *codec);
178 /* pcm <-> DAI connect */
179 void snd_soc_free_pcms(struct snd_soc_device *socdev);
180 int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid);
181 int snd_soc_init_card(struct snd_soc_device *socdev);
183 /* set runtime hw params */
184 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
185 const struct snd_pcm_hardware *hw);
188 #define snd_soc_read(codec, reg) codec->read(codec, reg)
189 #define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
191 /* codec register bit access */
192 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
193 unsigned short mask, unsigned short value);
194 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
195 unsigned short mask, unsigned short value);
197 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
198 struct snd_ac97_bus_ops *ops, int num);
199 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
204 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
205 void *data, char *long_name);
206 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
207 struct snd_ctl_elem_info *uinfo);
208 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
209 struct snd_ctl_elem_info *uinfo);
210 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
211 struct snd_ctl_elem_value *ucontrol);
212 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
213 struct snd_ctl_elem_value *ucontrol);
214 int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
215 struct snd_ctl_elem_value *ucontrol);
216 int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
217 struct snd_ctl_elem_value *ucontrol);
218 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
219 struct snd_ctl_elem_info *uinfo);
220 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
221 struct snd_ctl_elem_info *uinfo);
222 #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
223 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
224 struct snd_ctl_elem_value *ucontrol);
225 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
226 struct snd_ctl_elem_value *ucontrol);
227 int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
228 struct snd_ctl_elem_info *uinfo);
229 int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
230 struct snd_ctl_elem_value *ucontrol);
231 int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
232 struct snd_ctl_elem_value *ucontrol);
233 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
234 struct snd_ctl_elem_info *uinfo);
235 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
236 struct snd_ctl_elem_value *ucontrol);
237 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
238 struct snd_ctl_elem_value *ucontrol);
240 /* SoC PCM stream information */
241 struct snd_soc_pcm_stream {
243 u64 formats; /* SNDRV_PCM_FMTBIT_* */
244 unsigned int rates; /* SNDRV_PCM_RATE_* */
245 unsigned int rate_min; /* min rate */
246 unsigned int rate_max; /* max rate */
247 unsigned int channels_min; /* min channels */
248 unsigned int channels_max; /* max channels */
249 unsigned int active:1; /* stream is in use */
254 int (*startup)(struct snd_pcm_substream *);
255 void (*shutdown)(struct snd_pcm_substream *);
256 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
257 int (*hw_free)(struct snd_pcm_substream *);
258 int (*prepare)(struct snd_pcm_substream *);
259 int (*trigger)(struct snd_pcm_substream *, int);
262 /* SoC Audio Codec */
263 struct snd_soc_codec {
265 struct module *owner;
269 struct list_head list;
272 int (*set_bias_level)(struct snd_soc_codec *,
273 enum snd_soc_bias_level level);
276 struct snd_card *card;
277 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
279 unsigned int pcm_devs;
283 void *control_data; /* codec control (i2c/3wire) data */
284 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
285 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
286 int (*display_register)(struct snd_soc_codec *, char *,
287 size_t, unsigned int);
291 short reg_cache_size;
292 short reg_cache_step;
296 struct list_head dapm_widgets;
297 struct list_head dapm_paths;
298 enum snd_soc_bias_level bias_level;
299 enum snd_soc_bias_level suspend_bias_level;
300 struct delayed_work delayed_work;
303 struct snd_soc_dai *dai;
304 unsigned int num_dai;
306 #ifdef CONFIG_DEBUG_FS
307 struct dentry *debugfs_reg;
308 struct dentry *debugfs_pop_time;
313 struct snd_soc_codec_device {
314 int (*probe)(struct platform_device *pdev);
315 int (*remove)(struct platform_device *pdev);
316 int (*suspend)(struct platform_device *pdev, pm_message_t state);
317 int (*resume)(struct platform_device *pdev);
320 /* SoC platform interface */
321 struct snd_soc_platform {
323 struct list_head list;
325 int (*probe)(struct platform_device *pdev);
326 int (*remove)(struct platform_device *pdev);
327 int (*suspend)(struct snd_soc_dai *dai);
328 int (*resume)(struct snd_soc_dai *dai);
330 /* pcm creation and destruction */
331 int (*pcm_new)(struct snd_card *, struct snd_soc_dai *,
333 void (*pcm_free)(struct snd_pcm *);
335 /* platform stream ops */
336 struct snd_pcm_ops *pcm_ops;
339 /* SoC machine DAI configuration, glues a codec and cpu DAI together */
340 struct snd_soc_dai_link {
341 char *name; /* Codec name */
342 char *stream_name; /* Stream name */
345 struct snd_soc_dai *codec_dai;
346 struct snd_soc_dai *cpu_dai;
348 /* machine stream operations */
349 struct snd_soc_ops *ops;
351 /* codec/machine specific init - e.g. add machine controls */
352 int (*init)(struct snd_soc_codec *codec);
359 struct snd_soc_card {
363 struct list_head list;
367 int (*probe)(struct platform_device *pdev);
368 int (*remove)(struct platform_device *pdev);
370 /* the pre and post PM functions are used to do any PM work before and
371 * after the codec and DAI's do any PM work. */
372 int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
373 int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
374 int (*resume_pre)(struct platform_device *pdev);
375 int (*resume_post)(struct platform_device *pdev);
378 int (*set_bias_level)(struct snd_soc_card *,
379 enum snd_soc_bias_level level);
381 /* CPU <--> Codec DAI links */
382 struct snd_soc_dai_link *dai_link;
385 struct snd_soc_device *socdev;
387 struct snd_soc_platform *platform;
388 struct delayed_work delayed_work;
389 struct work_struct deferred_resume_work;
392 /* SoC Device - the audio subsystem */
393 struct snd_soc_device {
395 struct snd_soc_card *card;
396 struct snd_soc_codec *codec;
397 struct snd_soc_codec_device *codec_dev;
401 /* runtime channel data */
402 struct snd_soc_pcm_runtime {
403 struct snd_soc_dai_link *dai;
404 struct snd_soc_device *socdev;
408 struct soc_mixer_control {
410 unsigned int reg, rreg, shift, rshift, invert;
413 /* enumerated kcontrol */
417 unsigned char shift_l;
418 unsigned char shift_r;
422 const unsigned int *values;
426 #include <sound/soc-dai.h>