blob: 1e95342ed72e4d7b91ef53743cc11c42fcf8dd12 [file] [log] [blame]
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +02001ASoC Codec Driver
2=================
3
4The codec driver is generic and hardware independent code that configures the
5codec to provide audio capture and playback. It should contain no code that is
6specific to the target platform or machine. All platform and machine specific
7code should be added to the platform and machine drivers respectively.
8
Liam Girdwood10b98522007-02-08 17:06:09 +01009Each codec driver *must* provide the following features:-
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020010
Liam Girdwood10b98522007-02-08 17:06:09 +010011 1) Codec DAI and PCM configuration
Mark Brown7c4dbbd2008-01-23 08:41:46 +010012 2) Codec control IO - using I2C, 3 Wire(SPI) or both APIs
Liam Girdwood10b98522007-02-08 17:06:09 +010013 3) Mixers and audio controls
14 4) Codec audio operations
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020015
16Optionally, codec drivers can also provide:-
17
Liam Girdwood10b98522007-02-08 17:06:09 +010018 5) DAPM description.
19 6) DAPM event handler.
20 7) DAC Digital mute control.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020021
Mark Brown7c4dbbd2008-01-23 08:41:46 +010022Its probably best to use this guide in conjunction with the existing codec
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020023driver code in sound/soc/codecs/
24
25ASoC Codec driver breakdown
26===========================
27
Liam Girdwood10b98522007-02-08 17:06:09 +0100281 - Codec DAI and PCM configuration
29-----------------------------------
Mark Brown7c4dbbd2008-01-23 08:41:46 +010030Each codec driver must have a struct snd_soc_codec_dai to define its DAI and
31PCM capabilities and operations. This struct is exported so that it can be
Liam Girdwood10b98522007-02-08 17:06:09 +010032registered with the core by your machine driver.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020033
34e.g.
35
Liam Girdwood10b98522007-02-08 17:06:09 +010036struct snd_soc_codec_dai wm8731_dai = {
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020037 .name = "WM8731",
Liam Girdwood10b98522007-02-08 17:06:09 +010038 /* playback capabilities */
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020039 .playback = {
40 .stream_name = "Playback",
41 .channels_min = 1,
42 .channels_max = 2,
Liam Girdwood10b98522007-02-08 17:06:09 +010043 .rates = WM8731_RATES,
44 .formats = WM8731_FORMATS,},
45 /* capture capabilities */
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020046 .capture = {
47 .stream_name = "Capture",
48 .channels_min = 1,
49 .channels_max = 2,
Liam Girdwood10b98522007-02-08 17:06:09 +010050 .rates = WM8731_RATES,
51 .formats = WM8731_FORMATS,},
52 /* pcm operations - see section 4 below */
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020053 .ops = {
54 .prepare = wm8731_pcm_prepare,
Liam Girdwood10b98522007-02-08 17:06:09 +010055 .hw_params = wm8731_hw_params,
56 .shutdown = wm8731_shutdown,
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020057 },
Liam Girdwood10b98522007-02-08 17:06:09 +010058 /* DAI operations - see DAI.txt */
59 .dai_ops = {
60 .digital_mute = wm8731_mute,
61 .set_sysclk = wm8731_set_dai_sysclk,
62 .set_fmt = wm8731_set_dai_fmt,
63 }
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020064};
Liam Girdwood10b98522007-02-08 17:06:09 +010065EXPORT_SYMBOL_GPL(wm8731_dai);
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020066
67
Liam Girdwood10b98522007-02-08 17:06:09 +0100682 - Codec control IO
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020069--------------------
Mark Brown7c4dbbd2008-01-23 08:41:46 +010070The codec can usually be controlled via an I2C or SPI style interface
71(AC97 combines control with data in the DAI). The codec drivers provide
72functions to read and write the codec registers along with supplying a
73register cache:-
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020074
75 /* IO control data and register cache */
Mark Brown7c4dbbd2008-01-23 08:41:46 +010076 void *control_data; /* codec control (i2c/3wire) data */
77 void *reg_cache;
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020078
Mark Brown7c4dbbd2008-01-23 08:41:46 +010079Codec read/write should do any data formatting and call the hardware
80read write below to perform the IO. These functions are called by the
81core and ALSA when performing DAPM or changing the mixer:-
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020082
83 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
84 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
85
86Codec hardware IO functions - usually points to either the I2C, SPI or AC97
87read/write:-
88
89 hw_write_t hw_write;
90 hw_read_t hw_read;
91
92
Liam Girdwood10b98522007-02-08 17:06:09 +0100933 - Mixers and audio controls
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020094-----------------------------
95All the codec mixers and audio controls can be defined using the convenience
96macros defined in soc.h.
97
98 #define SOC_SINGLE(xname, reg, shift, mask, invert)
99
100Defines a single control as follows:-
101
102 xname = Control name e.g. "Playback Volume"
103 reg = codec register
104 shift = control bit(s) offset in register
105 mask = control bit size(s) e.g. mask of 7 = 3 bits
106 invert = the control is inverted
107
108Other macros include:-
109
110 #define SOC_DOUBLE(xname, reg, shift_left, shift_right, mask, invert)
111
112A stereo control
113
114 #define SOC_DOUBLE_R(xname, reg_left, reg_right, shift, mask, invert)
115
116A stereo control spanning 2 registers
117
118 #define SOC_ENUM_SINGLE(xreg, xshift, xmask, xtexts)
119
120Defines an single enumerated control as follows:-
121
122 xreg = register
123 xshift = control bit(s) offset in register
124 xmask = control bit(s) size
125 xtexts = pointer to array of strings that describe each setting
126
127 #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts)
128
129Defines a stereo enumerated control
130
131
Liam Girdwood10b98522007-02-08 17:06:09 +01001324 - Codec Audio Operations
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200133--------------------------
Mark Brown7c4dbbd2008-01-23 08:41:46 +0100134The codec driver also supports the following ALSA operations:-
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200135
136/* SoC audio ops */
137struct snd_soc_ops {
Takashi Iwai5b78efd2006-11-24 16:12:50 +0100138 int (*startup)(struct snd_pcm_substream *);
139 void (*shutdown)(struct snd_pcm_substream *);
140 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
141 int (*hw_free)(struct snd_pcm_substream *);
142 int (*prepare)(struct snd_pcm_substream *);
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200143};
144
Mark Brown7c4dbbd2008-01-23 08:41:46 +0100145Please refer to the ALSA driver PCM documentation for details.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200146http://www.alsa-project.org/~iwai/writing-an-alsa-driver/c436.htm
147
148
Liam Girdwood10b98522007-02-08 17:06:09 +01001495 - DAPM description.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200150---------------------
Mark Brown7c4dbbd2008-01-23 08:41:46 +0100151The Dynamic Audio Power Management description describes the codec power
152components and their relationships and registers to the ASoC core.
153Please read dapm.txt for details of building the description.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200154
155Please also see the examples in other codec drivers.
156
157
Liam Girdwood10b98522007-02-08 17:06:09 +01001586 - DAPM event handler
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200159----------------------
160This function is a callback that handles codec domain PM calls and system
Mark Brown7c4dbbd2008-01-23 08:41:46 +0100161domain PM calls (e.g. suspend and resume). It is used to put the codec
162to sleep when not in use.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200163
164Power states:-
165
166 SNDRV_CTL_POWER_D0: /* full On */
167 /* vref/mid, clk and osc on, active */
168
169 SNDRV_CTL_POWER_D1: /* partial On */
170 SNDRV_CTL_POWER_D2: /* partial On */
171
172 SNDRV_CTL_POWER_D3hot: /* Off, with power */
173 /* everything off except vref/vmid, inactive */
174
175 SNDRV_CTL_POWER_D3cold: /* Everything Off, without power */
176
177
Mark Brown7c4dbbd2008-01-23 08:41:46 +01001787 - Codec DAC digital mute control
179----------------------------------
180Most codecs have a digital mute before the DACs that can be used to
181minimise any system noise. The mute stops any digital data from
182entering the DAC.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200183
Mark Brown7c4dbbd2008-01-23 08:41:46 +0100184A callback can be created that is called by the core for each codec DAI
185when the mute is applied or freed.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200186
187i.e.
188
189static int wm8974_mute(struct snd_soc_codec *codec,
190 struct snd_soc_codec_dai *dai, int mute)
191{
192 u16 mute_reg = wm8974_read_reg_cache(codec, WM8974_DAC) & 0xffbf;
193 if(mute)
194 wm8974_write(codec, WM8974_DAC, mute_reg | 0x40);
195 else
196 wm8974_write(codec, WM8974_DAC, mute_reg);
197 return 0;
198}