2 * byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform
4 * Copyright (C) 2014 Intel Corp
5 * Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/platform_device.h>
23 #include <linux/device.h>
24 #include <linux/slab.h>
25 #include <linux/input.h>
26 #include <sound/pcm.h>
27 #include <sound/pcm_params.h>
28 #include <sound/soc.h>
29 #include "../codecs/rt5640.h"
30 #include "sst-atom-controls.h"
32 static const struct snd_soc_dapm_widget byt_dapm_widgets[] = {
33 SND_SOC_DAPM_HP("Headphone", NULL),
34 SND_SOC_DAPM_MIC("Headset Mic", NULL),
35 SND_SOC_DAPM_MIC("Int Mic", NULL),
36 SND_SOC_DAPM_SPK("Ext Spk", NULL),
39 static const struct snd_soc_dapm_route byt_audio_map[] = {
40 {"IN2P", NULL, "Headset Mic"},
41 {"IN2N", NULL, "Headset Mic"},
42 {"Headset Mic", NULL, "MICBIAS1"},
43 {"IN1P", NULL, "MICBIAS1"},
44 {"LDO2", NULL, "Int Mic"},
45 {"Headphone", NULL, "HPOL"},
46 {"Headphone", NULL, "HPOR"},
47 {"Ext Spk", NULL, "SPOLP"},
48 {"Ext Spk", NULL, "SPOLN"},
49 {"Ext Spk", NULL, "SPORP"},
50 {"Ext Spk", NULL, "SPORN"},
52 {"AIF1 Playback", NULL, "ssp2 Tx"},
53 {"ssp2 Tx", NULL, "codec_out0"},
54 {"ssp2 Tx", NULL, "codec_out1"},
55 {"codec_in0", NULL, "ssp2 Rx"},
56 {"codec_in1", NULL, "ssp2 Rx"},
57 {"ssp2 Rx", NULL, "AIF1 Capture"},
60 static const struct snd_kcontrol_new byt_mc_controls[] = {
61 SOC_DAPM_PIN_SWITCH("Headphone"),
62 SOC_DAPM_PIN_SWITCH("Headset Mic"),
63 SOC_DAPM_PIN_SWITCH("Int Mic"),
64 SOC_DAPM_PIN_SWITCH("Ext Spk"),
67 static int byt_aif1_hw_params(struct snd_pcm_substream *substream,
68 struct snd_pcm_hw_params *params)
70 struct snd_soc_pcm_runtime *rtd = substream->private_data;
71 struct snd_soc_dai *codec_dai = rtd->codec_dai;
74 snd_soc_dai_set_bclk_ratio(codec_dai, 50);
76 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
77 params_rate(params) * 512,
80 dev_err(rtd->dev, "can't set codec clock %d\n", ret);
84 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1,
85 params_rate(params) * 50,
86 params_rate(params) * 512);
88 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
95 static const struct snd_soc_pcm_stream byt_dai_params = {
96 .formats = SNDRV_PCM_FMTBIT_S24_LE,
103 static int byt_codec_fixup(struct snd_soc_pcm_runtime *rtd,
104 struct snd_pcm_hw_params *params)
106 struct snd_interval *rate = hw_param_interval(params,
107 SNDRV_PCM_HW_PARAM_RATE);
108 struct snd_interval *channels = hw_param_interval(params,
109 SNDRV_PCM_HW_PARAM_CHANNELS);
111 /* The DSP will covert the FE rate to 48k, stereo, 24bits */
112 rate->min = rate->max = 48000;
113 channels->min = channels->max = 2;
115 /* set SSP2 to 24-bit */
116 snd_mask_set(¶ms->masks[SNDRV_PCM_HW_PARAM_FORMAT -
117 SNDRV_PCM_HW_PARAM_FIRST_MASK],
118 SNDRV_PCM_FORMAT_S24_LE);
122 static unsigned int rates_48000[] = {
126 static struct snd_pcm_hw_constraint_list constraints_48000 = {
127 .count = ARRAY_SIZE(rates_48000),
131 static int byt_aif1_startup(struct snd_pcm_substream *substream)
133 return snd_pcm_hw_constraint_list(substream->runtime, 0,
134 SNDRV_PCM_HW_PARAM_RATE,
138 static struct snd_soc_ops byt_aif1_ops = {
139 .startup = byt_aif1_startup,
142 static struct snd_soc_ops byt_be_ssp2_ops = {
143 .hw_params = byt_aif1_hw_params,
146 static struct snd_soc_dai_link byt_dailink[] = {
147 [MERR_DPCM_AUDIO] = {
148 .name = "Baytrail Audio Port",
149 .stream_name = "Baytrail Audio",
150 .cpu_dai_name = "media-cpu-dai",
151 .codec_dai_name = "snd-soc-dummy-dai",
152 .codec_name = "snd-soc-dummy",
153 .platform_name = "sst-mfld-platform",
158 .ops = &byt_aif1_ops,
160 [MERR_DPCM_COMPR] = {
161 .name = "Baytrail Compressed Port",
162 .stream_name = "Baytrail Compress",
163 .cpu_dai_name = "compress-cpu-dai",
164 .codec_dai_name = "snd-soc-dummy-dai",
165 .codec_name = "snd-soc-dummy",
166 .platform_name = "sst-mfld-platform",
170 .name = "SSP2-Codec",
172 .cpu_dai_name = "ssp2-port",
173 .platform_name = "sst-mfld-platform",
175 .codec_dai_name = "rt5640-aif1",
176 .codec_name = "i2c-10EC5640:00",
177 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
178 | SND_SOC_DAIFMT_CBS_CFS,
179 .be_hw_params_fixup = byt_codec_fixup,
183 .ops = &byt_be_ssp2_ops,
188 static struct snd_soc_card snd_soc_card_byt = {
189 .name = "baytrailcraudio",
190 .dai_link = byt_dailink,
191 .num_links = ARRAY_SIZE(byt_dailink),
192 .dapm_widgets = byt_dapm_widgets,
193 .num_dapm_widgets = ARRAY_SIZE(byt_dapm_widgets),
194 .dapm_routes = byt_audio_map,
195 .num_dapm_routes = ARRAY_SIZE(byt_audio_map),
196 .controls = byt_mc_controls,
197 .num_controls = ARRAY_SIZE(byt_mc_controls),
200 static int snd_byt_mc_probe(struct platform_device *pdev)
204 /* register the soc card */
205 snd_soc_card_byt.dev = &pdev->dev;
207 ret_val = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_byt);
209 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n", ret_val);
212 platform_set_drvdata(pdev, &snd_soc_card_byt);
216 static struct platform_driver snd_byt_mc_driver = {
218 .owner = THIS_MODULE,
219 .name = "bytt100_rt5640",
220 .pm = &snd_soc_pm_ops,
222 .probe = snd_byt_mc_probe,
225 module_platform_driver(snd_byt_mc_driver);
227 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
228 MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
229 MODULE_LICENSE("GPL v2");
230 MODULE_ALIAS("platform:bytt100_rt5640");