2 * bytcht_nocodec.c - ASoc Machine driver for MinnowBoard Max and Up
3 * to make I2S signals observable on the Low-Speed connector. Audio codec
4 * is not managed by ASoC/DAPM
6 * Copyright (C) 2015-2017 Intel Corp
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 <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/soc.h>
26 #include "../atom/sst-atom-controls.h"
28 static const struct snd_soc_dapm_widget widgets[] = {
29 SND_SOC_DAPM_MIC("Mic", NULL),
30 SND_SOC_DAPM_SPK("Speaker", NULL),
33 static const struct snd_kcontrol_new controls[] = {
34 SOC_DAPM_PIN_SWITCH("Mic"),
35 SOC_DAPM_PIN_SWITCH("Speaker"),
38 static const struct snd_soc_dapm_route audio_map[] = {
39 {"ssp2 Tx", NULL, "codec_out0"},
40 {"ssp2 Tx", NULL, "codec_out1"},
41 {"codec_in0", NULL, "ssp2 Rx"},
42 {"codec_in1", NULL, "ssp2 Rx"},
44 {"ssp2 Rx", NULL, "Mic"},
45 {"Speaker", NULL, "ssp2 Tx"},
48 static int codec_fixup(struct snd_soc_pcm_runtime *rtd,
49 struct snd_pcm_hw_params *params)
51 struct snd_interval *rate = hw_param_interval(params,
52 SNDRV_PCM_HW_PARAM_RATE);
53 struct snd_interval *channels = hw_param_interval(params,
54 SNDRV_PCM_HW_PARAM_CHANNELS);
57 /* The DSP will convert the FE rate to 48k, stereo, 24bits */
58 rate->min = rate->max = 48000;
59 channels->min = channels->max = 2;
61 /* set SSP2 to 24-bit */
62 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
65 * Default mode for SSP configuration is TDM 4 slot, override config
66 * with explicit setting to I2S 2ch 24-bit. The word length is set with
67 * dai_set_tdm_slot() since there is no other API exposed
69 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
71 SND_SOC_DAIFMT_NB_NF |
72 SND_SOC_DAIFMT_CBS_CFS);
75 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
79 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
81 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
88 static unsigned int rates_48000[] = {
92 static struct snd_pcm_hw_constraint_list constraints_48000 = {
93 .count = ARRAY_SIZE(rates_48000),
97 static int aif1_startup(struct snd_pcm_substream *substream)
99 return snd_pcm_hw_constraint_list(substream->runtime, 0,
100 SNDRV_PCM_HW_PARAM_RATE,
104 static struct snd_soc_ops aif1_ops = {
105 .startup = aif1_startup,
108 static struct snd_soc_dai_link dais[] = {
109 [MERR_DPCM_AUDIO] = {
110 .name = "Audio Port",
111 .stream_name = "Audio",
112 .cpu_dai_name = "media-cpu-dai",
113 .codec_dai_name = "snd-soc-dummy-dai",
114 .codec_name = "snd-soc-dummy",
115 .platform_name = "sst-mfld-platform",
123 [MERR_DPCM_DEEP_BUFFER] = {
124 .name = "Deep-Buffer Audio Port",
125 .stream_name = "Deep-Buffer Audio",
126 .cpu_dai_name = "deepbuffer-cpu-dai",
127 .codec_dai_name = "snd-soc-dummy-dai",
128 .codec_name = "snd-soc-dummy",
129 .platform_name = "sst-mfld-platform",
136 [MERR_DPCM_COMPR] = {
137 .name = "Compressed Port",
138 .stream_name = "Compress",
139 .cpu_dai_name = "compress-cpu-dai",
140 .codec_dai_name = "snd-soc-dummy-dai",
141 .codec_name = "snd-soc-dummy",
142 .platform_name = "sst-mfld-platform",
144 /* CODEC<->CODEC link */
147 .name = "SSP2-LowSpeed Connector",
149 .cpu_dai_name = "ssp2-port",
150 .platform_name = "sst-mfld-platform",
152 .codec_dai_name = "snd-soc-dummy-dai",
153 .codec_name = "snd-soc-dummy",
154 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
155 | SND_SOC_DAIFMT_CBS_CFS,
156 .be_hw_params_fixup = codec_fixup,
165 static struct snd_soc_card bytcht_nocodec_card = {
166 .name = "bytcht-nocodec",
167 .owner = THIS_MODULE,
169 .num_links = ARRAY_SIZE(dais),
170 .dapm_widgets = widgets,
171 .num_dapm_widgets = ARRAY_SIZE(widgets),
172 .dapm_routes = audio_map,
173 .num_dapm_routes = ARRAY_SIZE(audio_map),
174 .controls = controls,
175 .num_controls = ARRAY_SIZE(controls),
176 .fully_routed = true,
179 static int snd_bytcht_nocodec_mc_probe(struct platform_device *pdev)
183 /* register the soc card */
184 bytcht_nocodec_card.dev = &pdev->dev;
186 ret_val = devm_snd_soc_register_card(&pdev->dev, &bytcht_nocodec_card);
189 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
193 platform_set_drvdata(pdev, &bytcht_nocodec_card);
197 static struct platform_driver snd_bytcht_nocodec_mc_driver = {
199 .name = "bytcht_nocodec",
201 .probe = snd_bytcht_nocodec_mc_probe,
203 module_platform_driver(snd_bytcht_nocodec_mc_driver);
205 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail/Cherrytrail Nocodec Machine driver");
206 MODULE_AUTHOR("Pierre-Louis Bossart <pierre-louis.bossart at linux.intel.com>");
207 MODULE_LICENSE("GPL v2");
208 MODULE_ALIAS("platform:bytcht_nocodec");