2016-11-11 04:16:04 +07:00
|
|
|
=======================
|
2013-09-21 00:19:05 +07:00
|
|
|
ASoC Codec Class Driver
|
|
|
|
=======================
|
2006-10-06 23:34:51 +07:00
|
|
|
|
2013-09-21 00:19:05 +07:00
|
|
|
The codec class driver is generic and hardware independent code that configures
|
|
|
|
the codec, FM, MODEM, BT or external DSP to provide audio capture and playback.
|
|
|
|
It should contain no code that is specific to the target platform or machine.
|
|
|
|
All platform and machine specific code should be added to the platform and
|
|
|
|
machine drivers respectively.
|
2006-10-06 23:34:51 +07:00
|
|
|
|
2013-09-21 00:19:05 +07:00
|
|
|
Each codec class driver *must* provide the following features:-
|
2006-10-06 23:34:51 +07:00
|
|
|
|
2016-11-11 04:16:04 +07:00
|
|
|
1. Codec DAI and PCM configuration
|
|
|
|
2. Codec control IO - using RegMap API
|
|
|
|
3. Mixers and audio controls
|
|
|
|
4. Codec audio operations
|
|
|
|
5. DAPM description.
|
|
|
|
6. DAPM event handler.
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
Optionally, codec drivers can also provide:-
|
|
|
|
|
2016-11-11 04:16:04 +07:00
|
|
|
7. DAC Digital mute control.
|
2006-10-06 23:34:51 +07:00
|
|
|
|
2008-01-23 14:41:46 +07:00
|
|
|
Its probably best to use this guide in conjunction with the existing codec
|
2006-10-06 23:34:51 +07:00
|
|
|
driver code in sound/soc/codecs/
|
|
|
|
|
|
|
|
ASoC Codec driver breakdown
|
|
|
|
===========================
|
|
|
|
|
2016-11-11 04:16:04 +07:00
|
|
|
Codec DAI and PCM configuration
|
|
|
|
-------------------------------
|
2011-01-13 09:08:21 +07:00
|
|
|
Each codec driver must have a struct snd_soc_dai_driver to define its DAI and
|
2008-01-23 14:41:46 +07:00
|
|
|
PCM capabilities and operations. This struct is exported so that it can be
|
2007-02-08 23:06:09 +07:00
|
|
|
registered with the core by your machine driver.
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
e.g.
|
2016-11-11 04:16:04 +07:00
|
|
|
::
|
2006-10-06 23:34:51 +07:00
|
|
|
|
2016-11-11 04:16:04 +07:00
|
|
|
static struct snd_soc_dai_ops wm8731_dai_ops = {
|
2011-01-13 09:08:21 +07:00
|
|
|
.prepare = wm8731_pcm_prepare,
|
|
|
|
.hw_params = wm8731_hw_params,
|
|
|
|
.shutdown = wm8731_shutdown,
|
|
|
|
.digital_mute = wm8731_mute,
|
|
|
|
.set_sysclk = wm8731_set_dai_sysclk,
|
|
|
|
.set_fmt = wm8731_set_dai_fmt,
|
2016-11-11 04:16:04 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct snd_soc_dai_driver wm8731_dai = {
|
2011-01-13 09:08:21 +07:00
|
|
|
.name = "wm8731-hifi",
|
2006-10-06 23:34:51 +07:00
|
|
|
.playback = {
|
|
|
|
.stream_name = "Playback",
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
2007-02-08 23:06:09 +07:00
|
|
|
.rates = WM8731_RATES,
|
|
|
|
.formats = WM8731_FORMATS,},
|
2006-10-06 23:34:51 +07:00
|
|
|
.capture = {
|
|
|
|
.stream_name = "Capture",
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
2007-02-08 23:06:09 +07:00
|
|
|
.rates = WM8731_RATES,
|
|
|
|
.formats = WM8731_FORMATS,},
|
2011-01-13 09:08:21 +07:00
|
|
|
.ops = &wm8731_dai_ops,
|
|
|
|
.symmetric_rates = 1,
|
2016-11-11 04:16:04 +07:00
|
|
|
};
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
|
2016-11-11 04:16:04 +07:00
|
|
|
Codec control IO
|
|
|
|
----------------
|
2008-01-23 14:41:46 +07:00
|
|
|
The codec can usually be controlled via an I2C or SPI style interface
|
2013-09-21 00:19:05 +07:00
|
|
|
(AC97 combines control with data in the DAI). The codec driver should use the
|
|
|
|
Regmap API for all codec IO. Please see include/linux/regmap.h and existing
|
|
|
|
codec drivers for example regmap usage.
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
|
2016-11-11 04:16:04 +07:00
|
|
|
Mixers and audio controls
|
|
|
|
-------------------------
|
2006-10-06 23:34:51 +07:00
|
|
|
All the codec mixers and audio controls can be defined using the convenience
|
|
|
|
macros defined in soc.h.
|
2016-11-11 04:16:04 +07:00
|
|
|
::
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
#define SOC_SINGLE(xname, reg, shift, mask, invert)
|
|
|
|
|
|
|
|
Defines a single control as follows:-
|
2016-11-11 04:16:04 +07:00
|
|
|
::
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
xname = Control name e.g. "Playback Volume"
|
|
|
|
reg = codec register
|
|
|
|
shift = control bit(s) offset in register
|
|
|
|
mask = control bit size(s) e.g. mask of 7 = 3 bits
|
|
|
|
invert = the control is inverted
|
|
|
|
|
|
|
|
Other macros include:-
|
2016-11-11 04:16:04 +07:00
|
|
|
::
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
#define SOC_DOUBLE(xname, reg, shift_left, shift_right, mask, invert)
|
|
|
|
|
|
|
|
A stereo control
|
2016-11-11 04:16:04 +07:00
|
|
|
::
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
#define SOC_DOUBLE_R(xname, reg_left, reg_right, shift, mask, invert)
|
|
|
|
|
|
|
|
A stereo control spanning 2 registers
|
2016-11-11 04:16:04 +07:00
|
|
|
::
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
#define SOC_ENUM_SINGLE(xreg, xshift, xmask, xtexts)
|
|
|
|
|
|
|
|
Defines an single enumerated control as follows:-
|
2016-11-11 04:16:04 +07:00
|
|
|
::
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
xreg = register
|
|
|
|
xshift = control bit(s) offset in register
|
|
|
|
xmask = control bit(s) size
|
|
|
|
xtexts = pointer to array of strings that describe each setting
|
|
|
|
|
|
|
|
#define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts)
|
|
|
|
|
|
|
|
Defines a stereo enumerated control
|
|
|
|
|
|
|
|
|
2016-11-11 04:16:04 +07:00
|
|
|
Codec Audio Operations
|
|
|
|
----------------------
|
2013-09-21 00:19:05 +07:00
|
|
|
The codec driver also supports the following ALSA PCM operations:-
|
2016-11-11 04:16:04 +07:00
|
|
|
::
|
2006-10-06 23:34:51 +07:00
|
|
|
|
2016-11-11 04:16:04 +07:00
|
|
|
/* SoC audio ops */
|
|
|
|
struct snd_soc_ops {
|
2006-11-24 22:12:50 +07:00
|
|
|
int (*startup)(struct snd_pcm_substream *);
|
|
|
|
void (*shutdown)(struct snd_pcm_substream *);
|
|
|
|
int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
|
|
|
|
int (*hw_free)(struct snd_pcm_substream *);
|
|
|
|
int (*prepare)(struct snd_pcm_substream *);
|
2016-11-11 04:16:04 +07:00
|
|
|
};
|
2006-10-06 23:34:51 +07:00
|
|
|
|
2008-01-23 14:41:46 +07:00
|
|
|
Please refer to the ALSA driver PCM documentation for details.
|
2010-07-24 10:51:24 +07:00
|
|
|
http://www.alsa-project.org/~iwai/writing-an-alsa-driver/
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
|
2016-11-11 04:16:04 +07:00
|
|
|
DAPM description
|
|
|
|
----------------
|
2008-01-23 14:41:46 +07:00
|
|
|
The Dynamic Audio Power Management description describes the codec power
|
|
|
|
components and their relationships and registers to the ASoC core.
|
2018-04-11 23:33:26 +07:00
|
|
|
Please read dapm.rst for details of building the description.
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
Please also see the examples in other codec drivers.
|
|
|
|
|
|
|
|
|
2016-11-11 04:16:04 +07:00
|
|
|
DAPM event handler
|
|
|
|
------------------
|
2006-10-06 23:34:51 +07:00
|
|
|
This function is a callback that handles codec domain PM calls and system
|
2008-01-23 14:41:46 +07:00
|
|
|
domain PM calls (e.g. suspend and resume). It is used to put the codec
|
|
|
|
to sleep when not in use.
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
Power states:-
|
2016-11-11 04:16:04 +07:00
|
|
|
::
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
SNDRV_CTL_POWER_D0: /* full On */
|
|
|
|
/* vref/mid, clk and osc on, active */
|
|
|
|
|
|
|
|
SNDRV_CTL_POWER_D1: /* partial On */
|
|
|
|
SNDRV_CTL_POWER_D2: /* partial On */
|
|
|
|
|
|
|
|
SNDRV_CTL_POWER_D3hot: /* Off, with power */
|
|
|
|
/* everything off except vref/vmid, inactive */
|
|
|
|
|
|
|
|
SNDRV_CTL_POWER_D3cold: /* Everything Off, without power */
|
|
|
|
|
|
|
|
|
2016-11-11 04:16:04 +07:00
|
|
|
Codec DAC digital mute control
|
|
|
|
------------------------------
|
2008-01-23 14:41:46 +07:00
|
|
|
Most codecs have a digital mute before the DACs that can be used to
|
|
|
|
minimise any system noise. The mute stops any digital data from
|
|
|
|
entering the DAC.
|
2006-10-06 23:34:51 +07:00
|
|
|
|
2008-01-23 14:41:46 +07:00
|
|
|
A callback can be created that is called by the core for each codec DAI
|
|
|
|
when the mute is applied or freed.
|
2006-10-06 23:34:51 +07:00
|
|
|
|
|
|
|
i.e.
|
2016-11-11 04:16:04 +07:00
|
|
|
::
|
2006-10-06 23:34:51 +07:00
|
|
|
|
2016-11-11 04:16:04 +07:00
|
|
|
static int wm8974_mute(struct snd_soc_dai *dai, int mute)
|
|
|
|
{
|
2018-03-28 09:14:22 +07:00
|
|
|
struct snd_soc_component *component = dai->component;
|
|
|
|
u16 mute_reg = snd_soc_component_read32(component, WM8974_DAC) & 0xffbf;
|
2011-01-13 09:08:21 +07:00
|
|
|
|
|
|
|
if (mute)
|
2018-03-28 09:14:22 +07:00
|
|
|
snd_soc_component_write(component, WM8974_DAC, mute_reg | 0x40);
|
2006-10-06 23:34:51 +07:00
|
|
|
else
|
2018-03-28 09:14:22 +07:00
|
|
|
snd_soc_component_write(component, WM8974_DAC, mute_reg);
|
2006-10-06 23:34:51 +07:00
|
|
|
return 0;
|
2016-11-11 04:16:04 +07:00
|
|
|
}
|