1 =======================
2 ASoC Codec Class Driver
3 =======================
5 The codec class driver is generic and hardware independent code that configures
6 the codec, FM, MODEM, BT or external DSP to provide audio capture and playback.
7 It should contain no code that is specific to the target platform or machine.
8 All platform and machine specific code should be added to the platform and
9 machine drivers respectively.
11 Each codec class driver *must* provide the following features:-
13 1. Codec DAI and PCM configuration
14 2. Codec control IO - using RegMap API
15 3. Mixers and audio controls
16 4. Codec audio operations
18 6. DAPM event handler.
20 Optionally, codec drivers can also provide:-
22 7. DAC Digital mute control.
24 Its probably best to use this guide in conjunction with the existing codec
25 driver code in sound/soc/codecs/
27 ASoC Codec driver breakdown
28 ===========================
30 Codec DAI and PCM configuration
31 -------------------------------
32 Each codec driver must have a struct snd_soc_dai_driver to define its DAI and
33 PCM capabilities and operations. This struct is exported so that it can be
34 registered with the core by your machine driver.
39 static struct snd_soc_dai_ops wm8731_dai_ops = {
40 .prepare = wm8731_pcm_prepare,
41 .hw_params = wm8731_hw_params,
42 .shutdown = wm8731_shutdown,
43 .digital_mute = wm8731_mute,
44 .set_sysclk = wm8731_set_dai_sysclk,
45 .set_fmt = wm8731_set_dai_fmt,
48 struct snd_soc_dai_driver wm8731_dai = {
49 .name = "wm8731-hifi",
51 .stream_name = "Playback",
54 .rates = WM8731_RATES,
55 .formats = WM8731_FORMATS,},
57 .stream_name = "Capture",
60 .rates = WM8731_RATES,
61 .formats = WM8731_FORMATS,},
62 .ops = &wm8731_dai_ops,
69 The codec can usually be controlled via an I2C or SPI style interface
70 (AC97 combines control with data in the DAI). The codec driver should use the
71 Regmap API for all codec IO. Please see include/linux/regmap.h and existing
72 codec drivers for example regmap usage.
75 Mixers and audio controls
76 -------------------------
77 All the codec mixers and audio controls can be defined using the convenience
78 macros defined in soc.h.
81 #define SOC_SINGLE(xname, reg, shift, mask, invert)
83 Defines a single control as follows:-
86 xname = Control name e.g. "Playback Volume"
88 shift = control bit(s) offset in register
89 mask = control bit size(s) e.g. mask of 7 = 3 bits
90 invert = the control is inverted
92 Other macros include:-
95 #define SOC_DOUBLE(xname, reg, shift_left, shift_right, mask, invert)
100 #define SOC_DOUBLE_R(xname, reg_left, reg_right, shift, mask, invert)
102 A stereo control spanning 2 registers
105 #define SOC_ENUM_SINGLE(xreg, xshift, xmask, xtexts)
107 Defines an single enumerated control as follows:-
111 xshift = control bit(s) offset in register
112 xmask = control bit(s) size
113 xtexts = pointer to array of strings that describe each setting
115 #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts)
117 Defines a stereo enumerated control
120 Codec Audio Operations
121 ----------------------
122 The codec driver also supports the following ALSA PCM operations:-
127 int (*startup)(struct snd_pcm_substream *);
128 void (*shutdown)(struct snd_pcm_substream *);
129 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
130 int (*hw_free)(struct snd_pcm_substream *);
131 int (*prepare)(struct snd_pcm_substream *);
134 Please refer to the ALSA driver PCM documentation for details.
135 http://www.alsa-project.org/~iwai/writing-an-alsa-driver/
140 The Dynamic Audio Power Management description describes the codec power
141 components and their relationships and registers to the ASoC core.
142 Please read dapm.txt for details of building the description.
144 Please also see the examples in other codec drivers.
149 This function is a callback that handles codec domain PM calls and system
150 domain PM calls (e.g. suspend and resume). It is used to put the codec
151 to sleep when not in use.
156 SNDRV_CTL_POWER_D0: /* full On */
157 /* vref/mid, clk and osc on, active */
159 SNDRV_CTL_POWER_D1: /* partial On */
160 SNDRV_CTL_POWER_D2: /* partial On */
162 SNDRV_CTL_POWER_D3hot: /* Off, with power */
163 /* everything off except vref/vmid, inactive */
165 SNDRV_CTL_POWER_D3cold: /* Everything Off, without power */
168 Codec DAC digital mute control
169 ------------------------------
170 Most codecs have a digital mute before the DACs that can be used to
171 minimise any system noise. The mute stops any digital data from
174 A callback can be created that is called by the core for each codec DAI
175 when the mute is applied or freed.
180 static int wm8974_mute(struct snd_soc_dai *dai, int mute)
182 struct snd_soc_codec *codec = dai->codec;
183 u16 mute_reg = snd_soc_read(codec, WM8974_DAC) & 0xffbf;
186 snd_soc_write(codec, WM8974_DAC, mute_reg | 0x40);
188 snd_soc_write(codec, WM8974_DAC, mute_reg);