xref: /OK3568_Linux_fs/kernel/Documentation/sound/soc/machine.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun===================
2*4882a593SmuzhiyunASoC Machine Driver
3*4882a593Smuzhiyun===================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunThe ASoC machine (or board) driver is the code that glues together all the
6*4882a593Smuzhiyuncomponent drivers (e.g. codecs, platforms and DAIs). It also describes the
7*4882a593Smuzhiyunrelationships between each component which include audio paths, GPIOs,
8*4882a593Smuzhiyuninterrupts, clocking, jacks and voltage regulators.
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunThe machine driver can contain codec and platform specific code. It registers
11*4882a593Smuzhiyunthe audio subsystem with the kernel as a platform device and is represented by
12*4882a593Smuzhiyunthe following struct:-
13*4882a593Smuzhiyun::
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun  /* SoC machine */
16*4882a593Smuzhiyun  struct snd_soc_card {
17*4882a593Smuzhiyun	char *name;
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun	...
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun	int (*probe)(struct platform_device *pdev);
22*4882a593Smuzhiyun	int (*remove)(struct platform_device *pdev);
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun	/* the pre and post PM functions are used to do any PM work before and
25*4882a593Smuzhiyun	 * after the codec and DAIs do any PM work. */
26*4882a593Smuzhiyun	int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
27*4882a593Smuzhiyun	int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
28*4882a593Smuzhiyun	int (*resume_pre)(struct platform_device *pdev);
29*4882a593Smuzhiyun	int (*resume_post)(struct platform_device *pdev);
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun	...
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun	/* CPU <--> Codec DAI links  */
34*4882a593Smuzhiyun	struct snd_soc_dai_link *dai_link;
35*4882a593Smuzhiyun	int num_links;
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun	...
38*4882a593Smuzhiyun  };
39*4882a593Smuzhiyun
40*4882a593Smuzhiyunprobe()/remove()
41*4882a593Smuzhiyun----------------
42*4882a593Smuzhiyunprobe/remove are optional. Do any machine specific probe here.
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun
45*4882a593Smuzhiyunsuspend()/resume()
46*4882a593Smuzhiyun------------------
47*4882a593SmuzhiyunThe machine driver has pre and post versions of suspend and resume to take care
48*4882a593Smuzhiyunof any machine audio tasks that have to be done before or after the codec, DAIs
49*4882a593Smuzhiyunand DMA is suspended and resumed. Optional.
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun
52*4882a593SmuzhiyunMachine DAI Configuration
53*4882a593Smuzhiyun-------------------------
54*4882a593SmuzhiyunThe machine DAI configuration glues all the codec and CPU DAIs together. It can
55*4882a593Smuzhiyunalso be used to set up the DAI system clock and for any machine related DAI
56*4882a593Smuzhiyuninitialisation e.g. the machine audio map can be connected to the codec audio
57*4882a593Smuzhiyunmap, unconnected codec pins can be set as such.
58*4882a593Smuzhiyun
59*4882a593Smuzhiyunstruct snd_soc_dai_link is used to set up each DAI in your machine. e.g.
60*4882a593Smuzhiyun::
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun  /* corgi digital audio interface glue - connects codec <--> CPU */
63*4882a593Smuzhiyun  static struct snd_soc_dai_link corgi_dai = {
64*4882a593Smuzhiyun	.name = "WM8731",
65*4882a593Smuzhiyun	.stream_name = "WM8731",
66*4882a593Smuzhiyun	.cpu_dai_name = "pxa-is2-dai",
67*4882a593Smuzhiyun	.codec_dai_name = "wm8731-hifi",
68*4882a593Smuzhiyun	.platform_name = "pxa-pcm-audio",
69*4882a593Smuzhiyun	.codec_name = "wm8713-codec.0-001a",
70*4882a593Smuzhiyun	.init = corgi_wm8731_init,
71*4882a593Smuzhiyun	.ops = &corgi_ops,
72*4882a593Smuzhiyun  };
73*4882a593Smuzhiyun
74*4882a593Smuzhiyunstruct snd_soc_card then sets up the machine with its DAIs. e.g.
75*4882a593Smuzhiyun::
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun  /* corgi audio machine driver */
78*4882a593Smuzhiyun  static struct snd_soc_card snd_soc_corgi = {
79*4882a593Smuzhiyun	.name = "Corgi",
80*4882a593Smuzhiyun	.dai_link = &corgi_dai,
81*4882a593Smuzhiyun	.num_links = 1,
82*4882a593Smuzhiyun  };
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun
85*4882a593SmuzhiyunMachine Power Map
86*4882a593Smuzhiyun-----------------
87*4882a593Smuzhiyun
88*4882a593SmuzhiyunThe machine driver can optionally extend the codec power map and to become an
89*4882a593Smuzhiyunaudio power map of the audio subsystem. This allows for automatic power up/down
90*4882a593Smuzhiyunof speaker/HP amplifiers, etc. Codec pins can be connected to the machines jack
91*4882a593Smuzhiyunsockets in the machine init function.
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun
94*4882a593SmuzhiyunMachine Controls
95*4882a593Smuzhiyun----------------
96*4882a593Smuzhiyun
97*4882a593SmuzhiyunMachine specific audio mixer controls can be added in the DAI init function.
98