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