← Documents Documentation/sound/soc/machine.rst GitHub 원문 ↗

Linux 6.18.37 · Sound / ASoC

ASoC Machine Driver

ASoC machine driver가 CPU·codec·platform DAI와 board의 GPIO·IRQ·clock·jack·regulator 관계를 `snd_soc_card`와 `snd_soc_dai_link`로 결합하는 방법을 설명합니다. PM callback, 이름·Device Tree 규칙, card 등록, power map과 clock 책임을 원문 코드 좌표에 맞춰 정리합니다.

Source pathDocumentation/sound/soc/machine.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

machine.rst:1-123

ASoC machine driver가 CPU·codec·platform DAI와 board의 GPIO·IRQ·clock·jack·regulator 관계를 `snd_soc_card`와 `snd_soc_dai_link`로 결합하는 방법을 설명합니다. PM callback, 이름·Device Tree 규칙, card 등록, power map과 clock 책임을 원문 코드 좌표에 맞춰 정리합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ===================
2 ASoC Machine Driver
3 ===================
4
5 The ASoC machine (or board) driver is the code that glues together all the
6 component drivers (e.g. codecs, platforms and DAIs). It also describes the
7 relationships between each component which include audio paths, GPIOs,
8 interrupts, clocking, jacks and voltage regulators.
9
10 The machine driver can contain codec and platform specific code. It registers
11 the audio subsystem with the kernel as a platform device and is represented by
12 the following struct:-
13 ::
14
15 /* SoC machine */
16 struct snd_soc_card {
17 char *name;
18
19 ...
20
21 int (*probe)(struct platform_device *pdev);
22 int (*remove)(struct platform_device *pdev);
23
24 /* the pre and post PM functions are used to do any PM work before and
25 * after the codec and DAIs do any PM work. */
26 int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
27 int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
28 int (*resume_pre)(struct platform_device *pdev);
29 int (*resume_post)(struct platform_device *pdev);
30
31 ...
32
33 /* CPU <--> Codec DAI links */
34 struct snd_soc_dai_link *dai_link;
35 int num_links;
36
37 ...
38 };
39
40 probe()/remove()
41 ----------------
42 probe/remove are optional. Do any machine specific probe here.
43
44
45 suspend()/resume()
46 ------------------
47 The machine driver has pre and post versions of suspend and resume to take care
48 of any machine audio tasks that have to be done before or after the codec, DAIs
49 and DMA is suspended and resumed. Optional.
50
51
52 Machine DAI Configuration
53 -------------------------
54 The machine DAI configuration glues all the codec and CPU DAIs together. It can
55 also be used to set up the DAI system clock and for any machine related DAI
56 initialisation e.g. the machine audio map can be connected to the codec audio
57 map, unconnected codec pins can be set as such.
58
59 struct snd_soc_dai_link is used to set up each DAI in your machine. e.g.
60 ::
61
62 /* corgi digital audio interface glue - connects codec <--> CPU */
63 static struct snd_soc_dai_link corgi_dai = {
64 .name = "WM8731",
65 .stream_name = "WM8731",
66 .cpu_dai_name = "pxa-is2-dai",
67 .codec_dai_name = "wm8731-hifi",
68 .platform_name = "pxa-pcm-audio",
69 .codec_name = "wm8713-codec.0-001a",
70 .init = corgi_wm8731_init,
71 .ops = &corgi_ops,
72 };
73
74 In the above struct, dai’s are registered using names but you can pass
75 either dai name or device tree node but not both. Also, names used here
76 for cpu/codec/platform dais should be globally unique.
77
78 Additionally below example macro can be used to register cpu, codec and
79 platform dai::
80
81 SND_SOC_DAILINK_DEFS(wm2200_cpu_dsp,
82 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
83 DAILINK_COMP_ARRAY(COMP_CODEC("spi0.0", "wm0010-sdi1")),
84 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
85
86 struct snd_soc_card then sets up the machine with its DAIs. e.g.
87 ::
88
89 /* corgi audio machine driver */
90 static struct snd_soc_card snd_soc_corgi = {
91 .name = "Corgi",
92 .dai_link = &corgi_dai,
93 .num_links = 1,
94 };
95
96 Following this, ``devm_snd_soc_register_card`` can be used to register
97 the sound card. During the registration, the individual components
98 such as the codec, CPU, and platform are probed. If all these components
99 are successfully probed, the sound card gets registered.
100
101 Machine Power Map
102 -----------------
103
104 The machine driver can optionally extend the codec power map and to become an
105 audio power map of the audio subsystem. This allows for automatic power up/down
106 of speaker/HP amplifiers, etc. Codec pins can be connected to the machines jack
107 sockets in the machine init function.
108
109
110 Machine Controls
111 ----------------
112
113 Machine specific audio mixer controls can be added in the DAI init function.
114
115
116 Clocking Controls
117 -----------------
118
119 As previously noted, clock configuration is handled within the machine driver.
120 For details on the clock APIs that the machine driver can utilize for
121 setup, please refer to Documentation/sound/soc/clocking.rst. However, the
122 callback needs to be registered by the CPU/Codec/Platform drivers to configure
123 the clocks that is needed for the corresponding device operation.
124

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Machine driver와 snd_soc_card

1-39

ASoC machine 또는 board driver는 codec, platform, DAI 같은 모든 component driver를 결합하는 코드다. Audio path, GPIO, interrupt, clocking, jack, voltage regulator를 포함한 component 사이 관계도 기술한다.

Machine driver에는 codec·platform 종속 코드를 넣을 수 있다. Audio subsystem을 platform device로 kernel에 등록하며 `struct snd_soc_card`로 표현한다.

`snd_soc_card`에는 card 이름, 선택적 `probe`·`remove`, codec·DAI의 PM 작업 전후에 실행되는 `suspend_pre`, `suspend_post`, `resume_pre`, `resume_post`, CPU↔Codec DAI link array와 `num_links`가 포함된다.

snd_soc_card 주요 field
Field역할
nameSound card 이름
probe / removeMachine별 초기화·해제
suspend_pre / suspend_postCodec·DAI PM 전·후 suspend 작업
resume_pre / resume_postCodec·DAI PM 전·후 resume 작업
dai_linkCPU↔Codec DAI link array
num_linksDAI link 개수

원문 구조체에서 machine lifecycle과 DAI 구성을 담당하는 field다.

Machine driver의 결합 역할
CPU DAI driversnd_soc_dai_link
Codec driversnd_soc_dai_link
Platform / DMA driversnd_soc_dai_link
GPIO / IRQ / clocks / jacks / regulatorssnd_soc_card machine policy
snd_soc_dai_link + machine policyRegistered ASoC sound card

Board의 실제 배선과 정책을 component driver 위에 구성한다.

===================
ASoC Machine Driver
===================

The ASoC machine (or board) driver is the code that glues together all the
component drivers (e.g. codecs, platforms and DAIs). It also describes the
relationships between each component which include audio paths, GPIOs,
interrupts, clocking, jacks and voltage regulators.

The machine driver can contain codec and platform specific code. It registers
the audio subsystem with the kernel as a platform device and is represented by
the following struct:-
::

  /* SoC machine */
  struct snd_soc_card {
	char *name;

	...

	int (*probe)(struct platform_device *pdev);
	int (*remove)(struct platform_device *pdev);

	/* the pre and post PM functions are used to do any PM work before and
	 * after the codec and DAIs do any PM work. */
	int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
	int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
	int (*resume_pre)(struct platform_device *pdev);
	int (*resume_post)(struct platform_device *pdev);

	...

	/* CPU <--> Codec DAI links  */
	struct snd_soc_dai_link *dai_link;
	int num_links;

	...
  };

probe()와 remove()

40-44

`probe()`와 `remove()`는 선택 사항이다. Machine별 probe와 teardown이 필요하면 이 callback에서 수행한다.

Machine lifecycle callback
Callback용도
probe()Machine-specific 초기화
remove()Machine-specific 정리

선택적 card 초기화와 해제 지점이다.

probe()/remove()
----------------
probe/remove are optional. Do any machine specific probe here.

suspend()와 resume()

45-51

Machine driver는 suspend와 resume의 pre·post 버전을 제공할 수 있다. Codec, DAI, DMA가 suspend·resume되기 전이나 후에 필요한 machine audio 작업을 처리한다. 이 callback도 선택 사항이다.

Machine PM callback 순서
suspend_preCodec / DAI / DMA suspendsuspend_post
resume_preCodec / DAI / DMA resumeresume_post

Machine 작업을 component PM 경계 앞뒤에 배치한다.

suspend()/resume()
------------------
The machine driver has pre and post versions of suspend and resume to take care
of any machine audio tasks that have to be done before or after the codec, DAIs
and DMA is suspended and resumed. Optional.

Machine DAI 설정과 card 등록

52-100

Machine DAI 설정은 codec DAI와 CPU DAI를 결합한다. DAI system clock을 설정하고, machine audio map을 codec audio map에 연결하거나 연결되지 않은 codec pin을 표시하는 machine별 DAI 초기화에도 사용할 수 있다.

각 DAI는 `struct snd_soc_dai_link`로 설정한다. Corgi 예제는 CPU DAI `pxa-is2-dai`, codec DAI `wm8731-hifi`, platform `pxa-pcm-audio`, codec device `wm8713-codec.0-001a`를 연결하고 `corgi_wm8731_init`, `corgi_ops`를 지정한다. 원문의 `wm8713` 표기는 그대로 보존한다.

DAI를 이름으로 등록할 때 DAI 이름과 Device Tree node 중 하나만 전달할 수 있고 둘을 함께 사용할 수 없다. CPU·codec·platform DAI에 쓰는 이름은 전역에서 고유해야 한다.

`SND_SOC_DAILINK_DEFS` macro는 CPU `samsung-i2s.0`, codec device `spi0.0`의 DAI `wm0010-sdi1`, platform `samsung-i2s.0`을 component array로 선언한다.

그 다음 `struct snd_soc_card snd_soc_corgi`가 card 이름 `Corgi`, `corgi_dai` pointer, link 수 1을 설정한다. `devm_snd_soc_register_card()`로 card를 등록하면 codec, CPU, platform component가 각각 probe되고, 모두 성공해야 sound card 등록이 완료된다.

corgi_dai 연결
Field
name / stream_nameWM8731
cpu_dai_namepxa-is2-dai
codec_dai_namewm8731-hifi
platform_namepxa-pcm-audio
codec_namewm8713-codec.0-001a
initcorgi_wm8731_init
opscorgi_ops

Machine DAI link가 결합하는 component와 callback이다.

DAI 식별 규칙
규칙요구사항
식별 방식DAI name 또는 Device Tree node 중 하나
금지 조합Name과 node를 동시에 전달하지 않음
이름 범위CPU·codec·platform DAI name은 globally unique

이름 기반과 firmware node 기반 등록의 제약이다.

Sound card 등록
SND_SOC_DAILINK_DEFS / snd_soc_dai_linksnd_soc_carddevm_snd_soc_register_card()Probe CodecProbe CPU DAIProbe PlatformSound card registered

DAI link 선언에서 component probe와 card 등록 완료까지의 순서다.

Machine DAI Configuration
-------------------------
The machine DAI configuration glues all the codec and CPU DAIs together. It can
also be used to set up the DAI system clock and for any machine related DAI
initialisation e.g. the machine audio map can be connected to the codec audio
map, unconnected codec pins can be set as such.

struct snd_soc_dai_link is used to set up each DAI in your machine. e.g.
::

  /* corgi digital audio interface glue - connects codec <--> CPU */
  static struct snd_soc_dai_link corgi_dai = {
	.name = "WM8731",
	.stream_name = "WM8731",
	.cpu_dai_name = "pxa-is2-dai",
	.codec_dai_name = "wm8731-hifi",
	.platform_name = "pxa-pcm-audio",
	.codec_name = "wm8713-codec.0-001a",
	.init = corgi_wm8731_init,
	.ops = &corgi_ops,
  };

In the above struct, dai’s are registered using names but you can pass
either dai name or device tree node but not both. Also, names used here
for cpu/codec/platform dais should be globally unique.

Additionally below example macro can be used to register cpu, codec and
platform dai::

  SND_SOC_DAILINK_DEFS(wm2200_cpu_dsp,
	DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
	DAILINK_COMP_ARRAY(COMP_CODEC("spi0.0", "wm0010-sdi1")),
	DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));

struct snd_soc_card then sets up the machine with its DAIs. e.g.
::

  /* corgi audio machine driver */
  static struct snd_soc_card snd_soc_corgi = {
	.name = "Corgi",
	.dai_link = &corgi_dai,
	.num_links = 1,
  };

Following this, ``devm_snd_soc_register_card`` can be used to register
the sound card. During the registration, the individual components
such as the codec, CPU, and platform are probed. If all these components
are successfully probed, the sound card gets registered.

Machine power map

101-109

Machine driver는 선택적으로 codec power map을 확장해 audio subsystem 전체 power map으로 만들 수 있다. 그러면 speaker·headphone amplifier 같은 board component를 자동으로 power up·down할 수 있다.

Machine init function에서 codec pin을 machine의 jack socket에 연결할 수 있다.

Power map 확장
Codec DAPM pinsMachine init routesJack sockets / Speaker amp / HP ampAutomatic power control

Codec graph를 board-level amplifier와 jack까지 연결한다.

Machine Power Map
-----------------

The machine driver can optionally extend the codec power map and to become an
audio power map of the audio subsystem. This allows for automatic power up/down
of speaker/HP amplifiers, etc. Codec pins can be connected to the machines jack
sockets in the machine init function.

Machine audio control

110-115

Machine별 audio mixer control은 DAI init function에서 추가할 수 있다.

Machine control 위치
Control등록 위치
Machine-specific audio mixerDAI init function

Board-specific mixer control의 등록 지점이다.

Machine Controls
----------------

Machine specific audio mixer controls can be added in the DAI init function.

Clocking control

116-123

Clock configuration은 machine driver가 담당한다. Machine driver가 사용할 수 있는 clock API의 자세한 내용은 `Documentation/sound/soc/clocking.rst`를 참조한다.

다만 실제 장치 동작에 필요한 clock을 설정하려면 CPU·Codec·Platform driver가 대응 callback을 등록해야 한다.

Clock 설정 책임
Machine driver clock policyCPU driver callbackCPU DAI clock
Machine driver clock policyCodec driver callbackCodec clock
Machine driver clock policyPlatform driver callbackPlatform clock

Machine policy가 각 component driver callback을 통해 hardware clock을 구성한다.

Clocking Controls
-----------------

As previously noted, clock configuration is handled within the machine driver.
For details on the clock APIs that the machine driver can utilize for
setup, please refer to Documentation/sound/soc/clocking.rst. However, the
callback needs to be registered by the CPU/Codec/Platform drivers to configure
the clocks that is needed for the corresponding device operation.