2 * bytcht-da7213.c - ASoc Machine driver for Intel Baytrail and
3 * Cherrytrail-based platforms, with Dialog DA7213 codec
5 * Copyright (C) 2017 Intel Corporation
6 * Author: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 #include <linux/module.h>
23 #include <linux/acpi.h>
24 #include <linux/platform_device.h>
25 #include <linux/slab.h>
26 #include <asm/platform_sst_audio.h>
27 #include <sound/pcm.h>
28 #include <sound/pcm_params.h>
29 #include <sound/soc.h>
30 #include "../../codecs/da7213.h"
31 #include "../atom/sst-atom-controls.h"
32 #include "../common/sst-acpi.h"
34 static const struct snd_kcontrol_new controls[] = {
35 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
36 SOC_DAPM_PIN_SWITCH("Headset Mic"),
37 SOC_DAPM_PIN_SWITCH("Mic"),
38 SOC_DAPM_PIN_SWITCH("Aux In"),
41 static const struct snd_soc_dapm_widget dapm_widgets[] = {
42 SND_SOC_DAPM_HP("Headphone Jack", NULL),
43 SND_SOC_DAPM_MIC("Headset Mic", NULL),
44 SND_SOC_DAPM_MIC("Mic", NULL),
45 SND_SOC_DAPM_LINE("Aux In", NULL),
48 static const struct snd_soc_dapm_route audio_map[] = {
49 {"Headphone Jack", NULL, "HPL"},
50 {"Headphone Jack", NULL, "HPR"},
52 {"AUXL", NULL, "Aux In"},
53 {"AUXR", NULL, "Aux In"},
55 /* Assume Mic1 is linked to Headset and Mic2 to on-board mic */
56 {"MIC1", NULL, "Headset Mic"},
57 {"MIC2", NULL, "Mic"},
60 {"ssp2 Tx", NULL, "codec_out0"},
61 {"ssp2 Tx", NULL, "codec_out1"},
62 {"codec_in0", NULL, "ssp2 Rx"},
63 {"codec_in1", NULL, "ssp2 Rx"},
65 {"Playback", NULL, "ssp2 Tx"},
66 {"ssp2 Rx", NULL, "Capture"},
69 static int codec_fixup(struct snd_soc_pcm_runtime *rtd,
70 struct snd_pcm_hw_params *params)
73 struct snd_interval *rate = hw_param_interval(params,
74 SNDRV_PCM_HW_PARAM_RATE);
75 struct snd_interval *channels = hw_param_interval(params,
76 SNDRV_PCM_HW_PARAM_CHANNELS);
78 /* The DSP will convert the FE rate to 48k, stereo, 24bits */
79 rate->min = rate->max = 48000;
80 channels->min = channels->max = 2;
82 /* set SSP2 to 24-bit */
83 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
86 * Default mode for SSP configuration is TDM 4 slot, override config
87 * with explicit setting to I2S 2ch 24-bit. The word length is set with
88 * dai_set_tdm_slot() since there is no other API exposed
90 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
92 SND_SOC_DAIFMT_NB_NF |
93 SND_SOC_DAIFMT_CBS_CFS);
95 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
99 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
101 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
108 static int aif1_startup(struct snd_pcm_substream *substream)
110 return snd_pcm_hw_constraint_single(substream->runtime,
111 SNDRV_PCM_HW_PARAM_RATE, 48000);
114 static int aif1_hw_params(struct snd_pcm_substream *substream,
115 struct snd_pcm_hw_params *params)
117 struct snd_soc_pcm_runtime *rtd = substream->private_data;
118 struct snd_soc_dai *codec_dai = rtd->codec_dai;
121 ret = snd_soc_dai_set_sysclk(codec_dai, DA7213_CLKSRC_MCLK,
122 19200000, SND_SOC_CLOCK_IN);
124 dev_err(codec_dai->dev, "can't set codec sysclk configuration\n");
126 ret = snd_soc_dai_set_pll(codec_dai, 0,
127 DA7213_SYSCLK_PLL_SRM, 0, DA7213_PLL_FREQ_OUT_98304000);
129 dev_err(codec_dai->dev, "failed to start PLL: %d\n", ret);
136 static int aif1_hw_free(struct snd_pcm_substream *substream)
138 struct snd_soc_pcm_runtime *rtd = substream->private_data;
139 struct snd_soc_dai *codec_dai = rtd->codec_dai;
142 ret = snd_soc_dai_set_pll(codec_dai, 0,
143 DA7213_SYSCLK_MCLK, 0, 0);
145 dev_err(codec_dai->dev, "failed to stop PLL: %d\n", ret);
152 static const struct snd_soc_ops aif1_ops = {
153 .startup = aif1_startup,
156 static const struct snd_soc_ops ssp2_ops = {
157 .hw_params = aif1_hw_params,
158 .hw_free = aif1_hw_free,
162 static struct snd_soc_dai_link dailink[] = {
163 [MERR_DPCM_AUDIO] = {
164 .name = "Audio Port",
165 .stream_name = "Audio",
166 .cpu_dai_name = "media-cpu-dai",
167 .codec_dai_name = "snd-soc-dummy-dai",
168 .codec_name = "snd-soc-dummy",
169 .platform_name = "sst-mfld-platform",
176 [MERR_DPCM_DEEP_BUFFER] = {
177 .name = "Deep-Buffer Audio Port",
178 .stream_name = "Deep-Buffer Audio",
179 .cpu_dai_name = "deepbuffer-cpu-dai",
180 .codec_dai_name = "snd-soc-dummy-dai",
181 .codec_name = "snd-soc-dummy",
182 .platform_name = "sst-mfld-platform",
188 [MERR_DPCM_COMPR] = {
189 .name = "Compressed Port",
190 .stream_name = "Compress",
191 .cpu_dai_name = "compress-cpu-dai",
192 .codec_dai_name = "snd-soc-dummy-dai",
193 .codec_name = "snd-soc-dummy",
194 .platform_name = "sst-mfld-platform",
196 /* CODEC<->CODEC link */
199 .name = "SSP2-Codec",
201 .cpu_dai_name = "ssp2-port",
202 .platform_name = "sst-mfld-platform",
204 .codec_dai_name = "da7213-hifi",
205 .codec_name = "i2c-DLGS7213:00",
206 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
207 | SND_SOC_DAIFMT_CBS_CFS,
208 .be_hw_params_fixup = codec_fixup,
217 static struct snd_soc_card bytcht_da7213_card = {
218 .name = "bytcht-da7213",
219 .owner = THIS_MODULE,
221 .num_links = ARRAY_SIZE(dailink),
222 .controls = controls,
223 .num_controls = ARRAY_SIZE(controls),
224 .dapm_widgets = dapm_widgets,
225 .num_dapm_widgets = ARRAY_SIZE(dapm_widgets),
226 .dapm_routes = audio_map,
227 .num_dapm_routes = ARRAY_SIZE(audio_map),
230 static char codec_name[16]; /* i2c-<HID>:00 with HID being 8 chars */
232 static int bytcht_da7213_probe(struct platform_device *pdev)
236 struct snd_soc_card *card;
237 struct sst_acpi_mach *mach;
238 const char *i2c_name = NULL;
241 mach = (&pdev->dev)->platform_data;
242 card = &bytcht_da7213_card;
243 card->dev = &pdev->dev;
245 /* fix index of codec dai */
246 dai_index = MERR_DPCM_COMPR + 1;
247 for (i = 0; i < ARRAY_SIZE(dailink); i++) {
248 if (!strcmp(dailink[i].codec_name, "i2c-DLGS7213:00")) {
254 /* fixup codec name based on HID */
255 i2c_name = sst_acpi_find_name_from_hid(mach->id);
256 if (i2c_name != NULL) {
257 snprintf(codec_name, sizeof(codec_name),
258 "%s%s", "i2c-", i2c_name);
259 dailink[dai_index].codec_name = codec_name;
262 ret_val = devm_snd_soc_register_card(&pdev->dev, card);
265 "snd_soc_register_card failed %d\n", ret_val);
268 platform_set_drvdata(pdev, card);
272 static struct platform_driver bytcht_da7213_driver = {
274 .name = "bytcht_da7213",
276 .probe = bytcht_da7213_probe,
278 module_platform_driver(bytcht_da7213_driver);
280 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail/Cherrytrail+DA7213 Machine driver");
281 MODULE_AUTHOR("Pierre-Louis Bossart");
282 MODULE_LICENSE("GPL v2");
283 MODULE_ALIAS("platform:bytcht_da7213");