This source file includes following definitions.
- cz_aif1_hw_params
- cz_init
- cz_probe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #include <sound/core.h>
30 #include <sound/soc.h>
31 #include <sound/pcm.h>
32 #include <sound/pcm_params.h>
33 #include <sound/soc-dapm.h>
34 #include <sound/jack.h>
35 #include <linux/gpio.h>
36 #include <linux/module.h>
37 #include <linux/i2c.h>
38 #include <linux/acpi.h>
39
40 #include "../codecs/rt5645.h"
41
42 #define CZ_PLAT_CLK 24000000
43
44 static struct snd_soc_jack cz_jack;
45
46 static int cz_aif1_hw_params(struct snd_pcm_substream *substream,
47 struct snd_pcm_hw_params *params)
48 {
49 int ret = 0;
50 struct snd_soc_pcm_runtime *rtd = substream->private_data;
51 struct snd_soc_dai *codec_dai = rtd->codec_dai;
52
53 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5645_PLL1_S_MCLK,
54 CZ_PLAT_CLK, params_rate(params) * 512);
55 if (ret < 0) {
56 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
57 return ret;
58 }
59
60 ret = snd_soc_dai_set_sysclk(codec_dai, RT5645_SCLK_S_PLL1,
61 params_rate(params) * 512, SND_SOC_CLOCK_OUT);
62 if (ret < 0) {
63 dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret);
64 return ret;
65 }
66
67 return ret;
68 }
69
70 static int cz_init(struct snd_soc_pcm_runtime *rtd)
71 {
72 int ret;
73 struct snd_soc_card *card;
74 struct snd_soc_component *codec;
75
76 codec = rtd->codec_dai->component;
77 card = rtd->card;
78
79 ret = snd_soc_card_jack_new(card, "Headset Jack",
80 SND_JACK_HEADPHONE | SND_JACK_MICROPHONE |
81 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
82 SND_JACK_BTN_2 | SND_JACK_BTN_3,
83 &cz_jack, NULL, 0);
84 if (ret) {
85 dev_err(card->dev, "HP jack creation failed %d\n", ret);
86 return ret;
87 }
88
89 rt5645_set_jack_detect(codec, &cz_jack, &cz_jack, &cz_jack);
90
91 return 0;
92 }
93
94 static struct snd_soc_ops cz_aif1_ops = {
95 .hw_params = cz_aif1_hw_params,
96 };
97
98 SND_SOC_DAILINK_DEF(designware1,
99 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.1.auto")));
100 SND_SOC_DAILINK_DEF(designware2,
101 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.2.auto")));
102
103 SND_SOC_DAILINK_DEF(codec,
104 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5650:00", "rt5645-aif1")));
105
106 SND_SOC_DAILINK_DEF(platform,
107 DAILINK_COMP_ARRAY(COMP_PLATFORM("acp_audio_dma.0.auto")));
108
109 static struct snd_soc_dai_link cz_dai_rt5650[] = {
110 {
111 .name = "amd-rt5645-play",
112 .stream_name = "RT5645_AIF1",
113 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
114 | SND_SOC_DAIFMT_CBM_CFM,
115 .init = cz_init,
116 .ops = &cz_aif1_ops,
117 SND_SOC_DAILINK_REG(designware1, codec, platform),
118 },
119 {
120 .name = "amd-rt5645-cap",
121 .stream_name = "RT5645_AIF1",
122 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
123 | SND_SOC_DAIFMT_CBM_CFM,
124 .ops = &cz_aif1_ops,
125 SND_SOC_DAILINK_REG(designware2, codec, platform),
126 },
127 };
128
129 static const struct snd_soc_dapm_widget cz_widgets[] = {
130 SND_SOC_DAPM_HP("Headphones", NULL),
131 SND_SOC_DAPM_SPK("Speakers", NULL),
132 SND_SOC_DAPM_MIC("Headset Mic", NULL),
133 SND_SOC_DAPM_MIC("Int Mic", NULL),
134 };
135
136 static const struct snd_soc_dapm_route cz_audio_route[] = {
137 {"Headphones", NULL, "HPOL"},
138 {"Headphones", NULL, "HPOR"},
139 {"RECMIXL", NULL, "Headset Mic"},
140 {"RECMIXR", NULL, "Headset Mic"},
141 {"Speakers", NULL, "SPOL"},
142 {"Speakers", NULL, "SPOR"},
143 {"DMIC L2", NULL, "Int Mic"},
144 {"DMIC R2", NULL, "Int Mic"},
145 };
146
147 static const struct snd_kcontrol_new cz_mc_controls[] = {
148 SOC_DAPM_PIN_SWITCH("Headphones"),
149 SOC_DAPM_PIN_SWITCH("Speakers"),
150 SOC_DAPM_PIN_SWITCH("Headset Mic"),
151 SOC_DAPM_PIN_SWITCH("Int Mic"),
152 };
153
154 static struct snd_soc_card cz_card = {
155 .name = "acprt5650",
156 .owner = THIS_MODULE,
157 .dai_link = cz_dai_rt5650,
158 .num_links = ARRAY_SIZE(cz_dai_rt5650),
159 .dapm_widgets = cz_widgets,
160 .num_dapm_widgets = ARRAY_SIZE(cz_widgets),
161 .dapm_routes = cz_audio_route,
162 .num_dapm_routes = ARRAY_SIZE(cz_audio_route),
163 .controls = cz_mc_controls,
164 .num_controls = ARRAY_SIZE(cz_mc_controls),
165 };
166
167 static int cz_probe(struct platform_device *pdev)
168 {
169 int ret;
170 struct snd_soc_card *card;
171
172 card = &cz_card;
173 cz_card.dev = &pdev->dev;
174 platform_set_drvdata(pdev, card);
175 ret = devm_snd_soc_register_card(&pdev->dev, &cz_card);
176 if (ret) {
177 dev_err(&pdev->dev,
178 "devm_snd_soc_register_card(%s) failed: %d\n",
179 cz_card.name, ret);
180 return ret;
181 }
182 return 0;
183 }
184
185 static const struct acpi_device_id cz_audio_acpi_match[] = {
186 { "AMDI1002", 0 },
187 {},
188 };
189 MODULE_DEVICE_TABLE(acpi, cz_audio_acpi_match);
190
191 static struct platform_driver cz_pcm_driver = {
192 .driver = {
193 .name = "cz-rt5645",
194 .acpi_match_table = ACPI_PTR(cz_audio_acpi_match),
195 .pm = &snd_soc_pm_ops,
196 },
197 .probe = cz_probe,
198 };
199
200 module_platform_driver(cz_pcm_driver);
201
202 MODULE_AUTHOR("akshu.agrawal@amd.com");
203 MODULE_DESCRIPTION("cz-rt5645 audio support");
204 MODULE_LICENSE("GPL v2");