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 "../atom/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 params_set_format(params
, SNDRV_PCM_FORMAT_S24_LE
);
120 static int byt_aif1_startup(struct snd_pcm_substream
*substream
)
122 return snd_pcm_hw_constraint_single(substream
->runtime
,
123 SNDRV_PCM_HW_PARAM_RATE
, 48000);
126 static struct snd_soc_ops byt_aif1_ops
= {
127 .startup
= byt_aif1_startup
,
130 static struct snd_soc_ops byt_be_ssp2_ops
= {
131 .hw_params
= byt_aif1_hw_params
,
134 static struct snd_soc_dai_link byt_dailink
[] = {
135 [MERR_DPCM_AUDIO
] = {
136 .name
= "Baytrail Audio Port",
137 .stream_name
= "Baytrail Audio",
138 .cpu_dai_name
= "media-cpu-dai",
139 .codec_dai_name
= "snd-soc-dummy-dai",
140 .codec_name
= "snd-soc-dummy",
141 .platform_name
= "sst-mfld-platform",
146 .ops
= &byt_aif1_ops
,
148 [MERR_DPCM_COMPR
] = {
149 .name
= "Baytrail Compressed Port",
150 .stream_name
= "Baytrail Compress",
151 .cpu_dai_name
= "compress-cpu-dai",
152 .codec_dai_name
= "snd-soc-dummy-dai",
153 .codec_name
= "snd-soc-dummy",
154 .platform_name
= "sst-mfld-platform",
158 .name
= "SSP2-Codec",
160 .cpu_dai_name
= "ssp2-port",
161 .platform_name
= "sst-mfld-platform",
163 .codec_dai_name
= "rt5640-aif1",
164 .codec_name
= "i2c-10EC5640:00",
165 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
166 | SND_SOC_DAIFMT_CBS_CFS
,
167 .be_hw_params_fixup
= byt_codec_fixup
,
171 .ops
= &byt_be_ssp2_ops
,
176 static struct snd_soc_card snd_soc_card_byt
= {
177 .name
= "baytrailcraudio",
178 .owner
= THIS_MODULE
,
179 .dai_link
= byt_dailink
,
180 .num_links
= ARRAY_SIZE(byt_dailink
),
181 .dapm_widgets
= byt_dapm_widgets
,
182 .num_dapm_widgets
= ARRAY_SIZE(byt_dapm_widgets
),
183 .dapm_routes
= byt_audio_map
,
184 .num_dapm_routes
= ARRAY_SIZE(byt_audio_map
),
185 .controls
= byt_mc_controls
,
186 .num_controls
= ARRAY_SIZE(byt_mc_controls
),
189 static int snd_byt_mc_probe(struct platform_device
*pdev
)
193 /* register the soc card */
194 snd_soc_card_byt
.dev
= &pdev
->dev
;
196 ret_val
= devm_snd_soc_register_card(&pdev
->dev
, &snd_soc_card_byt
);
198 dev_err(&pdev
->dev
, "devm_snd_soc_register_card failed %d\n", ret_val
);
201 platform_set_drvdata(pdev
, &snd_soc_card_byt
);
205 static struct platform_driver snd_byt_mc_driver
= {
207 .name
= "bytt100_rt5640",
208 .pm
= &snd_soc_pm_ops
,
210 .probe
= snd_byt_mc_probe
,
213 module_platform_driver(snd_byt_mc_driver
);
215 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
216 MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
217 MODULE_LICENSE("GPL v2");
218 MODULE_ALIAS("platform:bytt100_rt5640");