]> git.karo-electronics.de Git - linux-beck.git/blob - sound/soc/intel/boards/skl_nau88l25_ssm4567.c
ASoc: Intel: boards: fix dapm map of nau88l25_ssm4567 machine
[linux-beck.git] / sound / soc / intel / boards / skl_nau88l25_ssm4567.c
1 /*
2  * Intel Skylake I2S Machine Driver for NAU88L25+SSM4567
3  *
4  * Copyright (C) 2015, Intel Corporation. All rights reserved.
5  *
6  * Modified from:
7  *   Intel Skylake I2S Machine Driver for NAU88L25 and SSM4567
8  *
9  *   Copyright (C) 2015, Intel Corporation. All rights reserved.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License version
13  * 2 as published by the Free Software Foundation.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  */
20
21 #include <linux/module.h>
22 #include <linux/platform_device.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
25 #include <sound/soc.h>
26 #include <sound/jack.h>
27 #include <sound/pcm_params.h>
28 #include "../../codecs/nau8825.h"
29
30 #define SKL_NUVOTON_CODEC_DAI   "nau8825-hifi"
31 #define SKL_SSM_CODEC_DAI       "ssm4567-hifi"
32
33 static struct snd_soc_jack skylake_headset;
34 static struct snd_soc_card skylake_audio_card;
35
36 static inline struct snd_soc_dai *skl_get_codec_dai(struct snd_soc_card *card)
37 {
38         struct snd_soc_pcm_runtime *rtd;
39
40         list_for_each_entry(rtd, &card->rtd_list, list) {
41
42                 if (!strncmp(rtd->codec_dai->name, SKL_NUVOTON_CODEC_DAI,
43                              strlen(SKL_NUVOTON_CODEC_DAI)))
44                         return rtd->codec_dai;
45         }
46
47         return NULL;
48 }
49
50 static const struct snd_kcontrol_new skylake_controls[] = {
51         SOC_DAPM_PIN_SWITCH("Headphone Jack"),
52         SOC_DAPM_PIN_SWITCH("Headset Mic"),
53         SOC_DAPM_PIN_SWITCH("Left Speaker"),
54         SOC_DAPM_PIN_SWITCH("Right Speaker"),
55 };
56
57 static int platform_clock_control(struct snd_soc_dapm_widget *w,
58                 struct snd_kcontrol *k, int  event)
59 {
60         struct snd_soc_dapm_context *dapm = w->dapm;
61         struct snd_soc_card *card = dapm->card;
62         struct snd_soc_dai *codec_dai;
63         int ret;
64
65         codec_dai = skl_get_codec_dai(card);
66         if (!codec_dai) {
67                 dev_err(card->dev, "Codec dai not found\n");
68                 return -EIO;
69         }
70
71         if (SND_SOC_DAPM_EVENT_ON(event)) {
72                 ret = snd_soc_dai_set_sysclk(codec_dai,
73                                 NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN);
74                 if (ret < 0) {
75                         dev_err(card->dev, "set sysclk err = %d\n", ret);
76                         return -EIO;
77                 }
78         } else {
79                 ret = snd_soc_dai_set_sysclk(codec_dai,
80                                 NAU8825_CLK_INTERNAL, 0, SND_SOC_CLOCK_IN);
81                 if (ret < 0) {
82                         dev_err(card->dev, "set sysclk err = %d\n", ret);
83                         return -EIO;
84                 }
85         }
86         return ret;
87 }
88
89 static const struct snd_soc_dapm_widget skylake_widgets[] = {
90         SND_SOC_DAPM_HP("Headphone Jack", NULL),
91         SND_SOC_DAPM_MIC("Headset Mic", NULL),
92         SND_SOC_DAPM_SPK("Left Speaker", NULL),
93         SND_SOC_DAPM_SPK("Right Speaker", NULL),
94         SND_SOC_DAPM_MIC("SoC DMIC", NULL),
95         SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
96                         platform_clock_control, SND_SOC_DAPM_PRE_PMU |
97                         SND_SOC_DAPM_POST_PMD),
98 };
99
100 static const struct snd_soc_dapm_route skylake_map[] = {
101         /* HP jack connectors - unknown if we have jack detection */
102         {"Headphone Jack", NULL, "HPOL"},
103         {"Headphone Jack", NULL, "HPOR"},
104
105         /* speaker */
106         {"Left Speaker", NULL, "Left OUT"},
107         {"Right Speaker", NULL, "Right OUT"},
108
109         /* other jacks */
110         {"MIC", NULL, "Headset Mic"},
111         {"DMic", NULL, "SoC DMIC"},
112
113         /* CODEC BE connections */
114         { "Left Playback", NULL, "ssp0 Tx"},
115         { "Right Playback", NULL, "ssp0 Tx"},
116         { "ssp0 Tx", NULL, "codec0_out"},
117
118         { "Playback", NULL, "ssp1 Tx"},
119         { "ssp1 Tx", NULL, "codec1_out"},
120
121         { "codec0_in", NULL, "ssp1 Rx" },
122         { "ssp1 Rx", NULL, "Capture" },
123
124         /* DMIC */
125         { "dmic01_hifi", NULL, "DMIC01 Rx" },
126         { "DMIC01 Rx", NULL, "DMIC AIF" },
127         { "Headphone Jack", NULL, "Platform Clock" },
128         { "Headset Mic", NULL, "Platform Clock" },
129 };
130
131 static struct snd_soc_codec_conf ssm4567_codec_conf[] = {
132         {
133                 .dev_name = "i2c-INT343B:00",
134                 .name_prefix = "Left",
135         },
136         {
137                 .dev_name = "i2c-INT343B:01",
138                 .name_prefix = "Right",
139         },
140 };
141
142 static struct snd_soc_dai_link_component ssm4567_codec_components[] = {
143         { /* Left */
144                 .name = "i2c-INT343B:00",
145                 .dai_name = SKL_SSM_CODEC_DAI,
146         },
147         { /* Right */
148                 .name = "i2c-INT343B:01",
149                 .dai_name = SKL_SSM_CODEC_DAI,
150         },
151 };
152
153 static int skylake_ssm4567_codec_init(struct snd_soc_pcm_runtime *rtd)
154 {
155         int ret;
156
157         /* Slot 1 for left */
158         ret = snd_soc_dai_set_tdm_slot(rtd->codec_dais[0], 0x01, 0x01, 2, 48);
159         if (ret < 0)
160                 return ret;
161
162         /* Slot 2 for right */
163         ret = snd_soc_dai_set_tdm_slot(rtd->codec_dais[1], 0x02, 0x02, 2, 48);
164         if (ret < 0)
165                 return ret;
166
167         return ret;
168 }
169
170 static int skylake_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
171 {
172         int ret;
173         struct snd_soc_codec *codec = rtd->codec;
174
175         /*
176          * 4 buttons here map to the google Reference headset
177          * The use of these buttons can be decided by the user space.
178          */
179         ret = snd_soc_card_jack_new(&skylake_audio_card, "Headset Jack",
180                 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
181                 SND_JACK_BTN_2 | SND_JACK_BTN_3, &skylake_headset,
182                 NULL, 0);
183         if (ret) {
184                 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
185                 return ret;
186         }
187
188         nau8825_enable_jack_detect(codec, &skylake_headset);
189
190         return ret;
191 }
192
193 static int skylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
194                         struct snd_pcm_hw_params *params)
195 {
196         struct snd_interval *rate = hw_param_interval(params,
197                         SNDRV_PCM_HW_PARAM_RATE);
198         struct snd_interval *channels = hw_param_interval(params,
199                                                 SNDRV_PCM_HW_PARAM_CHANNELS);
200         struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
201
202         /* The ADSP will covert the FE rate to 48k, stereo */
203         rate->min = rate->max = 48000;
204         channels->min = channels->max = 2;
205
206         /* set SSP0 to 24 bit */
207         snd_mask_none(fmt);
208         snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
209         return 0;
210 }
211
212 static int skylake_nau8825_hw_params(struct snd_pcm_substream *substream,
213         struct snd_pcm_hw_params *params)
214 {
215         struct snd_soc_pcm_runtime *rtd = substream->private_data;
216         struct snd_soc_dai *codec_dai = rtd->codec_dai;
217         int ret;
218
219         ret = snd_soc_dai_set_sysclk(codec_dai,
220                         NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN);
221
222         if (ret < 0)
223                 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
224
225         return ret;
226 }
227
228 static struct snd_soc_ops skylake_nau8825_ops = {
229         .hw_params = skylake_nau8825_hw_params,
230 };
231
232 /* skylake digital audio interface glue - connects codec <--> CPU */
233 static struct snd_soc_dai_link skylake_dais[] = {
234         /* Front End DAI links */
235         {
236                 .name = "Skl Audio Port",
237                 .stream_name = "Audio",
238                 .cpu_dai_name = "System Pin",
239                 .platform_name = "0000:00:1f.3",
240                 .dynamic = 1,
241                 .codec_name = "snd-soc-dummy",
242                 .codec_dai_name = "snd-soc-dummy-dai",
243                 .nonatomic = 1,
244                 .trigger = {
245                         SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
246                 .dpcm_playback = 1,
247         },
248         {
249                 .name = "Skl Audio Capture Port",
250                 .stream_name = "Audio Record",
251                 .cpu_dai_name = "System Pin",
252                 .platform_name = "0000:00:1f.3",
253                 .dynamic = 1,
254                 .codec_name = "snd-soc-dummy",
255                 .codec_dai_name = "snd-soc-dummy-dai",
256                 .nonatomic = 1,
257                 .trigger = {
258                         SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
259                 .dpcm_capture = 1,
260         },
261         {
262                 .name = "Skl Audio Reference cap",
263                 .stream_name = "refcap",
264                 .cpu_dai_name = "Reference Pin",
265                 .codec_name = "snd-soc-dummy",
266                 .codec_dai_name = "snd-soc-dummy-dai",
267                 .platform_name = "0000:00:1f.3",
268                 .init = NULL,
269                 .dpcm_capture = 1,
270                 .ignore_suspend = 1,
271                 .nonatomic = 1,
272                 .dynamic = 1,
273         },
274         /* Back End DAI links */
275         {
276                 /* SSP0 - Codec */
277                 .name = "SSP0-Codec",
278                 .be_id = 0,
279                 .cpu_dai_name = "SSP0 Pin",
280                 .platform_name = "0000:00:1f.3",
281                 .no_pcm = 1,
282                 .codecs = ssm4567_codec_components,
283                 .num_codecs = ARRAY_SIZE(ssm4567_codec_components),
284                 .dai_fmt = SND_SOC_DAIFMT_DSP_A |
285                         SND_SOC_DAIFMT_IB_NF |
286                         SND_SOC_DAIFMT_CBS_CFS,
287                 .init = skylake_ssm4567_codec_init,
288                 .ignore_suspend = 1,
289                 .ignore_pmdown_time = 1,
290                 .be_hw_params_fixup = skylake_ssp_fixup,
291                 .dpcm_playback = 1,
292         },
293         {
294                 /* SSP1 - Codec */
295                 .name = "SSP1-Codec",
296                 .be_id = 0,
297                 .cpu_dai_name = "SSP1 Pin",
298                 .platform_name = "0000:00:1f.3",
299                 .no_pcm = 1,
300                 .codec_name = "i2c-10508825:00",
301                 .codec_dai_name = SKL_NUVOTON_CODEC_DAI,
302                 .init = skylake_nau8825_codec_init,
303                 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
304                         SND_SOC_DAIFMT_CBS_CFS,
305                 .ignore_suspend = 1,
306                 .ignore_pmdown_time = 1,
307                 .be_hw_params_fixup = skylake_ssp_fixup,
308                 .ops = &skylake_nau8825_ops,
309                 .dpcm_playback = 1,
310                 .dpcm_capture = 1,
311         },
312         {
313                 .name = "dmic01",
314                 .be_id = 1,
315                 .cpu_dai_name = "DMIC01 Pin",
316                 .codec_name = "dmic-codec",
317                 .codec_dai_name = "dmic-hifi",
318                 .platform_name = "0000:00:1f.3",
319                 .ignore_suspend = 1,
320                 .dpcm_capture = 1,
321                 .no_pcm = 1,
322         },
323 };
324
325 /* skylake audio machine driver for SPT + NAU88L25 */
326 static struct snd_soc_card skylake_audio_card = {
327         .name = "sklnau8825adi",
328         .owner = THIS_MODULE,
329         .dai_link = skylake_dais,
330         .num_links = ARRAY_SIZE(skylake_dais),
331         .controls = skylake_controls,
332         .num_controls = ARRAY_SIZE(skylake_controls),
333         .dapm_widgets = skylake_widgets,
334         .num_dapm_widgets = ARRAY_SIZE(skylake_widgets),
335         .dapm_routes = skylake_map,
336         .num_dapm_routes = ARRAY_SIZE(skylake_map),
337         .codec_conf = ssm4567_codec_conf,
338         .num_configs = ARRAY_SIZE(ssm4567_codec_conf),
339         .fully_routed = true,
340 };
341
342 static int skylake_audio_probe(struct platform_device *pdev)
343 {
344         skylake_audio_card.dev = &pdev->dev;
345
346         return devm_snd_soc_register_card(&pdev->dev, &skylake_audio_card);
347 }
348
349 static struct platform_driver skylake_audio = {
350         .probe = skylake_audio_probe,
351         .driver = {
352                 .name = "skl_nau88l25_ssm4567_i2s",
353                 .pm = &snd_soc_pm_ops,
354         },
355 };
356
357 module_platform_driver(skylake_audio)
358
359 /* Module information */
360 MODULE_AUTHOR("Conrad Cooke  <conrad.cooke@intel.com>");
361 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
362 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
363 MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
364 MODULE_AUTHOR("Yong Zhi <yong.zhi@intel.com>");
365 MODULE_DESCRIPTION("Intel Audio Machine driver for SKL with NAU88L25 and SSM4567 in I2S Mode");
366 MODULE_LICENSE("GPL v2");
367 MODULE_ALIAS("platform:skl_nau88l25_ssm4567_i2s");